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

N = 1
observations = []
def solve(results):
    table = {}
    for t1, tr1, s1, t2, tr2, s2 in results:
        for team, tries, s, o in ((t1, tr1, s1, s2), (t2, tr2, s2, s1)):
            row = table.setdefault(team, [0, 0, 0])
            if s > o:
                row[0] += 4
                row[1] += 1
            elif s == o:
                row[0] += 2
            if tries > 4:
                row[0] += 1
            if s < o and o - s <= 7:
                row[0] += 1
            row[2] += s - o
    order = sorted(table, key=lambda t: (-table[t][0], -table[t][1], -table[t][2], t))
    return [[t] + table[t] for t in order]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: try bonus threshold',
   ([['Wasps', 0, 15, 'Sale', 6, 15],
     ['Wasps', 4, 22, 'Leeds', 6, 27],
     ['Wasps', 2, 27, 'Bath', 6, 22]],),
   [['Wasps', 8, 1, 0], ['Leeds', 5, 1, 5], ['Sale', 3, 0, 0], ['Bath', 2, 0, -5]]),
  ('variant scenario 1',
   ([['Bath', 2, 27, 'Leeds', 0, 20], ['Sale', 0, 27, 'Wasps', 6, 5]],),
   [['Sale', 4, 1, 22], ['Bath', 4, 1, 7], ['Leeds', 1, 0, -7], ['Wasps', 1, 0, -22]]),
  ('variant scenario 2',
   ([['Leeds', 5, 7, 'Sale', 3, 20],
     ['Leeds', 1, 7, 'Bath', 3, 22],
     ['Sale', 0, 15, 'Leeds', 3, 15]],),
   [['Sale', 6, 1, 13], ['Bath', 4, 1, 15], ['Leeds', 3, 0, -28]])],
 [('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: try bonus threshold',
   ([['Wasps', 3, 24, 'Sale', 3, 12],
     ['Leeds', 2, 5, 'Wasps', 2, 3],
     ['Sale', 5, 20, 'Wasps', 5, 10],
     ['Wasps', 3, 10, 'Leeds', 5, 10],
     ['Leeds', 5, 27, 'Sale', 5, 10]],),
   [['Leeds', 12, 2, 19], ['Wasps', 8, 1, 0], ['Sale', 6, 1, -19]]),
  ('regression: try bonus threshold',
   ([['Wasps', 0, 22, 'Sale', 5, 30], ['Leeds', 0, 17, 'Sale', 4, 30]],),
   [['Sale', 10, 2, 21], ['Wasps', 0, 0, -8], ['Leeds', 0, 0, -13]]),
  ('variant scenario 1',
   ([['Wasps', 4, 12, 'Sale', 3, 30],
     ['Sale', 5, 30, 'Bath', 2, 27],
     ['Leeds', 1, 3, 'Sale', 4, 17],
     ['Sale', 1, 5, 'Bath', 2, 3],
     ['Bath', 2, 30, 'Sale', 6, 17],
     ['Sale', 4, 27, 'Wasps', 1, 20]],),
   [['Sale', 24, 5, 31], ['Bath', 6, 1, 8], ['Wasps', 2, 0, -25], ['Leeds', 0, 0, -14]]),
  ('variant scenario 2',
   ([['Bath', 6, 5, 'Sale', 2, 10],
     ['Leeds', 2, 3, 'Bath', 5, 12],
     ['Bath', 0, 22, 'Wasps', 4, 22],
     ['Leeds', 2, 5, 'Sale', 6, 12]],),
   [['Sale', 9, 2, 12], ['Bath', 9, 1, 4], ['Wasps', 3, 0, 0], ['Leeds', 1, 0, -16]])],
 [('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: try bonus threshold',
   ([['Bath', 1, 5, 'Leeds', 5, 3],
     ['Sale', 3, 33, 'Wasps', 4, 30],
     ['Sale', 2, 12, 'Bath', 0, 5],
     ['Wasps', 1, 12, 'Bath', 5, 5]],),
   [['Sale', 8, 2, 10], ['Bath', 7, 1, -12], ['Wasps', 6, 1, 4], ['Leeds', 2, 0, -2]]),
  ('variant scenario 1',
   ([['Wasps', 1, 17, 'Bath', 4, 12],
     ['Sale', 3, 27, 'Leeds', 6, 30],
     ['Sale', 2, 27, 'Bath', 3, 10],
     ['Bath', 1, 10, 'Leeds', 4, 30],
     ['Leeds', 2, 22, 'Sale', 2, 22],
     ['Leeds', 2, 3, 'Bath', 0, 5],
     ['Sale', 1, 20, 'Bath', 2, 10]],),
   [['Leeds', 13, 2, 21], ['Sale', 11, 2, 24], ['Bath', 6, 1, -50], ['Wasps', 4, 1, 5]]),
  ('variant scenario 2',
   ([['Sale', 3, 33, 'Bath', 2, 12],
     ['Wasps', 3, 27, 'Bath', 3, 22],
     ['Sale', 0, 5, 'Wasps', 2, 3],
     ['Wasps', 4, 10, 'Leeds', 2, 30],
     ['Sale', 3, 7, 'Leeds', 5, 24],
     ['Bath', 0, 15, 'Leeds', 5, 22]],),
   [['Leeds', 14, 3, 44], ['Sale', 8, 2, 6], ['Wasps', 6, 1, -17], ['Bath', 2, 0, -33]])],
 [('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: try bonus threshold',
   ([['Sale', 1, 27, 'Leeds', 3, 15],
     ['Bath', 5, 33, 'Leeds', 4, 3],
     ['Bath', 0, 20, 'Sale', 4, 3],
     ['Wasps', 2, 24, 'Bath', 2, 17],
     ['Bath', 5, 24, 'Leeds', 4, 20]],),
   [['Bath', 15, 3, 44], ['Sale', 5, 1, -5], ['Wasps', 4, 1, 7], ['Leeds', 3, 0, -46]]),
  ('variant scenario 1',
   ([['Wasps', 5, 5, 'Bath', 1, 10],
     ['Wasps', 3, 10, 'Sale', 4, 20],
     ['Sale', 1, 10, 'Leeds', 3, 5],
     ['Wasps', 6, 30, 'Sale', 6, 3],
     ['Wasps', 3, 20, 'Leeds', 1, 3],
     ['Leeds', 3, 12, 'Sale', 3, 30],
     ['Sale', 2, 20, 'Wasps', 6, 7],
     ['Sale', 2, 5, 'Wasps', 2, 5]],),
   [['Sale', 20, 4, 19], ['Wasps', 14, 2, 16], ['Bath', 4, 1, 5], ['Leeds', 1, 0, -40]]),
  ('variant scenario 2',
   ([['Wasps', 4, 17, 'Sale', 3, 5],
     ['Bath', 3, 3, 'Wasps', 2, 10],
     ['Wasps', 3, 17, 'Leeds', 5, 15],
     ['Leeds', 1, 30, 'Sale', 2, 24],
     ['Sale', 3, 24, 'Bath', 3, 3],
     ['Sale', 4, 5, 'Wasps', 2, 15],
     ['Leeds', 4, 27, 'Wasps', 6, 24]],),
   [['Wasps', 19, 4, 28], ['Leeds', 11, 2, 7], ['Sale', 6, 1, -7], ['Bath', 1, 0, -28]])],
 [('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: try bonus threshold',
   ([['Sale', 2, 17, 'Leeds', 1, 20],
     ['Leeds', 1, 17, 'Wasps', 1, 30],
     ['Wasps', 4, 17, 'Bath', 6, 22],
     ['Sale', 0, 27, 'Leeds', 6, 3],
     ['Bath', 1, 7, 'Sale', 4, 20],
     ['Bath', 1, 20, 'Wasps', 1, 17],
     ['Sale', 4, 33, 'Bath', 2, 17],
     ['Leeds', 0, 15, 'Sale', 4, 20]],),
   [['Sale', 20, 4, 55], ['Bath', 9, 2, -21], ['Wasps', 7, 1, 5], ['Leeds', 6, 1, -39]]),
  ('variant scenario 1',
   ([['Sale', 5, 24, 'Wasps', 2, 30],
     ['Bath', 6, 20, 'Wasps', 5, 24],
     ['Bath', 1, 27, 'Sale', 3, 30],
     ['Leeds', 2, 15, 'Sale', 6, 30],
     ['Wasps', 0, 30, 'Leeds', 4, 24],
     ['Bath', 5, 10, 'Leeds', 3, 30]],),
   [['Wasps', 13, 3, 16], ['Sale', 11, 2, 12], ['Leeds', 6, 1, -1], ['Bath', 4, 0, -27]]),
  ('variant scenario 2',
   ([['Bath', 3, 5, 'Sale', 0, 30],
     ['Leeds', 3, 10, 'Wasps', 0, 5],
     ['Bath', 6, 7, 'Sale', 2, 30],
     ['Leeds', 0, 33, 'Sale', 2, 5],
     ['Leeds', 1, 17, 'Wasps', 0, 5]],),
   [['Leeds', 12, 3, 45], ['Sale', 8, 2, 20], ['Wasps', 1, 0, -17], ['Bath', 1, 0, -48]])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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(results):
    table = {}
    for t1, tr1, s1, t2, tr2, s2 in results:
        for team, tries, s, o in ((t1, tr1, s1, s2), (t2, tr2, s2, s1)):
            row = table.setdefault(team, [0, 0, 0])
            if s > o:
                row[0] += 4
                row[1] += 1
            elif s == o:
                row[0] += 2
            if tries - (tr2 if team == t1 else tr1) >= 3:
                row[0] += 1
            if s < o and o - s <= 7:
                row[0] += 1
            row[2] += s - o
    order = sorted(table, key=lambda t: (-table[t][0], -table[t][1], -table[t][2], t))
    return [[t] + table[t] for t in order]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: try bonus threshold',
   ([['Wasps', 0, 15, 'Sale', 6, 15],
     ['Wasps', 4, 22, 'Leeds', 6, 27],
     ['Wasps', 2, 27, 'Bath', 6, 22]],),
   [['Wasps', 8, 1, 0], ['Leeds', 5, 1, 5], ['Sale', 3, 0, 0], ['Bath', 2, 0, -5]]),
  ('variant scenario 1',
   ([['Bath', 2, 27, 'Leeds', 0, 20], ['Sale', 0, 27, 'Wasps', 6, 5]],),
   [['Sale', 4, 1, 22], ['Bath', 4, 1, 7], ['Leeds', 1, 0, -7], ['Wasps', 1, 0, -22]]),
  ('variant scenario 2',
   ([['Leeds', 5, 7, 'Sale', 3, 20],
     ['Leeds', 1, 7, 'Bath', 3, 22],
     ['Sale', 0, 15, 'Leeds', 3, 15]],),
   [['Sale', 6, 1, 13], ['Bath', 4, 1, 15], ['Leeds', 3, 0, -28]])],
 [('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: try bonus threshold',
   ([['Wasps', 3, 24, 'Sale', 3, 12],
     ['Leeds', 2, 5, 'Wasps', 2, 3],
     ['Sale', 5, 20, 'Wasps', 5, 10],
     ['Wasps', 3, 10, 'Leeds', 5, 10],
     ['Leeds', 5, 27, 'Sale', 5, 10]],),
   [['Leeds', 12, 2, 19], ['Wasps', 8, 1, 0], ['Sale', 6, 1, -19]]),
  ('regression: try bonus threshold',
   ([['Wasps', 0, 22, 'Sale', 5, 30], ['Leeds', 0, 17, 'Sale', 4, 30]],),
   [['Sale', 10, 2, 21], ['Wasps', 0, 0, -8], ['Leeds', 0, 0, -13]]),
  ('variant scenario 1',
   ([['Wasps', 4, 12, 'Sale', 3, 30],
     ['Sale', 5, 30, 'Bath', 2, 27],
     ['Leeds', 1, 3, 'Sale', 4, 17],
     ['Sale', 1, 5, 'Bath', 2, 3],
     ['Bath', 2, 30, 'Sale', 6, 17],
     ['Sale', 4, 27, 'Wasps', 1, 20]],),
   [['Sale', 24, 5, 31], ['Bath', 6, 1, 8], ['Wasps', 2, 0, -25], ['Leeds', 0, 0, -14]]),
  ('variant scenario 2',
   ([['Bath', 6, 5, 'Sale', 2, 10],
     ['Leeds', 2, 3, 'Bath', 5, 12],
     ['Bath', 0, 22, 'Wasps', 4, 22],
     ['Leeds', 2, 5, 'Sale', 6, 12]],),
   [['Sale', 9, 2, 12], ['Bath', 9, 1, 4], ['Wasps', 3, 0, 0], ['Leeds', 1, 0, -16]])],
 [('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: try bonus threshold',
   ([['Bath', 1, 5, 'Leeds', 5, 3],
     ['Sale', 3, 33, 'Wasps', 4, 30],
     ['Sale', 2, 12, 'Bath', 0, 5],
     ['Wasps', 1, 12, 'Bath', 5, 5]],),
   [['Sale', 8, 2, 10], ['Bath', 7, 1, -12], ['Wasps', 6, 1, 4], ['Leeds', 2, 0, -2]]),
  ('variant scenario 1',
   ([['Wasps', 1, 17, 'Bath', 4, 12],
     ['Sale', 3, 27, 'Leeds', 6, 30],
     ['Sale', 2, 27, 'Bath', 3, 10],
     ['Bath', 1, 10, 'Leeds', 4, 30],
     ['Leeds', 2, 22, 'Sale', 2, 22],
     ['Leeds', 2, 3, 'Bath', 0, 5],
     ['Sale', 1, 20, 'Bath', 2, 10]],),
   [['Leeds', 13, 2, 21], ['Sale', 11, 2, 24], ['Bath', 6, 1, -50], ['Wasps', 4, 1, 5]]),
  ('variant scenario 2',
   ([['Sale', 3, 33, 'Bath', 2, 12],
     ['Wasps', 3, 27, 'Bath', 3, 22],
     ['Sale', 0, 5, 'Wasps', 2, 3],
     ['Wasps', 4, 10, 'Leeds', 2, 30],
     ['Sale', 3, 7, 'Leeds', 5, 24],
     ['Bath', 0, 15, 'Leeds', 5, 22]],),
   [['Leeds', 14, 3, 44], ['Sale', 8, 2, 6], ['Wasps', 6, 1, -17], ['Bath', 2, 0, -33]])],
 [('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: try bonus threshold',
   ([['Sale', 1, 27, 'Leeds', 3, 15],
     ['Bath', 5, 33, 'Leeds', 4, 3],
     ['Bath', 0, 20, 'Sale', 4, 3],
     ['Wasps', 2, 24, 'Bath', 2, 17],
     ['Bath', 5, 24, 'Leeds', 4, 20]],),
   [['Bath', 15, 3, 44], ['Sale', 5, 1, -5], ['Wasps', 4, 1, 7], ['Leeds', 3, 0, -46]]),
  ('variant scenario 1',
   ([['Wasps', 5, 5, 'Bath', 1, 10],
     ['Wasps', 3, 10, 'Sale', 4, 20],
     ['Sale', 1, 10, 'Leeds', 3, 5],
     ['Wasps', 6, 30, 'Sale', 6, 3],
     ['Wasps', 3, 20, 'Leeds', 1, 3],
     ['Leeds', 3, 12, 'Sale', 3, 30],
     ['Sale', 2, 20, 'Wasps', 6, 7],
     ['Sale', 2, 5, 'Wasps', 2, 5]],),
   [['Sale', 20, 4, 19], ['Wasps', 14, 2, 16], ['Bath', 4, 1, 5], ['Leeds', 1, 0, -40]]),
  ('variant scenario 2',
   ([['Wasps', 4, 17, 'Sale', 3, 5],
     ['Bath', 3, 3, 'Wasps', 2, 10],
     ['Wasps', 3, 17, 'Leeds', 5, 15],
     ['Leeds', 1, 30, 'Sale', 2, 24],
     ['Sale', 3, 24, 'Bath', 3, 3],
     ['Sale', 4, 5, 'Wasps', 2, 15],
     ['Leeds', 4, 27, 'Wasps', 6, 24]],),
   [['Wasps', 19, 4, 28], ['Leeds', 11, 2, 7], ['Sale', 6, 1, -7], ['Bath', 1, 0, -28]])],
 [('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: try bonus threshold',
   ([['Sale', 2, 17, 'Leeds', 1, 20],
     ['Leeds', 1, 17, 'Wasps', 1, 30],
     ['Wasps', 4, 17, 'Bath', 6, 22],
     ['Sale', 0, 27, 'Leeds', 6, 3],
     ['Bath', 1, 7, 'Sale', 4, 20],
     ['Bath', 1, 20, 'Wasps', 1, 17],
     ['Sale', 4, 33, 'Bath', 2, 17],
     ['Leeds', 0, 15, 'Sale', 4, 20]],),
   [['Sale', 20, 4, 55], ['Bath', 9, 2, -21], ['Wasps', 7, 1, 5], ['Leeds', 6, 1, -39]]),
  ('variant scenario 1',
   ([['Sale', 5, 24, 'Wasps', 2, 30],
     ['Bath', 6, 20, 'Wasps', 5, 24],
     ['Bath', 1, 27, 'Sale', 3, 30],
     ['Leeds', 2, 15, 'Sale', 6, 30],
     ['Wasps', 0, 30, 'Leeds', 4, 24],
     ['Bath', 5, 10, 'Leeds', 3, 30]],),
   [['Wasps', 13, 3, 16], ['Sale', 11, 2, 12], ['Leeds', 6, 1, -1], ['Bath', 4, 0, -27]]),
  ('variant scenario 2',
   ([['Bath', 3, 5, 'Sale', 0, 30],
     ['Leeds', 3, 10, 'Wasps', 0, 5],
     ['Bath', 6, 7, 'Sale', 2, 30],
     ['Leeds', 0, 33, 'Sale', 2, 5],
     ['Leeds', 1, 17, 'Wasps', 0, 5]],),
   [['Leeds', 12, 3, 45], ['Sale', 8, 2, 20], ['Wasps', 1, 0, -17], ['Bath', 1, 0, -48]])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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:
Teams scoring exactly four tries are denied the bonus point.

Rugby union league points. results rows are [team, tries, score, opponent, opp_tries, opp_score]. Win 4 points, draw 2, loss 0. A try bonus point is earned by any team scoring 4 or more tries, and a losing bonus point by a team that loses by 7 points or fewer (both can apply to a loser). Rank by points, then wins, then points difference, then name. Return [team, points, wins, points difference] rows for teams that appear.

split: open-access


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

N = 1
observations = []
def solve(results):
    table = {}
    for t1, tr1, s1, t2, tr2, s2 in results:
        for team, tries, s, o in ((t1, tr1, s1, s2), (t2, tr2, s2, s1)):
            row = table.setdefault(team, [0, 0, 0])
            if s > o:
                row[0] += 4
                row[1] += 1
            elif s == o:
                row[0] += 2
            if tries >= 4:
                row[0] += 1
            if s < o and o - s < 7:
                row[0] += 1
            row[2] += s - o
    order = sorted(table, key=lambda t: (-table[t][0], -table[t][1], -table[t][2], t))
    return [[t] + table[t] for t in order]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: losing bonus margin',
   ([['Sale', 5, 22, 'Leeds', 4, 15], ['Bath', 3, 20, 'Leeds', 5, 15]],),
   [['Sale', 5, 1, 7], ['Bath', 4, 1, 5], ['Leeds', 4, 0, -12]]),
  ('variant scenario 1',
   ([['Leeds', 4, 30, 'Sale', 6, 24],
     ['Bath', 6, 22, 'Leeds', 5, 5],
     ['Bath', 3, 12, 'Leeds', 0, 20]],),
   [['Leeds', 10, 2, -3], ['Bath', 5, 1, 9], ['Sale', 2, 0, -6]]),
  ('variant scenario 2',
   ([['Leeds', 4, 33, 'Sale', 1, 7], ['Wasps', 5, 20, 'Sale', 5, 12]],),
   [['Leeds', 5, 1, 26], ['Wasps', 5, 1, 8], ['Sale', 1, 0, -34]])],
 [('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: losing bonus margin',
   ([['Wasps', 4, 24, 'Leeds', 4, 15],
     ['Wasps', 4, 5, 'Bath', 6, 24],
     ['Leeds', 2, 12, 'Wasps', 2, 5],
     ['Wasps', 5, 30, 'Leeds', 1, 30],
     ['Leeds', 1, 3, 'Sale', 0, 24]],),
   [['Wasps', 10, 1, -17], ['Leeds', 7, 1, -23], ['Bath', 5, 1, 19], ['Sale', 4, 1, 21]]),
  ('variant scenario 1',
   ([['Wasps', 5, 22, 'Sale', 0, 27], ['Sale', 1, 33, 'Bath', 5, 24]],),
   [['Sale', 8, 2, 14], ['Wasps', 2, 0, -5], ['Bath', 1, 0, -9]]),
  ('variant scenario 2',
   ([['Leeds', 1, 20, 'Bath', 5, 17], ['Leeds', 0, 30, 'Wasps', 4, 24]],),
   [['Leeds', 8, 2, 9], ['Bath', 2, 0, -3], ['Wasps', 2, 0, -6]])],
 [('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: losing bonus margin',
   ([['Sale', 6, 22, 'Leeds', 4, 7],
     ['Sale', 1, 5, 'Leeds', 2, 22],
     ['Sale', 5, 17, 'Wasps', 6, 24],
     ['Wasps', 1, 15, 'Sale', 3, 30],
     ['Wasps', 4, 7, 'Sale', 4, 27]],),
   [['Sale', 16, 3, 26], ['Wasps', 6, 1, -28], ['Leeds', 5, 1, 2]]),
  ('variant scenario 1',
   ([['Bath', 0, 22, 'Wasps', 5, 3], ['Wasps', 4, 12, 'Sale', 6, 15]],),
   [['Sale', 5, 1, 3], ['Bath', 4, 1, 19], ['Wasps', 3, 0, -22]]),
  ('variant scenario 2',
   ([['Sale', 1, 3, 'Bath', 0, 22], ['Wasps', 0, 22, 'Leeds', 6, 5]],),
   [['Bath', 4, 1, 19], ['Wasps', 4, 1, 17], ['Leeds', 1, 0, -17], ['Sale', 0, 0, -19]])],
 [('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: losing bonus margin',
   ([['Leeds', 1, 22, 'Wasps', 4, 27],
     ['Leeds', 4, 5, 'Sale', 4, 22],
     ['Leeds', 6, 7, 'Wasps', 2, 20],
     ['Wasps', 3, 10, 'Sale', 4, 17],
     ['Leeds', 4, 5, 'Sale', 2, 30],
     ['Wasps', 5, 15, 'Sale', 4, 5],
     ['Leeds', 5, 20, 'Sale', 0, 17],
     ['Bath', 5, 12, 'Leeds', 3, 7]],),
   [['Sale', 16, 3, 36], ['Wasps', 15, 3, 21], ['Leeds', 10, 1, -62], ['Bath', 5, 1, 5]]),
  ('variant scenario 1',
   ([['Bath', 1, 15, 'Leeds', 4, 5],
     ['Sale', 0, 27, 'Leeds', 1, 15],
     ['Sale', 4, 20, 'Leeds', 2, 20]],),
   [['Sale', 7, 1, 12], ['Bath', 4, 1, 10], ['Leeds', 3, 0, -22]]),
  ('variant scenario 2',
   ([['Leeds', 6, 12, 'Wasps', 4, 22],
     ['Bath', 5, 17, 'Wasps', 0, 3],
     ['Wasps', 4, 17, 'Leeds', 3, 3]],),
   [['Wasps', 10, 2, 10], ['Bath', 5, 1, 14], ['Leeds', 1, 0, -24]])],
 [('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: losing bonus margin',
   ([['Leeds', 3, 22, 'Bath', 2, 15],
     ['Bath', 1, 27, 'Sale', 1, 7],
     ['Sale', 2, 15, 'Leeds', 0, 15],
     ['Leeds', 3, 3, 'Bath', 0, 24],
     ['Bath', 3, 33, 'Leeds', 6, 10]],),
   [['Bath', 13, 3, 57], ['Leeds', 7, 1, -37], ['Sale', 2, 0, -20]]),
  ('variant scenario 1',
   ([['Leeds', 1, 3, 'Sale', 2, 30],
     ['Bath', 3, 17, 'Wasps', 6, 5],
     ['Bath', 6, 27, 'Wasps', 5, 3],
     ['Leeds', 5, 3, 'Wasps', 3, 10],
     ['Bath', 4, 5, 'Wasps', 0, 22]],),
   [['Bath', 10, 2, 19], ['Wasps', 10, 2, -12], ['Sale', 4, 1, 27], ['Leeds', 2, 0, -34]]),
  ('variant scenario 2',
   ([['Sale', 6, 27, 'Wasps', 3, 12],
     ['Leeds', 6, 17, 'Sale', 5, 27],
     ['Sale', 5, 22, 'Leeds', 3, 10],
     ['Sale', 5, 22, 'Leeds', 5, 17],
     ['Bath', 6, 17, 'Leeds', 0, 24],
     ['Bath', 0, 22, 'Leeds', 0, 20],
     ['Wasps', 0, 3, 'Sale', 1, 15]],),
   [['Sale', 24, 5, 54], ['Leeds', 8, 1, -22], ['Bath', 6, 1, -5], ['Wasps', 0, 0, -27]])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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(results):
    table = {}
    for t1, tr1, s1, t2, tr2, s2 in results:
        for team, tries, s, o in ((t1, tr1, s1, s2), (t2, tr2, s2, s1)):
            row = table.setdefault(team, [0, 0, 0])
            if s > o:
                row[0] += 4
                row[1] += 1
            elif s == o:
                row[0] += 2
            if tries >= 4:
                row[0] += 1
            if s < o and o - s <= 5:
                row[0] += 1
            row[2] += s - o
    order = sorted(table, key=lambda t: (-table[t][0], -table[t][1], -table[t][2], t))
    return [[t] + table[t] for t in order]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: losing bonus margin',
   ([['Sale', 5, 22, 'Leeds', 4, 15], ['Bath', 3, 20, 'Leeds', 5, 15]],),
   [['Sale', 5, 1, 7], ['Bath', 4, 1, 5], ['Leeds', 4, 0, -12]]),
  ('variant scenario 1',
   ([['Leeds', 4, 30, 'Sale', 6, 24],
     ['Bath', 6, 22, 'Leeds', 5, 5],
     ['Bath', 3, 12, 'Leeds', 0, 20]],),
   [['Leeds', 10, 2, -3], ['Bath', 5, 1, 9], ['Sale', 2, 0, -6]]),
  ('variant scenario 2',
   ([['Leeds', 4, 33, 'Sale', 1, 7], ['Wasps', 5, 20, 'Sale', 5, 12]],),
   [['Leeds', 5, 1, 26], ['Wasps', 5, 1, 8], ['Sale', 1, 0, -34]])],
 [('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: losing bonus margin',
   ([['Wasps', 4, 24, 'Leeds', 4, 15],
     ['Wasps', 4, 5, 'Bath', 6, 24],
     ['Leeds', 2, 12, 'Wasps', 2, 5],
     ['Wasps', 5, 30, 'Leeds', 1, 30],
     ['Leeds', 1, 3, 'Sale', 0, 24]],),
   [['Wasps', 10, 1, -17], ['Leeds', 7, 1, -23], ['Bath', 5, 1, 19], ['Sale', 4, 1, 21]]),
  ('variant scenario 1',
   ([['Wasps', 5, 22, 'Sale', 0, 27], ['Sale', 1, 33, 'Bath', 5, 24]],),
   [['Sale', 8, 2, 14], ['Wasps', 2, 0, -5], ['Bath', 1, 0, -9]]),
  ('variant scenario 2',
   ([['Leeds', 1, 20, 'Bath', 5, 17], ['Leeds', 0, 30, 'Wasps', 4, 24]],),
   [['Leeds', 8, 2, 9], ['Bath', 2, 0, -3], ['Wasps', 2, 0, -6]])],
 [('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: losing bonus margin',
   ([['Sale', 6, 22, 'Leeds', 4, 7],
     ['Sale', 1, 5, 'Leeds', 2, 22],
     ['Sale', 5, 17, 'Wasps', 6, 24],
     ['Wasps', 1, 15, 'Sale', 3, 30],
     ['Wasps', 4, 7, 'Sale', 4, 27]],),
   [['Sale', 16, 3, 26], ['Wasps', 6, 1, -28], ['Leeds', 5, 1, 2]]),
  ('variant scenario 1',
   ([['Bath', 0, 22, 'Wasps', 5, 3], ['Wasps', 4, 12, 'Sale', 6, 15]],),
   [['Sale', 5, 1, 3], ['Bath', 4, 1, 19], ['Wasps', 3, 0, -22]]),
  ('variant scenario 2',
   ([['Sale', 1, 3, 'Bath', 0, 22], ['Wasps', 0, 22, 'Leeds', 6, 5]],),
   [['Bath', 4, 1, 19], ['Wasps', 4, 1, 17], ['Leeds', 1, 0, -17], ['Sale', 0, 0, -19]])],
 [('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: losing bonus margin',
   ([['Leeds', 1, 22, 'Wasps', 4, 27],
     ['Leeds', 4, 5, 'Sale', 4, 22],
     ['Leeds', 6, 7, 'Wasps', 2, 20],
     ['Wasps', 3, 10, 'Sale', 4, 17],
     ['Leeds', 4, 5, 'Sale', 2, 30],
     ['Wasps', 5, 15, 'Sale', 4, 5],
     ['Leeds', 5, 20, 'Sale', 0, 17],
     ['Bath', 5, 12, 'Leeds', 3, 7]],),
   [['Sale', 16, 3, 36], ['Wasps', 15, 3, 21], ['Leeds', 10, 1, -62], ['Bath', 5, 1, 5]]),
  ('variant scenario 1',
   ([['Bath', 1, 15, 'Leeds', 4, 5],
     ['Sale', 0, 27, 'Leeds', 1, 15],
     ['Sale', 4, 20, 'Leeds', 2, 20]],),
   [['Sale', 7, 1, 12], ['Bath', 4, 1, 10], ['Leeds', 3, 0, -22]]),
  ('variant scenario 2',
   ([['Leeds', 6, 12, 'Wasps', 4, 22],
     ['Bath', 5, 17, 'Wasps', 0, 3],
     ['Wasps', 4, 17, 'Leeds', 3, 3]],),
   [['Wasps', 10, 2, 10], ['Bath', 5, 1, 14], ['Leeds', 1, 0, -24]])],
 [('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: losing bonus margin',
   ([['Leeds', 3, 22, 'Bath', 2, 15],
     ['Bath', 1, 27, 'Sale', 1, 7],
     ['Sale', 2, 15, 'Leeds', 0, 15],
     ['Leeds', 3, 3, 'Bath', 0, 24],
     ['Bath', 3, 33, 'Leeds', 6, 10]],),
   [['Bath', 13, 3, 57], ['Leeds', 7, 1, -37], ['Sale', 2, 0, -20]]),
  ('variant scenario 1',
   ([['Leeds', 1, 3, 'Sale', 2, 30],
     ['Bath', 3, 17, 'Wasps', 6, 5],
     ['Bath', 6, 27, 'Wasps', 5, 3],
     ['Leeds', 5, 3, 'Wasps', 3, 10],
     ['Bath', 4, 5, 'Wasps', 0, 22]],),
   [['Bath', 10, 2, 19], ['Wasps', 10, 2, -12], ['Sale', 4, 1, 27], ['Leeds', 2, 0, -34]]),
  ('variant scenario 2',
   ([['Sale', 6, 27, 'Wasps', 3, 12],
     ['Leeds', 6, 17, 'Sale', 5, 27],
     ['Sale', 5, 22, 'Leeds', 3, 10],
     ['Sale', 5, 22, 'Leeds', 5, 17],
     ['Bath', 6, 17, 'Leeds', 0, 24],
     ['Bath', 0, 22, 'Leeds', 0, 20],
     ['Wasps', 0, 3, 'Sale', 1, 15]],),
   [['Sale', 24, 5, 54], ['Leeds', 8, 1, -22], ['Bath', 6, 1, -5], ['Wasps', 0, 0, -27]])]]
for label, args, expected in cases[N - 1]:
    check(label, run(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A seven-point defeat earns no losing bonus.

Rugby union league points. results rows are [team, tries, score, opponent, opp_tries, opp_score]. Win 4 points, draw 2, loss 0. A try bonus point is earned by any team scoring 4 or more tries, and a losing bonus point by a team that loses by 7 points or fewer (both can apply to a loser). Rank by points, then wins, then points difference, then name. Return [team, points, wins, points difference] rows for teams that appear.

split: open-access


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

N = 1
observations = []
def solve(results):
    table = {}
    for t1, tr1, s1, t2, tr2, s2 in results:
        for team, tries, s, o in ((t1, tr1, s1, s2), (t2, tr2, s2, s1)):
            row = table.setdefault(team, [0, 0, 0])
            if s > o:
                row[0] += 4
                row[1] += 1
            elif s == o:
                row[0] += 2
            if tries >= 4:
                row[0] += 1
            if o - s <= 7:
                row[0] += 1
            row[2] += s - o
    order = sorted(table, key=lambda t: (-table[t][0], -table[t][1], -table[t][2], t))
    return [[t] + table[t] for t in order]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: losing bonus result guard',
   ([['Leeds', 1, 24, 'Wasps', 4, 3],
     ['Bath', 3, 30, 'Wasps', 6, 3],
     ['Leeds', 0, 15, 'Wasps', 5, 30],
     ['Wasps', 3, 22, 'Bath', 2, 7],
     ['Sale', 5, 7, 'Bath', 3, 5]],),
   [['Wasps', 11, 2, -18], ['Bath', 5, 1, 10], ['Sale', 5, 1, 2], ['Leeds', 4, 1, 6]]),
  ('regression: losing bonus result guard',
   ([['Leeds', 2, 7, 'Wasps', 0, 5],
     ['Bath', 4, 17, 'Sale', 6, 17],
     ['Sale', 3, 15, 'Leeds', 1, 24],
     ['Wasps', 0, 30, 'Leeds', 5, 20],
     ['Leeds', 0, 3, 'Wasps', 2, 30]],),
   [['Wasps', 9, 2, 35], ['Leeds', 9, 2, -26], ['Bath', 3, 0, 0], ['Sale', 3, 0, -9]]),
  ('variant scenario 1',
   ([['Bath', 2, 20, 'Sale', 1, 24],
     ['Wasps', 1, 30, 'Leeds', 1, 3],
     ['Leeds', 2, 15, 'Bath', 5, 12],
     ['Bath', 0, 22, 'Leeds', 4, 7],
     ['Bath', 1, 30, 'Leeds', 1, 20]],),
   [['Bath', 11, 2, 18], ['Leeds', 5, 1, -49], ['Wasps', 4, 1, 27], ['Sale', 4, 1, 4]]),
  ('variant scenario 2',
   ([['Wasps', 6, 15, 'Sale', 2, 5], ['Leeds', 3, 20, 'Bath', 0, 17]],),
   [['Wasps', 5, 1, 10], ['Leeds', 4, 1, 3], ['Bath', 1, 0, -3], ['Sale', 0, 0, -10]])],
 [('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: losing bonus result guard',
   ([['Sale', 1, 24, 'Bath', 5, 5], ['Bath', 2, 15, 'Sale', 6, 5]],),
   [['Sale', 5, 1, 9], ['Bath', 5, 1, -9]]),
  ('regression: losing bonus result guard',
   ([['Leeds', 4, 12, 'Wasps', 2, 12],
     ['Wasps', 5, 22, 'Sale', 2, 17],
     ['Wasps', 2, 30, 'Leeds', 4, 24]],),
   [['Wasps', 11, 2, 11], ['Leeds', 5, 0, -6], ['Sale', 1, 0, -5]]),
  ('variant scenario 1',
   ([['Sale', 6, 20, 'Bath', 6, 22],
     ['Leeds', 1, 22, 'Wasps', 1, 20],
     ['Wasps', 0, 17, 'Bath', 3, 10],
     ['Leeds', 6, 15, 'Bath', 3, 30],
     ['Leeds', 3, 33, 'Bath', 5, 22],
     ['Wasps', 2, 3, 'Sale', 1, 5]],),
   [['Bath', 11, 2, -1], ['Leeds', 9, 2, -2], ['Wasps', 6, 1, 3], ['Sale', 6, 1, 0]]),
  ('variant scenario 2',
   ([['Wasps', 1, 27, 'Sale', 0, 24],
     ['Leeds', 1, 24, 'Bath', 1, 15],
     ['Sale', 4, 10, 'Bath', 2, 27]],),
   [['Leeds', 4, 1, 9], ['Bath', 4, 1, 8], ['Wasps', 4, 1, 3], ['Sale', 2, 0, -20]])],
 [('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: losing bonus result guard',
   ([['Wasps', 3, 33, 'Bath', 5, 10],
     ['Sale', 3, 5, 'Wasps', 5, 15],
     ['Sale', 1, 22, 'Leeds', 4, 7],
     ['Sale', 5, 10, 'Wasps', 1, 3],
     ['Leeds', 0, 10, 'Wasps', 3, 30],
     ['Leeds', 3, 17, 'Wasps', 4, 27]],),
   [['Wasps', 19, 4, 56], ['Sale', 9, 2, 12], ['Bath', 1, 0, -23], ['Leeds', 1, 0, -45]]),
  ('regression: losing bonus result guard',
   ([['Wasps', 0, 7, 'Bath', 5, 22],
     ['Bath', 2, 22, 'Leeds', 5, 27],
     ['Bath', 3, 5, 'Wasps', 5, 30],
     ['Bath', 0, 5, 'Wasps', 6, 3],
     ['Sale', 1, 10, 'Bath', 1, 10],
     ['Wasps', 5, 15, 'Sale', 2, 10]],),
   [['Wasps', 12, 2, 13], ['Bath', 12, 2, -13], ['Leeds', 5, 1, 5], ['Sale', 3, 0, -5]]),
  ('variant scenario 1',
   ([['Sale', 5, 24, 'Wasps', 1, 17],
     ['Sale', 2, 24, 'Wasps', 6, 27],
     ['Leeds', 2, 24, 'Wasps', 3, 30]],),
   [['Wasps', 10, 2, 2], ['Sale', 6, 1, 4], ['Leeds', 1, 0, -6]]),
  ('variant scenario 2',
   ([['Leeds', 4, 30, 'Bath', 5, 3],
     ['Wasps', 3, 5, 'Bath', 6, 30],
     ['Leeds', 2, 27, 'Wasps', 1, 12],
     ['Leeds', 3, 17, 'Sale', 1, 7]],),
   [['Leeds', 13, 3, 52], ['Bath', 6, 1, -2], ['Sale', 0, 0, -10], ['Wasps', 0, 0, -40]])],
 [('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: losing bonus result guard',
   ([['Bath', 1, 5, 'Leeds', 1, 10],
     ['Sale', 0, 30, 'Bath', 4, 5],
     ['Leeds', 3, 5, 'Wasps', 1, 17],
     ['Bath', 4, 15, 'Leeds', 3, 7],
     ['Bath', 5, 27, 'Wasps', 0, 7]],),
   [['Bath', 12, 2, -2], ['Sale', 4, 1, 25], ['Wasps', 4, 1, -8], ['Leeds', 4, 1, -15]]),
  ('regression: losing bonus result guard',
   ([['Wasps', 6, 12, 'Sale', 1, 12],
     ['Bath', 3, 12, 'Wasps', 1, 24],
     ['Wasps', 6, 27, 'Bath', 2, 10],
     ['Bath', 3, 33, 'Wasps', 5, 3]],),
   [['Wasps', 13, 2, -1], ['Bath', 4, 1, 1], ['Sale', 2, 0, 0]]),
  ('variant scenario 1',
   ([['Leeds', 0, 33, 'Wasps', 5, 30],
     ['Leeds', 1, 22, 'Sale', 2, 12],
     ['Leeds', 3, 22, 'Wasps', 0, 10],
     ['Wasps', 5, 17, 'Bath', 1, 24],
     ['Wasps', 3, 7, 'Sale', 2, 10],
     ['Bath', 5, 17, 'Leeds', 3, 3],
     ['Wasps', 2, 10, 'Leeds', 5, 30],
     ['Leeds', 4, 12, 'Bath', 2, 30]],),
   [['Leeds', 18, 4, 13], ['Bath', 13, 3, 39], ['Wasps', 5, 0, -45], ['Sale', 4, 1, -7]]),
  ('variant scenario 2',
   ([['Leeds', 0, 3, 'Bath', 1, 10],
     ['Sale', 5, 5, 'Wasps', 3, 20],
     ['Bath', 6, 20, 'Sale', 3, 10],
     ['Sale', 4, 17, 'Bath', 5, 7],
     ['Sale', 6, 15, 'Leeds', 0, 10],
     ['Wasps', 3, 22, 'Bath', 0, 27]],),
   [['Bath', 14, 3, 12], ['Sale', 11, 2, -10], ['Wasps', 5, 1, 10], ['Leeds', 2, 0, -12]])],
 [('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: losing bonus result guard',
   ([['Leeds', 3, 20, 'Bath', 1, 22],
     ['Sale', 1, 3, 'Leeds', 0, 20],
     ['Wasps', 4, 5, 'Bath', 1, 12],
     ['Sale', 3, 22, 'Leeds', 0, 20]],),
   [['Bath', 8, 2, 9], ['Leeds', 6, 1, 13], ['Sale', 4, 1, -15], ['Wasps', 2, 0, -7]]),
  ('regression: losing bonus result guard',
   ([['Leeds', 1, 33, 'Wasps', 6, 27],
     ['Sale', 3, 7, 'Bath', 3, 30],
     ['Sale', 0, 5, 'Wasps', 2, 5],
     ['Leeds', 6, 7, 'Sale', 5, 7],
     ['Bath', 0, 5, 'Wasps', 4, 10]],),
   [['Wasps', 9, 1, -1], ['Leeds', 7, 1, 6], ['Bath', 5, 1, 18], ['Sale', 5, 0, -23]]),
  ('variant scenario 1',
   ([['Sale', 1, 22, 'Bath', 1, 3],
     ['Bath', 0, 15, 'Leeds', 1, 22],
     ['Wasps', 3, 5, 'Bath', 3, 17],
     ['Leeds', 5, 12, 'Wasps', 0, 3],
     ['Sale', 2, 24, 'Bath', 3, 20],
     ['Sale', 0, 27, 'Leeds', 2, 15],
     ['Wasps', 6, 20, 'Bath', 6, 24]],),
   [['Sale', 12, 3, 35], ['Bath', 11, 2, -14], ['Leeds', 9, 2, 4], ['Wasps', 2, 0, -25]]),
  ('variant scenario 2',
   ([['Bath', 2, 33, 'Wasps', 2, 27], ['Bath', 3, 12, 'Leeds', 1, 20]],),
   [['Leeds', 4, 1, 8], ['Bath', 4, 1, -2], ['Wasps', 1, 0, -6]])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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(results):
    table = {}
    for t1, tr1, s1, t2, tr2, s2 in results:
        for team, tries, s, o in ((t1, tr1, s1, s2), (t2, tr2, s2, s1)):
            row = table.setdefault(team, [0, 0, 0])
            if s > o:
                row[0] += 4
                row[1] += 1
            elif s == o:
                row[0] += 2
            if tries >= 4:
                row[0] += 1
            if s <= o and o - s <= 7:
                row[0] += 1
            row[2] += s - o
    order = sorted(table, key=lambda t: (-table[t][0], -table[t][1], -table[t][2], t))
    return [[t] + table[t] for t in order]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: losing bonus result guard',
   ([['Leeds', 1, 24, 'Wasps', 4, 3],
     ['Bath', 3, 30, 'Wasps', 6, 3],
     ['Leeds', 0, 15, 'Wasps', 5, 30],
     ['Wasps', 3, 22, 'Bath', 2, 7],
     ['Sale', 5, 7, 'Bath', 3, 5]],),
   [['Wasps', 11, 2, -18], ['Bath', 5, 1, 10], ['Sale', 5, 1, 2], ['Leeds', 4, 1, 6]]),
  ('regression: losing bonus result guard',
   ([['Leeds', 2, 7, 'Wasps', 0, 5],
     ['Bath', 4, 17, 'Sale', 6, 17],
     ['Sale', 3, 15, 'Leeds', 1, 24],
     ['Wasps', 0, 30, 'Leeds', 5, 20],
     ['Leeds', 0, 3, 'Wasps', 2, 30]],),
   [['Wasps', 9, 2, 35], ['Leeds', 9, 2, -26], ['Bath', 3, 0, 0], ['Sale', 3, 0, -9]]),
  ('variant scenario 1',
   ([['Bath', 2, 20, 'Sale', 1, 24],
     ['Wasps', 1, 30, 'Leeds', 1, 3],
     ['Leeds', 2, 15, 'Bath', 5, 12],
     ['Bath', 0, 22, 'Leeds', 4, 7],
     ['Bath', 1, 30, 'Leeds', 1, 20]],),
   [['Bath', 11, 2, 18], ['Leeds', 5, 1, -49], ['Wasps', 4, 1, 27], ['Sale', 4, 1, 4]]),
  ('variant scenario 2',
   ([['Wasps', 6, 15, 'Sale', 2, 5], ['Leeds', 3, 20, 'Bath', 0, 17]],),
   [['Wasps', 5, 1, 10], ['Leeds', 4, 1, 3], ['Bath', 1, 0, -3], ['Sale', 0, 0, -10]])],
 [('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: losing bonus result guard',
   ([['Sale', 1, 24, 'Bath', 5, 5], ['Bath', 2, 15, 'Sale', 6, 5]],),
   [['Sale', 5, 1, 9], ['Bath', 5, 1, -9]]),
  ('regression: losing bonus result guard',
   ([['Leeds', 4, 12, 'Wasps', 2, 12],
     ['Wasps', 5, 22, 'Sale', 2, 17],
     ['Wasps', 2, 30, 'Leeds', 4, 24]],),
   [['Wasps', 11, 2, 11], ['Leeds', 5, 0, -6], ['Sale', 1, 0, -5]]),
  ('variant scenario 1',
   ([['Sale', 6, 20, 'Bath', 6, 22],
     ['Leeds', 1, 22, 'Wasps', 1, 20],
     ['Wasps', 0, 17, 'Bath', 3, 10],
     ['Leeds', 6, 15, 'Bath', 3, 30],
     ['Leeds', 3, 33, 'Bath', 5, 22],
     ['Wasps', 2, 3, 'Sale', 1, 5]],),
   [['Bath', 11, 2, -1], ['Leeds', 9, 2, -2], ['Wasps', 6, 1, 3], ['Sale', 6, 1, 0]]),
  ('variant scenario 2',
   ([['Wasps', 1, 27, 'Sale', 0, 24],
     ['Leeds', 1, 24, 'Bath', 1, 15],
     ['Sale', 4, 10, 'Bath', 2, 27]],),
   [['Leeds', 4, 1, 9], ['Bath', 4, 1, 8], ['Wasps', 4, 1, 3], ['Sale', 2, 0, -20]])],
 [('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: losing bonus result guard',
   ([['Wasps', 3, 33, 'Bath', 5, 10],
     ['Sale', 3, 5, 'Wasps', 5, 15],
     ['Sale', 1, 22, 'Leeds', 4, 7],
     ['Sale', 5, 10, 'Wasps', 1, 3],
     ['Leeds', 0, 10, 'Wasps', 3, 30],
     ['Leeds', 3, 17, 'Wasps', 4, 27]],),
   [['Wasps', 19, 4, 56], ['Sale', 9, 2, 12], ['Bath', 1, 0, -23], ['Leeds', 1, 0, -45]]),
  ('regression: losing bonus result guard',
   ([['Wasps', 0, 7, 'Bath', 5, 22],
     ['Bath', 2, 22, 'Leeds', 5, 27],
     ['Bath', 3, 5, 'Wasps', 5, 30],
     ['Bath', 0, 5, 'Wasps', 6, 3],
     ['Sale', 1, 10, 'Bath', 1, 10],
     ['Wasps', 5, 15, 'Sale', 2, 10]],),
   [['Wasps', 12, 2, 13], ['Bath', 12, 2, -13], ['Leeds', 5, 1, 5], ['Sale', 3, 0, -5]]),
  ('variant scenario 1',
   ([['Sale', 5, 24, 'Wasps', 1, 17],
     ['Sale', 2, 24, 'Wasps', 6, 27],
     ['Leeds', 2, 24, 'Wasps', 3, 30]],),
   [['Wasps', 10, 2, 2], ['Sale', 6, 1, 4], ['Leeds', 1, 0, -6]]),
  ('variant scenario 2',
   ([['Leeds', 4, 30, 'Bath', 5, 3],
     ['Wasps', 3, 5, 'Bath', 6, 30],
     ['Leeds', 2, 27, 'Wasps', 1, 12],
     ['Leeds', 3, 17, 'Sale', 1, 7]],),
   [['Leeds', 13, 3, 52], ['Bath', 6, 1, -2], ['Sale', 0, 0, -10], ['Wasps', 0, 0, -40]])],
 [('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: losing bonus result guard',
   ([['Bath', 1, 5, 'Leeds', 1, 10],
     ['Sale', 0, 30, 'Bath', 4, 5],
     ['Leeds', 3, 5, 'Wasps', 1, 17],
     ['Bath', 4, 15, 'Leeds', 3, 7],
     ['Bath', 5, 27, 'Wasps', 0, 7]],),
   [['Bath', 12, 2, -2], ['Sale', 4, 1, 25], ['Wasps', 4, 1, -8], ['Leeds', 4, 1, -15]]),
  ('regression: losing bonus result guard',
   ([['Wasps', 6, 12, 'Sale', 1, 12],
     ['Bath', 3, 12, 'Wasps', 1, 24],
     ['Wasps', 6, 27, 'Bath', 2, 10],
     ['Bath', 3, 33, 'Wasps', 5, 3]],),
   [['Wasps', 13, 2, -1], ['Bath', 4, 1, 1], ['Sale', 2, 0, 0]]),
  ('variant scenario 1',
   ([['Leeds', 0, 33, 'Wasps', 5, 30],
     ['Leeds', 1, 22, 'Sale', 2, 12],
     ['Leeds', 3, 22, 'Wasps', 0, 10],
     ['Wasps', 5, 17, 'Bath', 1, 24],
     ['Wasps', 3, 7, 'Sale', 2, 10],
     ['Bath', 5, 17, 'Leeds', 3, 3],
     ['Wasps', 2, 10, 'Leeds', 5, 30],
     ['Leeds', 4, 12, 'Bath', 2, 30]],),
   [['Leeds', 18, 4, 13], ['Bath', 13, 3, 39], ['Wasps', 5, 0, -45], ['Sale', 4, 1, -7]]),
  ('variant scenario 2',
   ([['Leeds', 0, 3, 'Bath', 1, 10],
     ['Sale', 5, 5, 'Wasps', 3, 20],
     ['Bath', 6, 20, 'Sale', 3, 10],
     ['Sale', 4, 17, 'Bath', 5, 7],
     ['Sale', 6, 15, 'Leeds', 0, 10],
     ['Wasps', 3, 22, 'Bath', 0, 27]],),
   [['Bath', 14, 3, 12], ['Sale', 11, 2, -10], ['Wasps', 5, 1, 10], ['Leeds', 2, 0, -12]])],
 [('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: losing bonus result guard',
   ([['Leeds', 3, 20, 'Bath', 1, 22],
     ['Sale', 1, 3, 'Leeds', 0, 20],
     ['Wasps', 4, 5, 'Bath', 1, 12],
     ['Sale', 3, 22, 'Leeds', 0, 20]],),
   [['Bath', 8, 2, 9], ['Leeds', 6, 1, 13], ['Sale', 4, 1, -15], ['Wasps', 2, 0, -7]]),
  ('regression: losing bonus result guard',
   ([['Leeds', 1, 33, 'Wasps', 6, 27],
     ['Sale', 3, 7, 'Bath', 3, 30],
     ['Sale', 0, 5, 'Wasps', 2, 5],
     ['Leeds', 6, 7, 'Sale', 5, 7],
     ['Bath', 0, 5, 'Wasps', 4, 10]],),
   [['Wasps', 9, 1, -1], ['Leeds', 7, 1, 6], ['Bath', 5, 1, 18], ['Sale', 5, 0, -23]]),
  ('variant scenario 1',
   ([['Sale', 1, 22, 'Bath', 1, 3],
     ['Bath', 0, 15, 'Leeds', 1, 22],
     ['Wasps', 3, 5, 'Bath', 3, 17],
     ['Leeds', 5, 12, 'Wasps', 0, 3],
     ['Sale', 2, 24, 'Bath', 3, 20],
     ['Sale', 0, 27, 'Leeds', 2, 15],
     ['Wasps', 6, 20, 'Bath', 6, 24]],),
   [['Sale', 12, 3, 35], ['Bath', 11, 2, -14], ['Leeds', 9, 2, 4], ['Wasps', 2, 0, -25]]),
  ('variant scenario 2',
   ([['Bath', 2, 33, 'Wasps', 2, 27], ['Bath', 3, 12, 'Leeds', 1, 20]],),
   [['Leeds', 4, 1, 8], ['Bath', 4, 1, -2], ['Wasps', 1, 0, -6]])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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:
Drawn and winning teams collect a losing bonus point.

Rugby union league points. results rows are [team, tries, score, opponent, opp_tries, opp_score]. Win 4 points, draw 2, loss 0. A try bonus point is earned by any team scoring 4 or more tries, and a losing bonus point by a team that loses by 7 points or fewer (both can apply to a loser). Rank by points, then wins, then points difference, then name. Return [team, points, wins, points difference] rows for teams that appear.

split: open-access


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

N = 1
observations = []
def solve(results):
    table = {}
    for t1, tr1, s1, t2, tr2, s2 in results:
        for team, tries, s, o in ((t1, tr1, s1, s2), (t2, tr2, s2, s1)):
            row = table.setdefault(team, [0, 0, 0])
            if s > o:
                row[0] += 4
                row[1] += 1
            elif s == o:
                row[0] += 2
            if tries >= 4:
                row[0] += 1
            if s < o and o - s <= 7:
                row[0] += 1
            row[2] += s - o
    order = sorted(table, key=lambda t: (-table[t][0], -table[t][2], -table[t][1], t))
    return [[t] + table[t] for t in order]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: table tiebreak order',
   ([['Sale', 1, 10, 'Wasps', 5, 15], ['Bath', 3, 17, 'Leeds', 4, 5]],),
   [['Wasps', 5, 1, 5], ['Bath', 4, 1, 12], ['Sale', 1, 0, -5], ['Leeds', 1, 0, -12]]),
  ('regression: table tiebreak order',
   ([['Wasps', 6, 27, 'Sale', 0, 27],
     ['Sale', 0, 5, 'Bath', 2, 12],
     ['Bath', 2, 7, 'Sale', 4, 3],
     ['Wasps', 5, 33, 'Sale', 4, 10]],),
   [['Bath', 8, 2, 11], ['Wasps', 8, 1, 23], ['Sale', 6, 0, -34]]),
  ('variant scenario 1',
   ([['Bath', 5, 3, 'Leeds', 3, 3],
     ['Wasps', 2, 3, 'Bath', 4, 27],
     ['Wasps', 0, 3, 'Sale', 4, 7],
     ['Leeds', 5, 33, 'Wasps', 0, 17]],),
   [['Bath', 8, 1, 24], ['Leeds', 7, 1, 16], ['Sale', 5, 1, 4], ['Wasps', 1, 0, -44]]),
  ('variant scenario 2',
   ([['Bath', 0, 5, 'Sale', 3, 12],
     ['Wasps', 0, 12, 'Leeds', 6, 27],
     ['Wasps', 2, 5, 'Leeds', 0, 12],
     ['Sale', 1, 10, 'Leeds', 5, 30]],),
   [['Leeds', 14, 3, 42], ['Sale', 4, 1, -13], ['Bath', 1, 0, -7], ['Wasps', 1, 0, -22]])],
 [('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: table tiebreak order',
   ([['Wasps', 1, 10, 'Bath', 0, 17], ['Bath', 4, 7, 'Sale', 4, 24]],),
   [['Sale', 5, 1, 17], ['Bath', 5, 1, -10], ['Wasps', 1, 0, -7]]),
  ('regression: table tiebreak order',
   ([['Sale', 0, 3, 'Wasps', 1, 5],
     ['Bath', 6, 15, 'Leeds', 3, 27],
     ['Sale', 6, 7, 'Bath', 2, 7],
     ['Bath', 3, 27, 'Wasps', 0, 17],
     ['Wasps', 3, 7, 'Leeds', 3, 17]],),
   [['Leeds', 8, 2, 22], ['Bath', 7, 1, -2], ['Wasps', 4, 1, -18], ['Sale', 4, 0, -2]]),
  ('variant scenario 1',
   ([['Wasps', 4, 7, 'Leeds', 3, 30],
     ['Leeds', 4, 20, 'Sale', 2, 3],
     ['Sale', 0, 7, 'Leeds', 1, 17],
     ['Bath', 4, 3, 'Sale', 0, 20],
     ['Sale', 5, 10, 'Bath', 6, 17],
     ['Sale', 2, 12, 'Bath', 2, 5]],),
   [['Leeds', 13, 3, 50], ['Sale', 10, 2, -10], ['Bath', 7, 1, -17], ['Wasps', 1, 0, -23]]),
  ('variant scenario 2',
   ([['Wasps', 5, 5, 'Bath', 0, 12],
     ['Sale', 4, 27, 'Bath', 5, 27],
     ['Sale', 1, 3, 'Wasps', 3, 24]],),
   [['Bath', 7, 1, 7], ['Wasps', 6, 1, 14], ['Sale', 3, 0, -21]])],
 [('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: table tiebreak order',
   ([['Leeds', 6, 30, 'Wasps', 6, 27],
     ['Wasps', 3, 5, 'Leeds', 6, 10],
     ['Sale', 6, 10, 'Bath', 6, 10]],),
   [['Leeds', 10, 2, 8], ['Bath', 3, 0, 0], ['Sale', 3, 0, 0], ['Wasps', 3, 0, -8]]),
  ('regression: table tiebreak order',
   ([['Sale', 5, 33, 'Bath', 0, 7],
     ['Wasps', 3, 7, 'Bath', 3, 24],
     ['Wasps', 2, 27, 'Bath', 1, 17],
     ['Bath', 4, 24, 'Sale', 2, 22],
     ['Bath', 5, 20, 'Wasps', 0, 24],
     ['Sale', 3, 5, 'Bath', 0, 7],
     ['Leeds', 0, 30, 'Sale', 5, 17]],),
   [['Bath', 15, 3, -19], ['Wasps', 8, 2, -3], ['Sale', 8, 1, 9], ['Leeds', 4, 1, 13]]),
  ('variant scenario 1',
   ([['Leeds', 6, 22, 'Sale', 2, 27],
     ['Leeds', 1, 20, 'Wasps', 6, 24],
     ['Sale', 3, 33, 'Bath', 4, 24],
     ['Wasps', 0, 24, 'Leeds', 6, 17],
     ['Leeds', 6, 15, 'Wasps', 5, 17],
     ['Wasps', 2, 24, 'Sale', 3, 3]],),
   [['Wasps', 18, 4, 34], ['Sale', 8, 2, -7], ['Leeds', 7, 0, -18], ['Bath', 1, 0, -9]]),
  ('variant scenario 2',
   ([['Wasps', 3, 7, 'Sale', 3, 5], ['Sale', 0, 30, 'Wasps', 0, 30]],),
   [['Wasps', 6, 1, 2], ['Sale', 3, 0, -2]])],
 [('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: table tiebreak order',
   ([['Leeds', 2, 7, 'Bath', 2, 27],
     ['Sale', 5, 30, 'Bath', 3, 12],
     ['Sale', 3, 15, 'Leeds', 5, 30],
     ['Bath', 2, 10, 'Sale', 2, 27],
     ['Bath', 4, 5, 'Wasps', 6, 22]],),
   [['Sale', 9, 2, 20], ['Wasps', 5, 1, 17], ['Leeds', 5, 1, -5], ['Bath', 5, 1, -32]]),
  ('regression: table tiebreak order',
   ([['Bath', 5, 5, 'Wasps', 3, 7],
     ['Sale', 0, 30, 'Wasps', 0, 27],
     ['Wasps', 1, 33, 'Bath', 5, 22],
     ['Wasps', 4, 12, 'Bath', 3, 7],
     ['Sale', 3, 7, 'Bath', 5, 27],
     ['Sale', 4, 22, 'Wasps', 5, 5]],),
   [['Wasps', 15, 3, -2], ['Sale', 9, 2, 0], ['Bath', 9, 1, 2]]),
  ('variant scenario 1',
   ([['Bath', 4, 3, 'Wasps', 1, 7],
     ['Bath', 6, 30, 'Sale', 3, 15],
     ['Sale', 1, 12, 'Bath', 2, 10],
     ['Bath', 3, 12, 'Wasps', 4, 17]],),
   [['Wasps', 9, 2, 9], ['Bath', 9, 1, 4], ['Sale', 4, 1, -13]]),
  ('variant scenario 2',
   ([['Leeds', 5, 12, 'Sale', 6, 22],
     ['Wasps', 6, 3, 'Sale', 1, 15],
     ['Sale', 3, 33, 'Leeds', 2, 7],
     ['Bath', 0, 30, 'Leeds', 4, 17],
     ['Sale', 1, 33, 'Bath', 1, 27],
     ['Leeds', 5, 15, 'Bath', 2, 22],
     ['Wasps', 1, 12, 'Sale', 2, 15]],),
   [['Sale', 21, 5, 57], ['Bath', 9, 2, 14], ['Leeds', 4, 0, -56], ['Wasps', 2, 0, -15]])],
 [('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: table tiebreak order',
   ([['Leeds', 5, 3, 'Wasps', 4, 24], ['Bath', 3, 10, 'Sale', 6, 20]],),
   [['Wasps', 5, 1, 21], ['Sale', 5, 1, 10], ['Leeds', 1, 0, -21], ['Bath', 0, 0, -10]]),
  ('regression: table tiebreak order',
   ([['Bath', 4, 17, 'Sale', 0, 30],
     ['Wasps', 2, 5, 'Sale', 0, 17],
     ['Wasps', 1, 22, 'Leeds', 2, 3],
     ['Bath', 1, 22, 'Sale', 3, 22],
     ['Wasps', 2, 3, 'Leeds', 3, 24],
     ['Bath', 3, 20, 'Wasps', 0, 20],
     ['Bath', 5, 33, 'Sale', 2, 7]],),
   [['Sale', 10, 2, -1], ['Bath', 10, 1, 13], ['Wasps', 6, 1, -14], ['Leeds', 4, 1, 2]]),
  ('variant scenario 1',
   ([['Leeds', 5, 15, 'Bath', 4, 10],
     ['Bath', 1, 22, 'Wasps', 2, 7],
     ['Wasps', 6, 22, 'Sale', 4, 27],
     ['Bath', 4, 12, 'Sale', 1, 27],
     ['Leeds', 1, 15, 'Sale', 1, 24],
     ['Leeds', 5, 30, 'Wasps', 4, 5]],),
   [['Sale', 13, 3, 29], ['Leeds', 10, 2, 21], ['Bath', 7, 1, -5], ['Wasps', 3, 0, -45]]),
  ('variant scenario 2',
   ([['Leeds', 0, 33, 'Wasps', 4, 30],
     ['Wasps', 3, 22, 'Sale', 6, 12],
     ['Wasps', 3, 20, 'Bath', 5, 27]],),
   [['Wasps', 7, 1, 0], ['Bath', 5, 1, 7], ['Leeds', 4, 1, 3], ['Sale', 1, 0, -10]])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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(results):
    table = {}
    for t1, tr1, s1, t2, tr2, s2 in results:
        for team, tries, s, o in ((t1, tr1, s1, s2), (t2, tr2, s2, s1)):
            row = table.setdefault(team, [0, 0, 0])
            if s > o:
                row[0] += 4
                row[1] += 1
            elif s == o:
                row[0] += 2
            if tries >= 4:
                row[0] += 1
            if s < o and o - s <= 7:
                row[0] += 1
            row[2] += s - o
    order = sorted(table, key=lambda t: (-table[t][0], -table[t][1], table[t][2], t))
    return [[t] + table[t] for t in order]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: table tiebreak order',
   ([['Sale', 1, 10, 'Wasps', 5, 15], ['Bath', 3, 17, 'Leeds', 4, 5]],),
   [['Wasps', 5, 1, 5], ['Bath', 4, 1, 12], ['Sale', 1, 0, -5], ['Leeds', 1, 0, -12]]),
  ('regression: table tiebreak order',
   ([['Wasps', 6, 27, 'Sale', 0, 27],
     ['Sale', 0, 5, 'Bath', 2, 12],
     ['Bath', 2, 7, 'Sale', 4, 3],
     ['Wasps', 5, 33, 'Sale', 4, 10]],),
   [['Bath', 8, 2, 11], ['Wasps', 8, 1, 23], ['Sale', 6, 0, -34]]),
  ('variant scenario 1',
   ([['Bath', 5, 3, 'Leeds', 3, 3],
     ['Wasps', 2, 3, 'Bath', 4, 27],
     ['Wasps', 0, 3, 'Sale', 4, 7],
     ['Leeds', 5, 33, 'Wasps', 0, 17]],),
   [['Bath', 8, 1, 24], ['Leeds', 7, 1, 16], ['Sale', 5, 1, 4], ['Wasps', 1, 0, -44]]),
  ('variant scenario 2',
   ([['Bath', 0, 5, 'Sale', 3, 12],
     ['Wasps', 0, 12, 'Leeds', 6, 27],
     ['Wasps', 2, 5, 'Leeds', 0, 12],
     ['Sale', 1, 10, 'Leeds', 5, 30]],),
   [['Leeds', 14, 3, 42], ['Sale', 4, 1, -13], ['Bath', 1, 0, -7], ['Wasps', 1, 0, -22]])],
 [('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: table tiebreak order',
   ([['Wasps', 1, 10, 'Bath', 0, 17], ['Bath', 4, 7, 'Sale', 4, 24]],),
   [['Sale', 5, 1, 17], ['Bath', 5, 1, -10], ['Wasps', 1, 0, -7]]),
  ('regression: table tiebreak order',
   ([['Sale', 0, 3, 'Wasps', 1, 5],
     ['Bath', 6, 15, 'Leeds', 3, 27],
     ['Sale', 6, 7, 'Bath', 2, 7],
     ['Bath', 3, 27, 'Wasps', 0, 17],
     ['Wasps', 3, 7, 'Leeds', 3, 17]],),
   [['Leeds', 8, 2, 22], ['Bath', 7, 1, -2], ['Wasps', 4, 1, -18], ['Sale', 4, 0, -2]]),
  ('variant scenario 1',
   ([['Wasps', 4, 7, 'Leeds', 3, 30],
     ['Leeds', 4, 20, 'Sale', 2, 3],
     ['Sale', 0, 7, 'Leeds', 1, 17],
     ['Bath', 4, 3, 'Sale', 0, 20],
     ['Sale', 5, 10, 'Bath', 6, 17],
     ['Sale', 2, 12, 'Bath', 2, 5]],),
   [['Leeds', 13, 3, 50], ['Sale', 10, 2, -10], ['Bath', 7, 1, -17], ['Wasps', 1, 0, -23]]),
  ('variant scenario 2',
   ([['Wasps', 5, 5, 'Bath', 0, 12],
     ['Sale', 4, 27, 'Bath', 5, 27],
     ['Sale', 1, 3, 'Wasps', 3, 24]],),
   [['Bath', 7, 1, 7], ['Wasps', 6, 1, 14], ['Sale', 3, 0, -21]])],
 [('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: table tiebreak order',
   ([['Leeds', 6, 30, 'Wasps', 6, 27],
     ['Wasps', 3, 5, 'Leeds', 6, 10],
     ['Sale', 6, 10, 'Bath', 6, 10]],),
   [['Leeds', 10, 2, 8], ['Bath', 3, 0, 0], ['Sale', 3, 0, 0], ['Wasps', 3, 0, -8]]),
  ('regression: table tiebreak order',
   ([['Sale', 5, 33, 'Bath', 0, 7],
     ['Wasps', 3, 7, 'Bath', 3, 24],
     ['Wasps', 2, 27, 'Bath', 1, 17],
     ['Bath', 4, 24, 'Sale', 2, 22],
     ['Bath', 5, 20, 'Wasps', 0, 24],
     ['Sale', 3, 5, 'Bath', 0, 7],
     ['Leeds', 0, 30, 'Sale', 5, 17]],),
   [['Bath', 15, 3, -19], ['Wasps', 8, 2, -3], ['Sale', 8, 1, 9], ['Leeds', 4, 1, 13]]),
  ('variant scenario 1',
   ([['Leeds', 6, 22, 'Sale', 2, 27],
     ['Leeds', 1, 20, 'Wasps', 6, 24],
     ['Sale', 3, 33, 'Bath', 4, 24],
     ['Wasps', 0, 24, 'Leeds', 6, 17],
     ['Leeds', 6, 15, 'Wasps', 5, 17],
     ['Wasps', 2, 24, 'Sale', 3, 3]],),
   [['Wasps', 18, 4, 34], ['Sale', 8, 2, -7], ['Leeds', 7, 0, -18], ['Bath', 1, 0, -9]]),
  ('variant scenario 2',
   ([['Wasps', 3, 7, 'Sale', 3, 5], ['Sale', 0, 30, 'Wasps', 0, 30]],),
   [['Wasps', 6, 1, 2], ['Sale', 3, 0, -2]])],
 [('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: table tiebreak order',
   ([['Leeds', 2, 7, 'Bath', 2, 27],
     ['Sale', 5, 30, 'Bath', 3, 12],
     ['Sale', 3, 15, 'Leeds', 5, 30],
     ['Bath', 2, 10, 'Sale', 2, 27],
     ['Bath', 4, 5, 'Wasps', 6, 22]],),
   [['Sale', 9, 2, 20], ['Wasps', 5, 1, 17], ['Leeds', 5, 1, -5], ['Bath', 5, 1, -32]]),
  ('regression: table tiebreak order',
   ([['Bath', 5, 5, 'Wasps', 3, 7],
     ['Sale', 0, 30, 'Wasps', 0, 27],
     ['Wasps', 1, 33, 'Bath', 5, 22],
     ['Wasps', 4, 12, 'Bath', 3, 7],
     ['Sale', 3, 7, 'Bath', 5, 27],
     ['Sale', 4, 22, 'Wasps', 5, 5]],),
   [['Wasps', 15, 3, -2], ['Sale', 9, 2, 0], ['Bath', 9, 1, 2]]),
  ('variant scenario 1',
   ([['Bath', 4, 3, 'Wasps', 1, 7],
     ['Bath', 6, 30, 'Sale', 3, 15],
     ['Sale', 1, 12, 'Bath', 2, 10],
     ['Bath', 3, 12, 'Wasps', 4, 17]],),
   [['Wasps', 9, 2, 9], ['Bath', 9, 1, 4], ['Sale', 4, 1, -13]]),
  ('variant scenario 2',
   ([['Leeds', 5, 12, 'Sale', 6, 22],
     ['Wasps', 6, 3, 'Sale', 1, 15],
     ['Sale', 3, 33, 'Leeds', 2, 7],
     ['Bath', 0, 30, 'Leeds', 4, 17],
     ['Sale', 1, 33, 'Bath', 1, 27],
     ['Leeds', 5, 15, 'Bath', 2, 22],
     ['Wasps', 1, 12, 'Sale', 2, 15]],),
   [['Sale', 21, 5, 57], ['Bath', 9, 2, 14], ['Leeds', 4, 0, -56], ['Wasps', 2, 0, -15]])],
 [('control plain win',
   ([['Bath', 2, 20, 'Leeds', 1, 10]],),
   [['Bath', 4, 1, 10], ['Leeds', 0, 0, -10]]),
  ('boundary losing by seven',
   ([['Bath', 1, 17, 'Leeds', 2, 10]],),
   [['Bath', 4, 1, 7], ['Leeds', 1, 0, -7]]),
  ('boundary four tries in defeat',
   ([['Bath', 3, 30, 'Leeds', 4, 24]],),
   [['Bath', 4, 1, 6], ['Leeds', 2, 0, -6]]),
  ('control draw', ([['Bath', 1, 10, 'Leeds', 1, 10]],), [['Bath', 2, 0, 0], ['Leeds', 2, 0, 0]]),
  ('boundary losing by eight',
   ([['Sale', 2, 18, 'Wasps', 1, 10]],),
   [['Sale', 4, 1, 8], ['Wasps', 0, 0, -8]]),
  ('regression: table tiebreak order',
   ([['Leeds', 5, 3, 'Wasps', 4, 24], ['Bath', 3, 10, 'Sale', 6, 20]],),
   [['Wasps', 5, 1, 21], ['Sale', 5, 1, 10], ['Leeds', 1, 0, -21], ['Bath', 0, 0, -10]]),
  ('regression: table tiebreak order',
   ([['Bath', 4, 17, 'Sale', 0, 30],
     ['Wasps', 2, 5, 'Sale', 0, 17],
     ['Wasps', 1, 22, 'Leeds', 2, 3],
     ['Bath', 1, 22, 'Sale', 3, 22],
     ['Wasps', 2, 3, 'Leeds', 3, 24],
     ['Bath', 3, 20, 'Wasps', 0, 20],
     ['Bath', 5, 33, 'Sale', 2, 7]],),
   [['Sale', 10, 2, -1], ['Bath', 10, 1, 13], ['Wasps', 6, 1, -14], ['Leeds', 4, 1, 2]]),
  ('variant scenario 1',
   ([['Leeds', 5, 15, 'Bath', 4, 10],
     ['Bath', 1, 22, 'Wasps', 2, 7],
     ['Wasps', 6, 22, 'Sale', 4, 27],
     ['Bath', 4, 12, 'Sale', 1, 27],
     ['Leeds', 1, 15, 'Sale', 1, 24],
     ['Leeds', 5, 30, 'Wasps', 4, 5]],),
   [['Sale', 13, 3, 29], ['Leeds', 10, 2, 21], ['Bath', 7, 1, -5], ['Wasps', 3, 0, -45]]),
  ('variant scenario 2',
   ([['Leeds', 0, 33, 'Wasps', 4, 30],
     ['Wasps', 3, 22, 'Sale', 6, 12],
     ['Wasps', 3, 20, 'Bath', 5, 27]],),
   [['Wasps', 7, 1, 0], ['Bath', 5, 1, 7], ['Leeds', 4, 1, 3], ['Sale', 1, 0, -10]])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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:
Teams level on points are ordered by points difference instead of wins.

Rugby union league points. results rows are [team, tries, score, opponent, opp_tries, opp_score]. Win 4 points, draw 2, loss 0. A try bonus point is earned by any team scoring 4 or more tries, and a losing bonus point by a team that loses by 7 points or fewer (both can apply to a loser). Rank by points, then wins, then points difference, then name. Return [team, points, wins, points difference] rows for teams that appear.

split: open-access


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

N = 1
observations = []
def solve(games):
    t = {}
    for h, hg, a, ag, decided, so_winner in games:
        if decided == 'SO':
            if so_winner == h:
                hg += 1
            else:
                ag += 1
        for team, f, g in ((h, hg, ag), (a, ag, hg)):
            row = t.setdefault(team, {'pts': 0, 'rw': 0, 'row': 0, 'w': 0, 'gd': 0})
            row['gd'] += f - g
            if f > g:
                row['pts'] += 2
                row['w'] += 1
                if decided == 'REG':
                    row['rw'] += 1
                if decided != 'SO':
                    row['row'] += 1
            elif decided == 'SO':
                row['pts'] += 1
    order = sorted(t, key=lambda k: (-t[k]['pts'], -t[k]['rw'], -t[k]['row'], -t[k]['w'], -t[k]['gd'], k))
    return [[k, t[k]['pts'], t[k]['rw'], t[k]['row'], t[k]['w'], t[k]['gd']] for k in order]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control regulation win',
   ([['Bears', 3, 'Hawks', 1, 'REG', None]],),
   [['Bears', 2, 1, 1, 1, 2], ['Hawks', 0, 0, 0, 0, -2]]),
  ('boundary overtime loss point',
   ([['Bears', 2, 'Hawks', 3, 'OT', None]],),
   [['Hawks', 2, 0, 1, 1, 1], ['Bears', 1, 0, 0, 0, -1]]),
  ('boundary shootout goal credit',
   ([['Bears', 2, 'Hawks', 2, 'SO', 'Hawks']],),
   [['Hawks', 2, 0, 0, 1, 1], ['Bears', 1, 0, 0, 0, -1]]),
  ('boundary RW breaks tie',
   ([['Bears', 1, 'Lynx', 0, 'REG', None], ['Hawks', 1, 'Otters', 0, 'OT', None]],),
   [['Bears', 2, 1, 1, 1, 1],
    ['Hawks', 2, 0, 1, 1, 1],
    ['Otters', 1, 0, 0, 0, -1],
    ['Lynx', 0, 0, 0, 0, -1]]),
  ('regression: overtime loser point',
   ([['Bears', 3, 'Lynx', 3, 'SO', 'Bears'],
     ['Lynx', 4, 'Hawks', 1, 'REG', None],
     ['Otters', 0, 'Bears', 3, 'REG', None],
     ['Hawks', 0, 'Otters', 4, 'REG', None],
     ['Lynx', 5, 'Otters', 3, 'REG', None],
     ['Lynx', 3, 'Otters', 3, 'SO', 'Lynx']],),
   [['Lynx', 7, 2, 2, 3, 5],
    ['Bears', 4, 1, 1, 2, 4],
    ['Otters', 3, 1, 1, 1, -2],
    ['Hawks', 0, 0, 0, 0, -7]]),
  ('regression: overtime loser point',
   ([['Otters', 5, 'Hawks', 4, 'OT', None],
     ['Bears', 0, 'Lynx', 0, 'SO', 'Lynx'],
     ['Hawks', 3, 'Otters', 5, 'REG', None],
     ['Hawks', 0, 'Otters', 1, 'REG', None]],),
   [['Otters', 6, 2, 3, 3, 4],
    ['Lynx', 2, 0, 0, 1, 1],
    ['Bears', 1, 0, 0, 0, -1],
    ['Hawks', 1, 0, 0, 0, -4]]),
  ('variant scenario 1',
   ([['Lynx', 0, 'Hawks', 0, 'SO', 'Lynx'],
     ['Bears', 1, 'Lynx', 1, 'SO', 'Lynx'],
     ['Hawks', 4, 'Lynx', 3, 'REG', None],
     ['Otters', 2, 'Hawks', 2, 'SO', 'Hawks'],
     ['Bears', 2, 'Hawks', 5, 'REG', None],
     ['Bears', 0, 'Lynx', 0, 'SO', 'Lynx']],),
   [['Hawks', 7, 2, 2, 3, 4],
    ['Lynx', 6, 0, 0, 3, 2],
    ['Bears', 2, 0, 0, 0, -5],
    ['Otters', 1, 0, 0, 0, -1]]),
  ('variant scenario 2',
   ([['Hawks', 2, 'Bears', 2, 'SO', 'Bears'],
     ['Lynx', 3, 'Otters', 2, 'REG', None],
     ['Lynx', 2, 'Bears', 4, 'REG', None],
     ['Otters', 1, 'Bears', 0, 'OT', None]],),
   [['Bears', 5, 1, 1, 2, 2],
    ['Lynx', 2, 1, 1, 1, -1],
    ['Otters', 2, 0, 1, 1, 0],
    ['Hawks', 1, 0, 0, 0, -1]])],
 [('control regulation win',
   ([['Bears', 3, 'Hawks', 1, 'REG', None]],),
   [['Bears', 2, 1, 1, 1, 2], ['Hawks', 0, 0, 0, 0, -2]]),
  ('boundary overtime loss point',
   ([['Bears', 2, 'Hawks', 3, 'OT', None]],),
   [['Hawks', 2, 0, 1, 1, 1], ['Bears', 1, 0, 0, 0, -1]]),
  ('boundary shootout goal credit',
   ([['Bears', 2, 'Hawks', 2, 'SO', 'Hawks']],),
   [['Hawks', 2, 0, 0, 1, 1], ['Bears', 1, 0, 0, 0, -1]]),
  ('boundary RW breaks tie',
   ([['Bears', 1, 'Lynx', 0, 'REG', None], ['Hawks', 1, 'Otters', 0, 'OT', None]],),
   [['Bears', 2, 1, 1, 1, 1],
    ['Hawks', 2, 0, 1, 1, 1],
    ['Otters', 1, 0, 0, 0, -1],
    ['Lynx', 0, 0, 0, 0, -1]]),
  ('regression: overtime loser point',
   ([['Otters', 3, 'Lynx', 0, 'REG', None],
     ['Bears', 3, 'Otters', 3, 'SO', 'Bears'],
     ['Bears', 2, 'Lynx', 0, 'REG', None],
     ['Bears', 2, 'Otters', 3, 'OT', None],
     ['Lynx', 4, 'Hawks', 4, 'SO', 'Hawks']],),
   [['Otters', 5, 1, 2, 2, 3],
    ['Bears', 5, 1, 1, 2, 2],
    ['Hawks', 2, 0, 0, 1, 1],
    ['Lynx', 1, 0, 0, 0, -6]]),
  ('variant scenario 1',
   ([['Bears', 3, 'Hawks', 4, 'REG', None],
     ['Otters', 1, 'Bears', 1, 'SO', 'Bears'],
     ['Hawks', 5, 'Lynx', 4, 'OT', None],
     ['Hawks', 1, 'Bears', 1, 'SO', 'Hawks']],),
   [['Hawks', 6, 1, 2, 3, 3],
    ['Bears', 3, 0, 0, 1, -1],
    ['Lynx', 1, 0, 0, 0, -1],
    ['Otters', 1, 0, 0, 0, -1]]),
  ('variant scenario 2',
   ([['Lynx', 0, 'Bears', 0, 'SO', 'Bears'],
     ['Lynx', 4, 'Bears', 0, 'REG', None],
     ['Hawks', 0, 'Otters', 0, 'SO', 'Hawks'],
     ['Otters', 3, 'Hawks', 2, 'REG', None],
     ['Hawks', 4, 'Bears', 5, 'REG', None],
     ['Lynx', 0, 'Hawks', 0, 'SO', 'Hawks'],
     ['Lynx', 4, 'Bears', 5, 'OT', None]],),
   [['Bears', 6, 1, 2, 3, -1],
    ['Lynx', 5, 1, 1, 1, 1],
    ['Hawks', 4, 0, 0, 2, 0],
    ['Otters', 3, 1, 1, 1, 0]])],
 [('control regulation win',
   ([['Bears', 3, 'Hawks', 1, 'REG', None]],),
   [['Bears', 2, 1, 1, 1, 2], ['Hawks', 0, 0, 0, 0, -2]]),
  ('boundary overtime loss point',
   ([['Bears', 2, 'Hawks', 3, 'OT', None]],),
   [['Hawks', 2, 0, 1, 1, 1], ['Bears', 1, 0, 0, 0, -1]]),
  ('boundary shootout goal credit',
   ([['Bears', 2, 'Hawks', 2, 'SO', 'Hawks']],),
   [['Hawks', 2, 0, 0, 1, 1], ['Bears', 1, 0, 0, 0, -1]]),
  ('boundary RW breaks tie',
   ([['Bears', 1, 'Lynx', 0, 'REG', None], ['Hawks', 1, 'Otters', 0, 'OT', None]],),
   [['Bears', 2, 1, 1, 1, 1],
    ['Hawks', 2, 0, 1, 1, 1],
    ['Otters', 1, 0, 0, 0, -1],
    ['Lynx', 0, 0, 0, 0, -1]]),
  ('regression: overtime loser point',
   ([['Lynx', 3, 'Hawks', 4, 'REG', None],
     ['Bears', 4, 'Otters', 3, 'REG', None],
     ['Hawks', 3, 'Lynx', 3, 'SO', 'Lynx'],
     ['Otters', 5, 'Lynx', 1, 'REG', None]],),
   [['Hawks', 3, 1, 1, 1, 0],
    ['Otters', 2, 1, 1, 1, 3],
    ['Bears', 2, 1, 1, 1, 1],
    ['Lynx', 2, 0, 0, 1, -4]]),
  ('regression: overtime loser point',
   ([['Otters', 2, 'Lynx', 2, 'SO', 'Otters'],
     ['Hawks', 2, 'Bears', 3, 'OT', None],
     ['Bears', 0, 'Otters', 1, 'OT', None],
     ['Otters', 2, 'Hawks', 3, 'REG', None],
     ['Otters', 4, 'Lynx', 0, 'REG', None]],),
   [['Otters', 6, 1, 2, 3, 5],
    ['Hawks', 3, 1, 1, 1, 0],
    ['Bears', 3, 0, 1, 1, 0],
    ['Lynx', 1, 0, 0, 0, -5]]),
  ('variant scenario 1',
   ([['Bears', 5, 'Lynx', 0, 'REG', None],
     ['Otters', 2, 'Bears', 2, 'SO', 'Otters'],
     ['Bears', 2, 'Hawks', 3, 'OT', None],
     ['Bears', 5, 'Hawks', 3, 'REG', None],
     ['Lynx', 2, 'Hawks', 1, 'OT', None]],),
   [['Bears', 6, 2, 2, 2, 5],
    ['Hawks', 3, 0, 1, 1, -2],
    ['Lynx', 2, 0, 1, 1, -4],
    ['Otters', 2, 0, 0, 1, 1]]),
  ('variant scenario 2',
   ([['Bears', 0, 'Otters', 1, 'REG', None],
     ['Hawks', 4, 'Lynx', 1, 'REG', None],
     ['Lynx', 5, 'Otters', 4, 'OT', None]],),
   [['Otters', 3, 1, 1, 1, 0],
    ['Hawks', 2, 1, 1, 1, 3],
    ['Lynx', 2, 0, 1, 1, -2],
    ['Bears', 0, 0, 0, 0, -1]])],
 [('control regulation win',
   ([['Bears', 3, 'Hawks', 1, 'REG', None]],),
   [['Bears', 2, 1, 1, 1, 2], ['Hawks', 0, 0, 0, 0, -2]]),
  ('boundary overtime loss point',
   ([['Bears', 2, 'Hawks', 3, 'OT', None]],),
   [['Hawks', 2, 0, 1, 1, 1], ['Bears', 1, 0, 0, 0, -1]]),
  ('boundary shootout goal credit',
   ([['Bears', 2, 'Hawks', 2, 'SO', 'Hawks']],),
   [['Hawks', 2, 0, 0, 1, 1], ['Bears', 1, 0, 0, 0, -1]]),
  ('boundary RW breaks tie',
   ([['Bears', 1, 'Lynx', 0, 'REG', None], ['Hawks', 1, 'Otters', 0, 'OT', None]],),
   [['Bears', 2, 1, 1, 1, 1],
    ['Hawks', 2, 0, 1, 1, 1],
    ['Otters', 1, 0, 0, 0, -1],
    ['Lynx', 0, 0, 0, 0, -1]]),
  ('regression: overtime loser point',
   ([['Bears', 3, 'Lynx', 2, 'OT', None],
     ['Lynx', 4, 'Hawks', 3, 'REG', None],
     ['Hawks', 5, 'Otters', 4, 'OT', None],
     ['Lynx', 1, 'Hawks', 1, 'SO', 'Lynx']],),
   [['Lynx', 5, 1, 1, 2, 1],
    ['Hawks', 3, 0, 1, 1, -1],
    ['Bears', 2, 0, 1, 1, 1],
    ['Otters', 1, 0, 0, 0, -1]]),
  ('variant scenario 1',
   ([['Bears', 4, 'Lynx', 4, 'SO', 'Lynx'],
     ['Bears', 5, 'Lynx', 2, 'REG', None],
     ['Hawks', 2, 'Bears', 2, 'SO', 'Bears'],
     ['Otters', 0, 'Bears', 1, 'OT', None]],),
   [['Bears', 7, 1, 2, 3, 4],
    ['Lynx', 2, 0, 0, 1, -2],
    ['Hawks', 1, 0, 0, 0, -1],
    ['Otters', 1, 0, 0, 0, -1]]),
  ('variant scenario 2',
   ([['Bears', 1, 'Otters', 1, 'SO', 'Otters'],
     ['Bears', 4, 'Lynx', 2, 'REG', None],
     ['Lynx', 0, 'Bears', 0, 'SO', 'Bears'],
     ['Otters', 0, 'Hawks', 0, 'SO', 'Hawks'],
     ['Bears', 2, 'Hawks', 3, 'OT', None],
     ['Otters', 1, 'Lynx', 2, 'OT', None],
     ['Lynx', 1, 'Otters', 0, 'REG', None]],),
   [['Bears', 6, 1, 1, 2, 1],
    ['Lynx', 5, 1, 2, 2, -1],
    ['Hawks', 4, 0, 1, 2, 2],
    ['Otters', 4, 0, 0, 1, -2]])],
 [('control regulation win',
   ([['Bears', 3, 'Hawks', 1, 'REG', None]],),
   [['Bears', 2, 1, 1, 1, 2], ['Hawks', 0, 0, 0, 0, -2]]),
  ('boundary overtime loss point',
   ([['Bears', 2, 'Hawks', 3, 'OT', None]],),
   [['Hawks', 2, 0, 1, 1, 1], ['Bears', 1, 0, 0, 0, -1]]),
  ('boundary shootout goal credit',
   ([['Bears', 2, 'Hawks', 2, 'SO', 'Hawks']],),
   [['Hawks', 2, 0, 0, 1, 1], ['Bears', 1, 0, 0, 0, -1]]),
  ('boundary RW breaks tie',
   ([['Bears', 1, 'Lynx', 0, 'REG', None], ['Hawks', 1, 'Otters', 0, 'OT', None]],),
   [['Bears', 2, 1, 1, 1, 1],
    ['Hawks', 2, 0, 1, 1, 1],
    ['Otters', 1, 0, 0, 0, -1],
    ['Lynx', 0, 0, 0, 0, -1]]),
  ('regression: overtime loser point',
   ([['Otters', 0, 'Bears', 2, 'REG', None],
     ['Bears', 4, 'Hawks', 5, 'REG', None],
     ['Otters', 1, 'Hawks', 1, 'SO', 'Otters'],
     ['Otters', 5, 'Hawks', 2, 'REG', None],
     ['Hawks', 2, 'Lynx', 1, 'REG', None],
     ['Lynx', 3, 'Bears', 3, 'SO', 'Bears'],
     ['Lynx', 3, 'Hawks', 5, 'REG', None],
     ['Hawks', 0, 'Bears', 3, 'REG', None]],),
   [['Hawks', 7, 3, 3, 3, -3],
    ['Bears', 6, 2, 2, 3, 5],
    ['Otters', 4, 1, 1, 2, 2],
    ['Lynx', 1, 0, 0, 0, -4]]),
  ('regression: overtime loser point',
   ([['Otters', 3, 'Bears', 0, 'REG', None],
     ['Lynx', 5, 'Otters', 4, 'REG', None],
     ['Lynx', 0, 'Bears', 4, 'REG', None],
     ['Otters', 2, 'Lynx', 3, 'OT', None],
     ['Otters', 5, 'Lynx', 4, 'OT', None]],),
   [['Otters', 5, 1, 2, 2, 2], ['Lynx', 5, 1, 2, 2, -3], ['Bears', 2, 1, 1, 1, 1]]),
  ('variant scenario 1',
   ([['Otters', 2, 'Bears', 1, 'REG', None],
     ['Otters', 3, 'Bears', 3, 'SO', 'Bears'],
     ['Lynx', 1, 'Hawks', 5, 'REG', None],
     ['Bears', 4, 'Hawks', 3, 'REG', None],
     ['Lynx', 1, 'Otters', 3, 'REG', None],
     ['Lynx', 1, 'Otters', 2, 'REG', None],
     ['Hawks', 2, 'Otters', 2, 'SO', 'Otters'],
     ['Hawks', 4, 'Lynx', 2, 'REG', None],
     ['Bears', 4, 'Lynx', 2, 'REG', None]],),
   [['Otters', 9, 3, 3, 4, 4],
    ['Bears', 6, 2, 2, 3, 3],
    ['Hawks', 5, 2, 2, 2, 4],
    ['Lynx', 0, 0, 0, 0, -11]]),
  ('variant scenario 2',
   ([['Otters', 3, 'Hawks', 3, 'SO', 'Otters'],
     ['Hawks', 3, 'Otters', 3, 'SO', 'Hawks'],
     ['Hawks', 1, 'Otters', 4, 'REG', None],
     ['Lynx', 4, 'Otters', 2, 'REG', None]],),
   [['Otters', 5, 1, 1, 2, 1], ['Hawks', 3, 0, 0, 1, -3], ['Lynx', 2, 1, 1, 1, 2]])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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(games):
    t = {}
    for h, hg, a, ag, decided, so_winner in games:
        if decided == 'SO':
            if so_winner == h:
                hg += 1
            else:
                ag += 1
        for team, f, g in ((h, hg, ag), (a, ag, hg)):
            row = t.setdefault(team, {'pts': 0, 'rw': 0, 'row': 0, 'w': 0, 'gd': 0})
            row['gd'] += f - g
            if f > g:
                row['pts'] += 2
                row['w'] += 1
                if decided == 'REG':
                    row['rw'] += 1
                if decided != 'SO':
                    row['row'] += 1
            elif decided == 'OT':
                row['pts'] += 1
    order = sorted(t, key=lambda k: (-t[k]['pts'], -t[k]['rw'], -t[k]['row'], -t[k]['w'], -t[k]['gd'], k))
    return [[k, t[k]['pts'], t[k]['rw'], t[k]['row'], t[k]['w'], t[k]['gd']] for k in order]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control regulation win',
   ([['Bears', 3, 'Hawks', 1, 'REG', None]],),
   [['Bears', 2, 1, 1, 1, 2], ['Hawks', 0, 0, 0, 0, -2]]),
  ('boundary overtime loss point',
   ([['Bears', 2, 'Hawks', 3, 'OT', None]],),
   [['Hawks', 2, 0, 1, 1, 1], ['Bears', 1, 0, 0, 0, -1]]),
  ('boundary shootout goal credit',
   ([['Bears', 2, 'Hawks', 2, 'SO', 'Hawks']],),
   [['Hawks', 2, 0, 0, 1, 1], ['Bears', 1, 0, 0, 0, -1]]),
  ('boundary RW breaks tie',
   ([['Bears', 1, 'Lynx', 0, 'REG', None], ['Hawks', 1, 'Otters', 0, 'OT', None]],),
   [['Bears', 2, 1, 1, 1, 1],
    ['Hawks', 2, 0, 1, 1, 1],
    ['Otters', 1, 0, 0, 0, -1],
    ['Lynx', 0, 0, 0, 0, -1]]),
  ('regression: overtime loser point',
   ([['Bears', 3, 'Lynx', 3, 'SO', 'Bears'],
     ['Lynx', 4, 'Hawks', 1, 'REG', None],
     ['Otters', 0, 'Bears', 3, 'REG', None],
     ['Hawks', 0, 'Otters', 4, 'REG', None],
     ['Lynx', 5, 'Otters', 3, 'REG', None],
     ['Lynx', 3, 'Otters', 3, 'SO', 'Lynx']],),
   [['Lynx', 7, 2, 2, 3, 5],
    ['Bears', 4, 1, 1, 2, 4],
    ['Otters', 3, 1, 1, 1, -2],
    ['Hawks', 0, 0, 0, 0, -7]]),
  ('regression: overtime loser point',
   ([['Otters', 5, 'Hawks', 4, 'OT', None],
     ['Bears', 0, 'Lynx', 0, 'SO', 'Lynx'],
     ['Hawks', 3, 'Otters', 5, 'REG', None],
     ['Hawks', 0, 'Otters', 1, 'REG', None]],),
   [['Otters', 6, 2, 3, 3, 4],
    ['Lynx', 2, 0, 0, 1, 1],
    ['Bears', 1, 0, 0, 0, -1],
    ['Hawks', 1, 0, 0, 0, -4]]),
  ('variant scenario 1',
   ([['Lynx', 0, 'Hawks', 0, 'SO', 'Lynx'],
     ['Bears', 1, 'Lynx', 1, 'SO', 'Lynx'],
     ['Hawks', 4, 'Lynx', 3, 'REG', None],
     ['Otters', 2, 'Hawks', 2, 'SO', 'Hawks'],
     ['Bears', 2, 'Hawks', 5, 'REG', None],
     ['Bears', 0, 'Lynx', 0, 'SO', 'Lynx']],),
   [['Hawks', 7, 2, 2, 3, 4],
    ['Lynx', 6, 0, 0, 3, 2],
    ['Bears', 2, 0, 0, 0, -5],
    ['Otters', 1, 0, 0, 0, -1]]),
  ('variant scenario 2',
   ([['Hawks', 2, 'Bears', 2, 'SO', 'Bears'],
     ['Lynx', 3, 'Otters', 2, 'REG', None],
     ['Lynx', 2, 'Bears', 4, 'REG', None],
     ['Otters', 1, 'Bears', 0, 'OT', None]],),
   [['Bears', 5, 1, 1, 2, 2],
    ['Lynx', 2, 1, 1, 1, -1],
    ['Otters', 2, 0, 1, 1, 0],
    ['Hawks', 1, 0, 0, 0, -1]])],
 [('control regulation win',
   ([['Bears', 3, 'Hawks', 1, 'REG', None]],),
   [['Bears', 2, 1, 1, 1, 2], ['Hawks', 0, 0, 0, 0, -2]]),
  ('boundary overtime loss point',
   ([['Bears', 2, 'Hawks', 3, 'OT', None]],),
   [['Hawks', 2, 0, 1, 1, 1], ['Bears', 1, 0, 0, 0, -1]]),
  ('boundary shootout goal credit',
   ([['Bears', 2, 'Hawks', 2, 'SO', 'Hawks']],),
   [['Hawks', 2, 0, 0, 1, 1], ['Bears', 1, 0, 0, 0, -1]]),
  ('boundary RW breaks tie',
   ([['Bears', 1, 'Lynx', 0, 'REG', None], ['Hawks', 1, 'Otters', 0, 'OT', None]],),
   [['Bears', 2, 1, 1, 1, 1],
    ['Hawks', 2, 0, 1, 1, 1],
    ['Otters', 1, 0, 0, 0, -1],
    ['Lynx', 0, 0, 0, 0, -1]]),
  ('regression: overtime loser point',
   ([['Otters', 3, 'Lynx', 0, 'REG', None],
     ['Bears', 3, 'Otters', 3, 'SO', 'Bears'],
     ['Bears', 2, 'Lynx', 0, 'REG', None],
     ['Bears', 2, 'Otters', 3, 'OT', None],
     ['Lynx', 4, 'Hawks', 4, 'SO', 'Hawks']],),
   [['Otters', 5, 1, 2, 2, 3],
    ['Bears', 5, 1, 1, 2, 2],
    ['Hawks', 2, 0, 0, 1, 1],
    ['Lynx', 1, 0, 0, 0, -6]]),
  ('variant scenario 1',
   ([['Bears', 3, 'Hawks', 4, 'REG', None],
     ['Otters', 1, 'Bears', 1, 'SO', 'Bears'],
     ['Hawks', 5, 'Lynx', 4, 'OT', None],
     ['Hawks', 1, 'Bears', 1, 'SO', 'Hawks']],),
   [['Hawks', 6, 1, 2, 3, 3],
    ['Bears', 3, 0, 0, 1, -1],
    ['Lynx', 1, 0, 0, 0, -1],
    ['Otters', 1, 0, 0, 0, -1]]),
  ('variant scenario 2',
   ([['Lynx', 0, 'Bears', 0, 'SO', 'Bears'],
     ['Lynx', 4, 'Bears', 0, 'REG', None],
     ['Hawks', 0, 'Otters', 0, 'SO', 'Hawks'],
     ['Otters', 3, 'Hawks', 2, 'REG', None],
     ['Hawks', 4, 'Bears', 5, 'REG', None],
     ['Lynx', 0, 'Hawks', 0, 'SO', 'Hawks'],
     ['Lynx', 4, 'Bears', 5, 'OT', None]],),
   [['Bears', 6, 1, 2, 3, -1],
    ['Lynx', 5, 1, 1, 1, 1],
    ['Hawks', 4, 0, 0, 2, 0],
    ['Otters', 3, 1, 1, 1, 0]])],
 [('control regulation win',
   ([['Bears', 3, 'Hawks', 1, 'REG', None]],),
   [['Bears', 2, 1, 1, 1, 2], ['Hawks', 0, 0, 0, 0, -2]]),
  ('boundary overtime loss point',
   ([['Bears', 2, 'Hawks', 3, 'OT', None]],),
   [['Hawks', 2, 0, 1, 1, 1], ['Bears', 1, 0, 0, 0, -1]]),
  ('boundary shootout goal credit',
   ([['Bears', 2, 'Hawks', 2, 'SO', 'Hawks']],),
   [['Hawks', 2, 0, 0, 1, 1], ['Bears', 1, 0, 0, 0, -1]]),
  ('boundary RW breaks tie',
   ([['Bears', 1, 'Lynx', 0, 'REG', None], ['Hawks', 1, 'Otters', 0, 'OT', None]],),
   [['Bears', 2, 1, 1, 1, 1],
    ['Hawks', 2, 0, 1, 1, 1],
    ['Otters', 1, 0, 0, 0, -1],
    ['Lynx', 0, 0, 0, 0, -1]]),
  ('regression: overtime loser point',
   ([['Lynx', 3, 'Hawks', 4, 'REG', None],
     ['Bears', 4, 'Otters', 3, 'REG', None],
     ['Hawks', 3, 'Lynx', 3, 'SO', 'Lynx'],
     ['Otters', 5, 'Lynx', 1, 'REG', None]],),
   [['Hawks', 3, 1, 1, 1, 0],
    ['Otters', 2, 1, 1, 1, 3],
    ['Bears', 2, 1, 1, 1, 1],
    ['Lynx', 2, 0, 0, 1, -4]]),
  ('regression: overtime loser point',
   ([['Otters', 2, 'Lynx', 2, 'SO', 'Otters'],
     ['Hawks', 2, 'Bears', 3, 'OT', None],
     ['Bears', 0, 'Otters', 1, 'OT', None],
     ['Otters', 2, 'Hawks', 3, 'REG', None],
     ['Otters', 4, 'Lynx', 0, 'REG', None]],),
   [['Otters', 6, 1, 2, 3, 5],
    ['Hawks', 3, 1, 1, 1, 0],
    ['Bears', 3, 0, 1, 1, 0],
    ['Lynx', 1, 0, 0, 0, -5]]),
  ('variant scenario 1',
   ([['Bears', 5, 'Lynx', 0, 'REG', None],
     ['Otters', 2, 'Bears', 2, 'SO', 'Otters'],
     ['Bears', 2, 'Hawks', 3, 'OT', None],
     ['Bears', 5, 'Hawks', 3, 'REG', None],
     ['Lynx', 2, 'Hawks', 1, 'OT', None]],),
   [['Bears', 6, 2, 2, 2, 5],
    ['Hawks', 3, 0, 1, 1, -2],
    ['Lynx', 2, 0, 1, 1, -4],
    ['Otters', 2, 0, 0, 1, 1]]),
  ('variant scenario 2',
   ([['Bears', 0, 'Otters', 1, 'REG', None],
     ['Hawks', 4, 'Lynx', 1, 'REG', None],
     ['Lynx', 5, 'Otters', 4, 'OT', None]],),
   [['Otters', 3, 1, 1, 1, 0],
    ['Hawks', 2, 1, 1, 1, 3],
    ['Lynx', 2, 0, 1, 1, -2],
    ['Bears', 0, 0, 0, 0, -1]])],
 [('control regulation win',
   ([['Bears', 3, 'Hawks', 1, 'REG', None]],),
   [['Bears', 2, 1, 1, 1, 2], ['Hawks', 0, 0, 0, 0, -2]]),
  ('boundary overtime loss point',
   ([['Bears', 2, 'Hawks', 3, 'OT', None]],),
   [['Hawks', 2, 0, 1, 1, 1], ['Bears', 1, 0, 0, 0, -1]]),
  ('boundary shootout goal credit',
   ([['Bears', 2, 'Hawks', 2, 'SO', 'Hawks']],),
   [['Hawks', 2, 0, 0, 1, 1], ['Bears', 1, 0, 0, 0, -1]]),
  ('boundary RW breaks tie',
   ([['Bears', 1, 'Lynx', 0, 'REG', None], ['Hawks', 1, 'Otters', 0, 'OT', None]],),
   [['Bears', 2, 1, 1, 1, 1],
    ['Hawks', 2, 0, 1, 1, 1],
    ['Otters', 1, 0, 0, 0, -1],
    ['Lynx', 0, 0, 0, 0, -1]]),
  ('regression: overtime loser point',
   ([['Bears', 3, 'Lynx', 2, 'OT', None],
     ['Lynx', 4, 'Hawks', 3, 'REG', None],
     ['Hawks', 5, 'Otters', 4, 'OT', None],
     ['Lynx', 1, 'Hawks', 1, 'SO', 'Lynx']],),
   [['Lynx', 5, 1, 1, 2, 1],
    ['Hawks', 3, 0, 1, 1, -1],
    ['Bears', 2, 0, 1, 1, 1],
    ['Otters', 1, 0, 0, 0, -1]]),
  ('variant scenario 1',
   ([['Bears', 4, 'Lynx', 4, 'SO', 'Lynx'],
     ['Bears', 5, 'Lynx', 2, 'REG', None],
     ['Hawks', 2, 'Bears', 2, 'SO', 'Bears'],
     ['Otters', 0, 'Bears', 1, 'OT', None]],),
   [['Bears', 7, 1, 2, 3, 4],
    ['Lynx', 2, 0, 0, 1, -2],
    ['Hawks', 1, 0, 0, 0, -1],
    ['Otters', 1, 0, 0, 0, -1]]),
  ('variant scenario 2',
   ([['Bears', 1, 'Otters', 1, 'SO', 'Otters'],
     ['Bears', 4, 'Lynx', 2, 'REG', None],
     ['Lynx', 0, 'Bears', 0, 'SO', 'Bears'],
     ['Otters', 0, 'Hawks', 0, 'SO', 'Hawks'],
     ['Bears', 2, 'Hawks', 3, 'OT', None],
     ['Otters', 1, 'Lynx', 2, 'OT', None],
     ['Lynx', 1, 'Otters', 0, 'REG', None]],),
   [['Bears', 6, 1, 1, 2, 1],
    ['Lynx', 5, 1, 2, 2, -1],
    ['Hawks', 4, 0, 1, 2, 2],
    ['Otters', 4, 0, 0, 1, -2]])],
 [('control regulation win',
   ([['Bears', 3, 'Hawks', 1, 'REG', None]],),
   [['Bears', 2, 1, 1, 1, 2], ['Hawks', 0, 0, 0, 0, -2]]),
  ('boundary overtime loss point',
   ([['Bears', 2, 'Hawks', 3, 'OT', None]],),
   [['Hawks', 2, 0, 1, 1, 1], ['Bears', 1, 0, 0, 0, -1]]),
  ('boundary shootout goal credit',
   ([['Bears', 2, 'Hawks', 2, 'SO', 'Hawks']],),
   [['Hawks', 2, 0, 0, 1, 1], ['Bears', 1, 0, 0, 0, -1]]),
  ('boundary RW breaks tie',
   ([['Bears', 1, 'Lynx', 0, 'REG', None], ['Hawks', 1, 'Otters', 0, 'OT', None]],),
   [['Bears', 2, 1, 1, 1, 1],
    ['Hawks', 2, 0, 1, 1, 1],
    ['Otters', 1, 0, 0, 0, -1],
    ['Lynx', 0, 0, 0, 0, -1]]),
  ('regression: overtime loser point',
   ([['Otters', 0, 'Bears', 2, 'REG', None],
     ['Bears', 4, 'Hawks', 5, 'REG', None],
     ['Otters', 1, 'Hawks', 1, 'SO', 'Otters'],
     ['Otters', 5, 'Hawks', 2, 'REG', None],
     ['Hawks', 2, 'Lynx', 1, 'REG', None],
     ['Lynx', 3, 'Bears', 3, 'SO', 'Bears'],
     ['Lynx', 3, 'Hawks', 5, 'REG', None],
     ['Hawks', 0, 'Bears', 3, 'REG', None]],),
   [['Hawks', 7, 3, 3, 3, -3],
    ['Bears', 6, 2, 2, 3, 5],
    ['Otters', 4, 1, 1, 2, 2],
    ['Lynx', 1, 0, 0, 0, -4]]),
  ('regression: overtime loser point',
   ([['Otters', 3, 'Bears', 0, 'REG', None],
     ['Lynx', 5, 'Otters', 4, 'REG', None],
     ['Lynx', 0, 'Bears', 4, 'REG', None],
     ['Otters', 2, 'Lynx', 3, 'OT', None],
     ['Otters', 5, 'Lynx', 4, 'OT', None]],),
   [['Otters', 5, 1, 2, 2, 2], ['Lynx', 5, 1, 2, 2, -3], ['Bears', 2, 1, 1, 1, 1]]),
  ('variant scenario 1',
   ([['Otters', 2, 'Bears', 1, 'REG', None],
     ['Otters', 3, 'Bears', 3, 'SO', 'Bears'],
     ['Lynx', 1, 'Hawks', 5, 'REG', None],
     ['Bears', 4, 'Hawks', 3, 'REG', None],
     ['Lynx', 1, 'Otters', 3, 'REG', None],
     ['Lynx', 1, 'Otters', 2, 'REG', None],
     ['Hawks', 2, 'Otters', 2, 'SO', 'Otters'],
     ['Hawks', 4, 'Lynx', 2, 'REG', None],
     ['Bears', 4, 'Lynx', 2, 'REG', None]],),
   [['Otters', 9, 3, 3, 4, 4],
    ['Bears', 6, 2, 2, 3, 3],
    ['Hawks', 5, 2, 2, 2, 4],
    ['Lynx', 0, 0, 0, 0, -11]]),
  ('variant scenario 2',
   ([['Otters', 3, 'Hawks', 3, 'SO', 'Otters'],
     ['Hawks', 3, 'Otters', 3, 'SO', 'Hawks'],
     ['Hawks', 1, 'Otters', 4, 'REG', None],
     ['Lynx', 4, 'Otters', 2, 'REG', None]],),
   [['Otters', 5, 1, 1, 2, 1], ['Hawks', 3, 0, 0, 1, -3], ['Lynx', 2, 1, 1, 1, 2]])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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:
Teams losing in overtime get zero points while shootout losers get one.

Ice hockey standings. games rows are [home, home_goals, away, away_goals, decided, so_winner] with decided in REG, OT, SO; for SO the listed goals are tied and so_winner names the winner. A win is 2 points and an OT or SO loss 1 point. The shootout winner is credited with one extra goal for, the loser one extra goal against. RW counts regulation wins, ROW regulation plus overtime wins (not shootouts). Rank by points, then RW, then ROW, then total wins, then goal difference, then name. Return [team, points, RW, ROW, W, GD].

split: open-access