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

N = 1
observations = []
def solve(x):
    if x['change'] >= x['end'] or x['change'] < x['start']:
        return []
    span = x['end'] - x['start']
    left = x['end'] - x['change']
    def hu(n):
        return (n * 2 + span) // (2 * span)
    lines = []
    if x['old'] * x['qold']:
        lines.append(['unused', hu(-x['old'] * x['qold'] * left)])
    if x['new'] * x['qnew']:
        lines.append(['remaining', hu(x['new'] * x['qnew'] * left)])
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression (boundary)', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 3, 'qold': 1, 'new': 5, 'qnew': 1}, [['unused', -2], ['remaining', 3]]), ('regression (boundary)', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 5, 'qold': 1, 'new': 7, 'qnew': 1}, [['unused', -3], ['remaining', 4]]), ('partial-repair probe (boundary)', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 7, 'qold': 1, 'new': 9, 'qnew': 1}, [['unused', -4], ['remaining', 5]]), ('partial-repair probe (boundary)', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 9, 'qold': 1, 'new': 11, 'qnew': 1}, [['unused', -5], ['remaining', 6]]), ('normal control', {'start': 1718898066, 'end': 1722579184, 'change': 1721183532, 'old': 87270, 'qold': 0, 'new': 4900, 'qnew': 1}, [['remaining', 1858]]), ('normal control', {'start': 1704011568, 'end': 1706689968, 'change': 1706689968, 'old': 1000, 'qold': 3, 'new': 1500, 'qnew': 3}, []), ('normal control', {'start': 1726549577, 'end': 1727154377, 'change': 1726962866, 'old': 2500, 'qold': 0, 'new': 0, 'qnew': 0}, []), ('normal control', {'start': 1737228310, 'end': 1739499785, 'change': 1739499795, 'old': 178, 'qold': 1, 'new': 1500, 'qnew': 1}, [])], [('regression (boundary)', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 5, 'qold': 1, 'new': 7, 'qnew': 1}, [['unused', -3], ['remaining', 4]]), ('regression (boundary)', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 7, 'qold': 1, 'new': 9, 'qnew': 1}, [['unused', -4], ['remaining', 5]]), ('partial-repair probe (boundary)', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 9, 'qold': 1, 'new': 11, 'qnew': 1}, [['unused', -5], ['remaining', 6]]), ('partial-repair probe (boundary)', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 11, 'qold': 1, 'new': 13, 'qnew': 1}, [['unused', -6], ['remaining', 7]]), ('normal control', {'start': 1732894162, 'end': 1735486162, 'change': 1732894162, 'old': 1000, 'qold': 2, 'new': 91004, 'qnew': 0}, [['unused', -2000]]), ('normal control', {'start': 1749969117, 'end': 1752647517, 'change': 1751393656, 'old': 63152, 'qold': 13, 'new': 0, 'qnew': 0}, [['unused', -384330]]), ('normal control', {'start': 1728579559, 'end': 1760115559, 'change': 1760115559, 'old': 0, 'qold': 0, 'new': 51264, 'qnew': 1}, []), ('normal control', {'start': 1700089359, 'end': 1702545450, 'change': 1702420392, 'old': 79079, 'qold': 0, 'new': 0, 'qnew': 5}, [])], [('regression (boundary)', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 7, 'qold': 1, 'new': 9, 'qnew': 1}, [['unused', -4], ['remaining', 5]]), ('regression (boundary)', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 9, 'qold': 1, 'new': 11, 'qnew': 1}, [['unused', -5], ['remaining', 6]]), ('partial-repair probe (boundary)', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 11, 'qold': 1, 'new': 13, 'qnew': 1}, [['unused', -6], ['remaining', 7]]), ('partial-repair probe (boundary)', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 13, 'qold': 1, 'new': 15, 'qnew': 1}, [['unused', -7], ['remaining', 8]]), ('normal control', {'start': 1721814513, 'end': 1722419313, 'change': 1722419313, 'old': 0, 'qold': 3, 'new': 0, 'qnew': 5}, []), ('normal control', {'start': 1720297909, 'end': 1720623118, 'change': 1720623118, 'old': 1000, 'qold': 17, 'new': 0, 'qnew': 0}, []), ('normal control', {'start': 1734629848, 'end': 1766165848, 'change': 1766165848, 'old': 1000, 'qold': 1, 'new': 4900, 'qnew': 1}, []), ('normal control', {'start': 1759524018, 'end': 1763871464, 'change': 1759976835, 'old': 0, 'qold': 0, 'new': 1500, 'qnew': 5}, [['remaining', 6719]])], [('regression (boundary)', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 9, 'qold': 1, 'new': 11, 'qnew': 1}, [['unused', -5], ['remaining', 6]]), ('regression (boundary)', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 11, 'qold': 1, 'new': 13, 'qnew': 1}, [['unused', -6], ['remaining', 7]]), ('partial-repair probe', {'start': 1734436882, 'end': 1765972882, 'change': 1756322121, 'old': 10374, 'qold': 1, 'new': 4900, 'qnew': 1}, [['unused', -3175], ['remaining', 1500]]), ('partial-repair probe', {'start': 1742110108, 'end': 1745693685, 'change': 1744431348, 'old': 2500, 'qold': 1, 'new': 1500, 'qnew': 5}, [['unused', -881], ['remaining', 2642]]), ('normal control', {'start': 1759898518, 'end': 1762576918, 'change': 1760952409, 'old': 0, 'qold': 3, 'new': 37669, 'qnew': 0}, []), ('normal control', {'start': 1724743049, 'end': 1756279049, 'change': 1724743049, 'old': 2500, 'qold': 1, 'new': 1500, 'qnew': 1}, [['unused', -2500], ['remaining', 1500]]), ('normal control', {'start': 1742436208, 'end': 1773972208, 'change': 1773972218, 'old': 0, 'qold': 3, 'new': 4900, 'qnew': 1}, []), ('normal control', {'start': 1757847857, 'end': 1760439857, 'change': 1757847852, 'old': 92286, 'qold': 0, 'new': 0, 'qnew': 4}, [])], [('regression (boundary)', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 11, 'qold': 1, 'new': 13, 'qnew': 1}, [['unused', -6], ['remaining', 7]]), ('regression (boundary)', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 13, 'qold': 1, 'new': 15, 'qnew': 1}, [['unused', -7], ['remaining', 8]]), ('partial-repair probe', {'start': 1714042904, 'end': 1745578904, 'change': 1717176355, 'old': 1000, 'qold': 3, 'new': 1500, 'qnew': 0}, [['unused', -2702]]), ('partial-repair probe', {'start': 1749513307, 'end': 1752191707, 'change': 1749624391, 'old': 37053, 'qold': 11, 'new': 0, 'qnew': 0}, [['unused', -390679]]), ('normal control', {'start': 1726496239, 'end': 1729174639, 'change': 1726496239, 'old': 73990, 'qold': 3, 'new': 47429, 'qnew': 5}, [['unused', -221970], ['remaining', 237145]]), ('normal control', {'start': 1739738740, 'end': 1771274740, 'change': 1771274740, 'old': 2500, 'qold': 3, 'new': 1500, 'qnew': 5}, []), ('normal control', {'start': 1725551908, 'end': 1757087908, 'change': 1757087918, 'old': 67119, 'qold': 3, 'new': 4900, 'qnew': 13}, []), ('normal control', {'start': 1753105090, 'end': 1753709890, 'change': 1753105090, 'old': 1000, 'qold': 0, 'new': 0, 'qnew': 1}, [])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    if x['change'] >= x['end'] or x['change'] < x['start']:
        return []
    span = x['end'] - x['start']
    left = x['end'] - x['change']
    def hu(n):
        return (n * 2 + span) // (2 * span)
    lines = []
    if x['old'] * x['qold']:
        lines.append(['unused', -(x['old'] * x['qold'] * left // span)])
    if x['new'] * x['qnew']:
        lines.append(['remaining', hu(x['new'] * x['qnew'] * left)])
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression (boundary)', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 3, 'qold': 1, 'new': 5, 'qnew': 1}, [['unused', -2], ['remaining', 3]]), ('regression (boundary)', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 5, 'qold': 1, 'new': 7, 'qnew': 1}, [['unused', -3], ['remaining', 4]]), ('partial-repair probe (boundary)', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 7, 'qold': 1, 'new': 9, 'qnew': 1}, [['unused', -4], ['remaining', 5]]), ('partial-repair probe (boundary)', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 9, 'qold': 1, 'new': 11, 'qnew': 1}, [['unused', -5], ['remaining', 6]]), ('normal control', {'start': 1718898066, 'end': 1722579184, 'change': 1721183532, 'old': 87270, 'qold': 0, 'new': 4900, 'qnew': 1}, [['remaining', 1858]]), ('normal control', {'start': 1704011568, 'end': 1706689968, 'change': 1706689968, 'old': 1000, 'qold': 3, 'new': 1500, 'qnew': 3}, []), ('normal control', {'start': 1726549577, 'end': 1727154377, 'change': 1726962866, 'old': 2500, 'qold': 0, 'new': 0, 'qnew': 0}, []), ('normal control', {'start': 1737228310, 'end': 1739499785, 'change': 1739499795, 'old': 178, 'qold': 1, 'new': 1500, 'qnew': 1}, [])], [('regression (boundary)', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 5, 'qold': 1, 'new': 7, 'qnew': 1}, [['unused', -3], ['remaining', 4]]), ('regression (boundary)', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 7, 'qold': 1, 'new': 9, 'qnew': 1}, [['unused', -4], ['remaining', 5]]), ('partial-repair probe (boundary)', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 9, 'qold': 1, 'new': 11, 'qnew': 1}, [['unused', -5], ['remaining', 6]]), ('partial-repair probe (boundary)', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 11, 'qold': 1, 'new': 13, 'qnew': 1}, [['unused', -6], ['remaining', 7]]), ('normal control', {'start': 1732894162, 'end': 1735486162, 'change': 1732894162, 'old': 1000, 'qold': 2, 'new': 91004, 'qnew': 0}, [['unused', -2000]]), ('normal control', {'start': 1749969117, 'end': 1752647517, 'change': 1751393656, 'old': 63152, 'qold': 13, 'new': 0, 'qnew': 0}, [['unused', -384330]]), ('normal control', {'start': 1728579559, 'end': 1760115559, 'change': 1760115559, 'old': 0, 'qold': 0, 'new': 51264, 'qnew': 1}, []), ('normal control', {'start': 1700089359, 'end': 1702545450, 'change': 1702420392, 'old': 79079, 'qold': 0, 'new': 0, 'qnew': 5}, [])], [('regression (boundary)', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 7, 'qold': 1, 'new': 9, 'qnew': 1}, [['unused', -4], ['remaining', 5]]), ('regression (boundary)', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 9, 'qold': 1, 'new': 11, 'qnew': 1}, [['unused', -5], ['remaining', 6]]), ('partial-repair probe (boundary)', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 11, 'qold': 1, 'new': 13, 'qnew': 1}, [['unused', -6], ['remaining', 7]]), ('partial-repair probe (boundary)', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 13, 'qold': 1, 'new': 15, 'qnew': 1}, [['unused', -7], ['remaining', 8]]), ('normal control', {'start': 1721814513, 'end': 1722419313, 'change': 1722419313, 'old': 0, 'qold': 3, 'new': 0, 'qnew': 5}, []), ('normal control', {'start': 1720297909, 'end': 1720623118, 'change': 1720623118, 'old': 1000, 'qold': 17, 'new': 0, 'qnew': 0}, []), ('normal control', {'start': 1734629848, 'end': 1766165848, 'change': 1766165848, 'old': 1000, 'qold': 1, 'new': 4900, 'qnew': 1}, []), ('normal control', {'start': 1759524018, 'end': 1763871464, 'change': 1759976835, 'old': 0, 'qold': 0, 'new': 1500, 'qnew': 5}, [['remaining', 6719]])], [('regression (boundary)', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 9, 'qold': 1, 'new': 11, 'qnew': 1}, [['unused', -5], ['remaining', 6]]), ('regression (boundary)', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 11, 'qold': 1, 'new': 13, 'qnew': 1}, [['unused', -6], ['remaining', 7]]), ('partial-repair probe', {'start': 1734436882, 'end': 1765972882, 'change': 1756322121, 'old': 10374, 'qold': 1, 'new': 4900, 'qnew': 1}, [['unused', -3175], ['remaining', 1500]]), ('partial-repair probe', {'start': 1742110108, 'end': 1745693685, 'change': 1744431348, 'old': 2500, 'qold': 1, 'new': 1500, 'qnew': 5}, [['unused', -881], ['remaining', 2642]]), ('normal control', {'start': 1759898518, 'end': 1762576918, 'change': 1760952409, 'old': 0, 'qold': 3, 'new': 37669, 'qnew': 0}, []), ('normal control', {'start': 1724743049, 'end': 1756279049, 'change': 1724743049, 'old': 2500, 'qold': 1, 'new': 1500, 'qnew': 1}, [['unused', -2500], ['remaining', 1500]]), ('normal control', {'start': 1742436208, 'end': 1773972208, 'change': 1773972218, 'old': 0, 'qold': 3, 'new': 4900, 'qnew': 1}, []), ('normal control', {'start': 1757847857, 'end': 1760439857, 'change': 1757847852, 'old': 92286, 'qold': 0, 'new': 0, 'qnew': 4}, [])], [('regression (boundary)', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 11, 'qold': 1, 'new': 13, 'qnew': 1}, [['unused', -6], ['remaining', 7]]), ('regression (boundary)', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 13, 'qold': 1, 'new': 15, 'qnew': 1}, [['unused', -7], ['remaining', 8]]), ('partial-repair probe', {'start': 1714042904, 'end': 1745578904, 'change': 1717176355, 'old': 1000, 'qold': 3, 'new': 1500, 'qnew': 0}, [['unused', -2702]]), ('partial-repair probe', {'start': 1749513307, 'end': 1752191707, 'change': 1749624391, 'old': 37053, 'qold': 11, 'new': 0, 'qnew': 0}, [['unused', -390679]]), ('normal control', {'start': 1726496239, 'end': 1729174639, 'change': 1726496239, 'old': 73990, 'qold': 3, 'new': 47429, 'qnew': 5}, [['unused', -221970], ['remaining', 237145]]), ('normal control', {'start': 1739738740, 'end': 1771274740, 'change': 1771274740, 'old': 2500, 'qold': 3, 'new': 1500, 'qnew': 5}, []), ('normal control', {'start': 1725551908, 'end': 1757087908, 'change': 1757087918, 'old': 67119, 'qold': 3, 'new': 4900, 'qnew': 13}, []), ('normal control', {'start': 1753105090, 'end': 1753709890, 'change': 1753105090, 'old': 1000, 'qold': 0, 'new': 0, 'qnew': 1}, [])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Credit lines ending in exactly half a cent are a cent smaller than the matching debit lines.

Input unix-second {start, end, change} and {old, qold, new, qnew}. If change < start or change >= end return []. Otherwise left = end - change, span = end - start. An "unused" credit line of -(old*qold*left/span) and a "remaining" line of new*qnew*left/span are emitted, each magnitude rounded half-up (half away from zero), omitting a line whose price*quantity is 0. Return [[kind, amount]].

split: open-access


meaning: Fixture-count band, not measured model difficulty

deps: stdlib

prompt:
Seat upgrades are charged for a single seat on the new plan.

Input unix-second {start, end, change} and {old, qold, new, qnew}. If change < start or change >= end return []. Otherwise left = end - change, span = end - start. An "unused" credit line of -(old*qold*left/span) and a "remaining" line of new*qnew*left/span are emitted, each magnitude rounded half-up (half away from zero), omitting a line whose price*quantity is 0. Return [[kind, amount]].

split: open-access


prompt:
A change exactly at renewal emits zero-amount proration lines.

Input unix-second {start, end, change} and {old, qold, new, qnew}. If change < start or change >= end return []. Otherwise left = end - change, span = end - start. An "unused" credit line of -(old*qold*left/span) and a "remaining" line of new*qnew*left/span are emitted, each magnitude rounded half-up (half away from zero), omitting a line whose price*quantity is 0. Return [[kind, amount]].

split: open-access


prompt:
Moving from zero seats produces an empty zero-cent credit line.

Input unix-second {start, end, change} and {old, qold, new, qnew}. If change < start or change >= end return []. Otherwise left = end - change, span = end - start. An "unused" credit line of -(old*qold*left/span) and a "remaining" line of new*qnew*left/span are emitted, each magnitude rounded half-up (half away from zero), omitting a line whose price*quantity is 0. Return [[kind, amount]].

split: open-access


prompt:
After a short month, renewals stay on the 28th or 30th for the rest of the subscription.

Input {anchor [y,m,d], n, interval months}. Renewal i (1..n) falls interval*i months after the anchor month, on the anchor day clamped to that month's length (so a 31st anchor returns to the 31st whenever possible). Return the list of [y, m, d].

split: open-access


prompt:
Renewals that roll into January keep the old year.

Input {anchor [y,m,d], n, interval months}. Renewal i (1..n) falls interval*i months after the anchor month, on the anchor day clamped to that month's length (so a 31st anchor returns to the 31st whenever possible). Return the list of [y, m, d].

split: open-access


prompt:
Renewals in February of a leap year land on the 28th instead of the 29th.

Input {anchor [y,m,d], n, interval months}. Renewal i (1..n) falls interval*i months after the anchor month, on the anchor day clamped to that month's length (so a 31st anchor returns to the 31st whenever possible). Return the list of [y, m, d].

split: open-access


prompt:
Every renewal is scheduled one month late.

Input {anchor [y,m,d], n, interval months}. Renewal i (1..n) falls interval*i months after the anchor month, on the anchor day clamped to that month's length (so a 31st anchor returns to the 31st whenever possible). Return the list of [y, m, d].

split: open-access


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

N = 1
observations = []
def solve(x):
    ch = sorted(x['changes'], key=lambda c: c[0])
    hwm = current = x['base_seats']
    charge = 0
    for day, count in ch:
        if count > hwm:
            added = count - current
            left = x['period_days'] - day
            charge += (x['price'] * added * left * 2 + x['period_days']) // (2 * x['period_days'])
            hwm = count
        current = count
    final = ch[-1][1] if ch else x['base_seats']
    return [charge, hwm, final]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'price': 1500, 'period_days': 30, 'base_seats': 9, 'changes': [[19, 10], [22, 3], [12, 12], [24, 3], [19, 20]]}, [7100, 20, 3]), ('regression', {'price': 1500, 'period_days': 28, 'base_seats': 12, 'changes': [[0, 4], [0, 9], [6, 24], [23, 1], [9, 21]]}, [14143, 24, 1]), ('partial-repair probe', {'price': 800, 'period_days': 28, 'base_seats': 6, 'changes': [[27, 25], [1, 17], [12, 18]]}, [9143, 25, 25]), ('partial-repair probe', {'price': 800, 'period_days': 31, 'base_seats': 7, 'changes': [[14, 11], [13, 12], [19, 0], [30, 25], [23, 8]]}, [2658, 25, 25]), ('boundary control', {'price': 1000, 'period_days': 30, 'base_seats': 5, 'changes': [[3, 3], [10, 5], [12, 7]]}, [1200, 7, 7]), ('normal control', {'price': 800, 'period_days': 31, 'base_seats': 8, 'changes': []}, [0, 8, 8]), ('normal control', {'price': 800, 'period_days': 30, 'base_seats': 13, 'changes': [[15, 1]]}, [0, 13, 1]), ('normal control', {'price': 1200, 'period_days': 31, 'base_seats': 11, 'changes': []}, [0, 11, 11]), ('normal control', {'price': 5360, 'period_days': 28, 'base_seats': 12, 'changes': []}, [0, 12, 12])], [('regression', {'price': 800, 'period_days': 31, 'base_seats': 7, 'changes': [[14, 11], [13, 12], [19, 0], [30, 25], [23, 8]]}, [2658, 25, 25]), ('regression', {'price': 1500, 'period_days': 28, 'base_seats': 12, 'changes': [[0, 4], [0, 9], [6, 24], [23, 1], [9, 21]]}, [14143, 24, 1]), ('partial-repair probe', {'price': 800, 'period_days': 30, 'base_seats': 11, 'changes': [[20, 22], [5, 15], [20, 14]]}, [4534, 22, 14]), ('partial-repair probe', {'price': 800, 'period_days': 30, 'base_seats': 7, 'changes': [[20, 9], [14, 20], [13, 5], [9, 15], [3, 15], [20, 17]]}, [7893, 20, 17]), ('boundary control', {'price': 1000, 'period_days': 30, 'base_seats': 5, 'changes': [[3, 3], [10, 5], [12, 7]]}, [1200, 7, 7]), ('normal control', {'price': 1200, 'period_days': 30, 'base_seats': 11, 'changes': [[6, 20], [12, 8], [15, 1], [7, 5], [0, 11]]}, [8640, 20, 1]), ('normal control', {'price': 1500, 'period_days': 28, 'base_seats': 10, 'changes': [[1, 16], [20, 13]]}, [8679, 16, 13]), ('normal control', {'price': 5820, 'period_days': 365, 'base_seats': 15, 'changes': [[14, 25], [190, 23], [339, 10], [22, 7], [14, 1]]}, [55968, 25, 10]), ('normal control', {'price': 7507, 'period_days': 31, 'base_seats': 15, 'changes': [[15, 8]]}, [0, 15, 8])], [('regression', {'price': 800, 'period_days': 30, 'base_seats': 7, 'changes': [[20, 9], [14, 20], [13, 5], [9, 15], [3, 15], [20, 17]]}, [7893, 20, 17]), ('regression', {'price': 800, 'period_days': 31, 'base_seats': 7, 'changes': [[14, 11], [13, 12], [19, 0], [30, 25], [23, 8]]}, [2658, 25, 25]), ('partial-repair probe', {'price': 1500, 'period_days': 28, 'base_seats': 7, 'changes': [[17, 25], [9, 11], [4, 16], [3, 0], [0, 15]]}, [18590, 25, 25]), ('partial-repair probe', {'price': 1200, 'period_days': 365, 'base_seats': 4, 'changes': [[333, 15], [352, 23], [4, 5]]}, [2581, 23, 23]), ('boundary control', {'price': 1000, 'period_days': 30, 'base_seats': 5, 'changes': [[3, 3], [10, 5], [12, 7]]}, [1200, 7, 7]), ('normal control', {'price': 2726, 'period_days': 365, 'base_seats': 15, 'changes': [[171, 14], [284, 12], [141, 18], [171, 5]]}, [5019, 18, 12]), ('normal control', {'price': 800, 'period_days': 30, 'base_seats': 8, 'changes': [[19, 24], [23, 8], [10, 24], [12, 12]]}, [8533, 24, 8]), ('normal control', {'price': 1500, 'period_days': 31, 'base_seats': 6, 'changes': []}, [0, 6, 6]), ('normal control', {'price': 800, 'period_days': 365, 'base_seats': 15, 'changes': []}, [0, 15, 15])], [('regression', {'price': 1500, 'period_days': 28, 'base_seats': 7, 'changes': [[17, 25], [9, 11], [4, 16], [3, 0], [0, 15]]}, [18590, 25, 25]), ('regression', {'price': 1500, 'period_days': 28, 'base_seats': 2, 'changes': [[26, 6], [4, 0], [26, 2]]}, [429, 6, 2]), ('partial-repair probe', {'price': 1200, 'period_days': 365, 'base_seats': 4, 'changes': [[333, 15], [352, 23], [4, 5]]}, [2581, 23, 23]), ('partial-repair probe', {'price': 800, 'period_days': 31, 'base_seats': 3, 'changes': [[28, 18], [20, 24], [30, 5], [0, 18], [28, 15]]}, [13703, 24, 5]), ('boundary control', {'price': 1000, 'period_days': 30, 'base_seats': 5, 'changes': [[3, 3], [10, 5], [12, 7]]}, [1200, 7, 7]), ('normal control', {'price': 1200, 'period_days': 365, 'base_seats': 7, 'changes': []}, [0, 7, 7]), ('normal control', {'price': 800, 'period_days': 31, 'base_seats': 9, 'changes': [[0, 4], [4, 7]]}, [0, 9, 7]), ('normal control', {'price': 1200, 'period_days': 30, 'base_seats': 13, 'changes': []}, [0, 13, 13]), ('normal control', {'price': 1200, 'period_days': 30, 'base_seats': 5, 'changes': [[22, 12], [22, 9]]}, [2240, 12, 9])], [('regression', {'price': 6476, 'period_days': 31, 'base_seats': 12, 'changes': [[19, 7], [29, 16], [4, 14]]}, [12117, 16, 16]), ('regression', {'price': 800, 'period_days': 30, 'base_seats': 7, 'changes': [[20, 9], [14, 20], [13, 5], [9, 15], [3, 15], [20, 17]]}, [7893, 20, 17]), ('partial-repair probe', {'price': 1200, 'period_days': 31, 'base_seats': 1, 'changes': [[19, 14], [24, 18]]}, [7123, 18, 18]), ('partial-repair probe', {'price': 800, 'period_days': 30, 'base_seats': 4, 'changes': [[21, 22], [29, 24]]}, [4373, 24, 24]), ('boundary control', {'price': 1000, 'period_days': 30, 'base_seats': 5, 'changes': [[3, 3], [10, 5], [12, 7]]}, [1200, 7, 7]), ('normal control', {'price': 800, 'period_days': 28, 'base_seats': 2, 'changes': [[14, 0]]}, [0, 2, 0]), ('normal control', {'price': 800, 'period_days': 30, 'base_seats': 1, 'changes': []}, [0, 1, 1]), ('normal control', {'price': 1500, 'period_days': 31, 'base_seats': 13, 'changes': [[24, 7]]}, [0, 13, 7]), ('normal control', {'price': 800, 'period_days': 28, 'base_seats': 11, 'changes': []}, [0, 11, 11])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    ch = sorted(x['changes'], key=lambda c: c[0])
    hwm = current = x['base_seats']
    charge = 0
    for day, count in ch:
        if count > hwm:
            added = count - x['base_seats']
            left = x['period_days'] - day
            charge += (x['price'] * added * left * 2 + x['period_days']) // (2 * x['period_days'])
            hwm = count
        current = count
    final = ch[-1][1] if ch else x['base_seats']
    return [charge, hwm, final]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'price': 1500, 'period_days': 30, 'base_seats': 9, 'changes': [[19, 10], [22, 3], [12, 12], [24, 3], [19, 20]]}, [7100, 20, 3]), ('regression', {'price': 1500, 'period_days': 28, 'base_seats': 12, 'changes': [[0, 4], [0, 9], [6, 24], [23, 1], [9, 21]]}, [14143, 24, 1]), ('partial-repair probe', {'price': 800, 'period_days': 28, 'base_seats': 6, 'changes': [[27, 25], [1, 17], [12, 18]]}, [9143, 25, 25]), ('partial-repair probe', {'price': 800, 'period_days': 31, 'base_seats': 7, 'changes': [[14, 11], [13, 12], [19, 0], [30, 25], [23, 8]]}, [2658, 25, 25]), ('boundary control', {'price': 1000, 'period_days': 30, 'base_seats': 5, 'changes': [[3, 3], [10, 5], [12, 7]]}, [1200, 7, 7]), ('normal control', {'price': 800, 'period_days': 31, 'base_seats': 8, 'changes': []}, [0, 8, 8]), ('normal control', {'price': 800, 'period_days': 30, 'base_seats': 13, 'changes': [[15, 1]]}, [0, 13, 1]), ('normal control', {'price': 1200, 'period_days': 31, 'base_seats': 11, 'changes': []}, [0, 11, 11]), ('normal control', {'price': 5360, 'period_days': 28, 'base_seats': 12, 'changes': []}, [0, 12, 12])], [('regression', {'price': 800, 'period_days': 31, 'base_seats': 7, 'changes': [[14, 11], [13, 12], [19, 0], [30, 25], [23, 8]]}, [2658, 25, 25]), ('regression', {'price': 1500, 'period_days': 28, 'base_seats': 12, 'changes': [[0, 4], [0, 9], [6, 24], [23, 1], [9, 21]]}, [14143, 24, 1]), ('partial-repair probe', {'price': 800, 'period_days': 30, 'base_seats': 11, 'changes': [[20, 22], [5, 15], [20, 14]]}, [4534, 22, 14]), ('partial-repair probe', {'price': 800, 'period_days': 30, 'base_seats': 7, 'changes': [[20, 9], [14, 20], [13, 5], [9, 15], [3, 15], [20, 17]]}, [7893, 20, 17]), ('boundary control', {'price': 1000, 'period_days': 30, 'base_seats': 5, 'changes': [[3, 3], [10, 5], [12, 7]]}, [1200, 7, 7]), ('normal control', {'price': 1200, 'period_days': 30, 'base_seats': 11, 'changes': [[6, 20], [12, 8], [15, 1], [7, 5], [0, 11]]}, [8640, 20, 1]), ('normal control', {'price': 1500, 'period_days': 28, 'base_seats': 10, 'changes': [[1, 16], [20, 13]]}, [8679, 16, 13]), ('normal control', {'price': 5820, 'period_days': 365, 'base_seats': 15, 'changes': [[14, 25], [190, 23], [339, 10], [22, 7], [14, 1]]}, [55968, 25, 10]), ('normal control', {'price': 7507, 'period_days': 31, 'base_seats': 15, 'changes': [[15, 8]]}, [0, 15, 8])], [('regression', {'price': 800, 'period_days': 30, 'base_seats': 7, 'changes': [[20, 9], [14, 20], [13, 5], [9, 15], [3, 15], [20, 17]]}, [7893, 20, 17]), ('regression', {'price': 800, 'period_days': 31, 'base_seats': 7, 'changes': [[14, 11], [13, 12], [19, 0], [30, 25], [23, 8]]}, [2658, 25, 25]), ('partial-repair probe', {'price': 1500, 'period_days': 28, 'base_seats': 7, 'changes': [[17, 25], [9, 11], [4, 16], [3, 0], [0, 15]]}, [18590, 25, 25]), ('partial-repair probe', {'price': 1200, 'period_days': 365, 'base_seats': 4, 'changes': [[333, 15], [352, 23], [4, 5]]}, [2581, 23, 23]), ('boundary control', {'price': 1000, 'period_days': 30, 'base_seats': 5, 'changes': [[3, 3], [10, 5], [12, 7]]}, [1200, 7, 7]), ('normal control', {'price': 2726, 'period_days': 365, 'base_seats': 15, 'changes': [[171, 14], [284, 12], [141, 18], [171, 5]]}, [5019, 18, 12]), ('normal control', {'price': 800, 'period_days': 30, 'base_seats': 8, 'changes': [[19, 24], [23, 8], [10, 24], [12, 12]]}, [8533, 24, 8]), ('normal control', {'price': 1500, 'period_days': 31, 'base_seats': 6, 'changes': []}, [0, 6, 6]), ('normal control', {'price': 800, 'period_days': 365, 'base_seats': 15, 'changes': []}, [0, 15, 15])], [('regression', {'price': 1500, 'period_days': 28, 'base_seats': 7, 'changes': [[17, 25], [9, 11], [4, 16], [3, 0], [0, 15]]}, [18590, 25, 25]), ('regression', {'price': 1500, 'period_days': 28, 'base_seats': 2, 'changes': [[26, 6], [4, 0], [26, 2]]}, [429, 6, 2]), ('partial-repair probe', {'price': 1200, 'period_days': 365, 'base_seats': 4, 'changes': [[333, 15], [352, 23], [4, 5]]}, [2581, 23, 23]), ('partial-repair probe', {'price': 800, 'period_days': 31, 'base_seats': 3, 'changes': [[28, 18], [20, 24], [30, 5], [0, 18], [28, 15]]}, [13703, 24, 5]), ('boundary control', {'price': 1000, 'period_days': 30, 'base_seats': 5, 'changes': [[3, 3], [10, 5], [12, 7]]}, [1200, 7, 7]), ('normal control', {'price': 1200, 'period_days': 365, 'base_seats': 7, 'changes': []}, [0, 7, 7]), ('normal control', {'price': 800, 'period_days': 31, 'base_seats': 9, 'changes': [[0, 4], [4, 7]]}, [0, 9, 7]), ('normal control', {'price': 1200, 'period_days': 30, 'base_seats': 13, 'changes': []}, [0, 13, 13]), ('normal control', {'price': 1200, 'period_days': 30, 'base_seats': 5, 'changes': [[22, 12], [22, 9]]}, [2240, 12, 9])], [('regression', {'price': 6476, 'period_days': 31, 'base_seats': 12, 'changes': [[19, 7], [29, 16], [4, 14]]}, [12117, 16, 16]), ('regression', {'price': 800, 'period_days': 30, 'base_seats': 7, 'changes': [[20, 9], [14, 20], [13, 5], [9, 15], [3, 15], [20, 17]]}, [7893, 20, 17]), ('partial-repair probe', {'price': 1200, 'period_days': 31, 'base_seats': 1, 'changes': [[19, 14], [24, 18]]}, [7123, 18, 18]), ('partial-repair probe', {'price': 800, 'period_days': 30, 'base_seats': 4, 'changes': [[21, 22], [29, 24]]}, [4373, 24, 24]), ('boundary control', {'price': 1000, 'period_days': 30, 'base_seats': 5, 'changes': [[3, 3], [10, 5], [12, 7]]}, [1200, 7, 7]), ('normal control', {'price': 800, 'period_days': 28, 'base_seats': 2, 'changes': [[14, 0]]}, [0, 2, 0]), ('normal control', {'price': 800, 'period_days': 30, 'base_seats': 1, 'changes': []}, [0, 1, 1]), ('normal control', {'price': 1500, 'period_days': 31, 'base_seats': 13, 'changes': [[24, 7]]}, [0, 13, 7]), ('normal control', {'price': 800, 'period_days': 28, 'base_seats': 11, 'changes': []}, [0, 11, 11])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Seats removed and re-added in the same period are charged twice.

Input {price per seat per period, period_days, base_seats, changes: [[day, seat_count]]}. Changes apply in day order (same-day changes keep input order). Seats above the period high-water mark are charged price*added*(period_days - day)/period_days half-up; decreases earn no mid-cycle credit. Return [prorated charges, high-water mark, renewal seat count (the last count)].

split: open-access


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

N = 1
observations = []
def solve(x):
    ch = sorted(x['changes'], key=lambda c: c[0])
    hwm = current = x['base_seats']
    charge = 0
    for day, count in ch:
        if count > hwm:
            added = count - hwm
            left = x['period_days'] - day
            charge += (x['price'] * added * left * 2 + x['period_days']) // (2 * x['period_days'])
            hwm = count
        if count < current:
            charge -= (x['price'] * (current - count) * (x['period_days'] - day) * 2 + x['period_days']) // (2 * x['period_days'])
        current = count
    final = ch[-1][1] if ch else x['base_seats']
    return [charge, hwm, final]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression (boundary)', {'price': 1000, 'period_days': 30, 'base_seats': 5, 'changes': [[3, 3], [10, 5], [12, 7]]}, [1200, 7, 7]), ('regression', {'price': 800, 'period_days': 30, 'base_seats': 13, 'changes': [[15, 1]]}, [0, 13, 1]), ('partial-repair probe', {'price': 1500, 'period_days': 30, 'base_seats': 9, 'changes': [[19, 10], [22, 3], [12, 12], [24, 3], [19, 20]]}, [7100, 20, 3]), ('partial-repair probe', {'price': 1200, 'period_days': 30, 'base_seats': 11, 'changes': [[6, 20], [12, 8], [15, 1], [7, 5], [0, 11]]}, [8640, 20, 1]), ('normal control', {'price': 800, 'period_days': 31, 'base_seats': 8, 'changes': []}, [0, 8, 8]), ('normal control', {'price': 1200, 'period_days': 31, 'base_seats': 11, 'changes': []}, [0, 11, 11]), ('normal control', {'price': 5360, 'period_days': 28, 'base_seats': 12, 'changes': []}, [0, 12, 12]), ('normal control', {'price': 800, 'period_days': 28, 'base_seats': 6, 'changes': [[27, 25], [1, 17], [12, 18]]}, [9143, 25, 25])], [('regression', {'price': 800, 'period_days': 30, 'base_seats': 13, 'changes': [[15, 1]]}, [0, 13, 1]), ('regression', {'price': 1500, 'period_days': 30, 'base_seats': 9, 'changes': [[19, 10], [22, 3], [12, 12], [24, 3], [19, 20]]}, [7100, 20, 3]), ('partial-repair probe', {'price': 1200, 'period_days': 30, 'base_seats': 11, 'changes': [[6, 20], [12, 8], [15, 1], [7, 5], [0, 11]]}, [8640, 20, 1]), ('partial-repair probe', {'price': 1500, 'period_days': 28, 'base_seats': 12, 'changes': [[0, 4], [0, 9], [6, 24], [23, 1], [9, 21]]}, [14143, 24, 1]), ('normal control', {'price': 1500, 'period_days': 31, 'base_seats': 6, 'changes': []}, [0, 6, 6]), ('normal control', {'price': 800, 'period_days': 365, 'base_seats': 15, 'changes': []}, [0, 15, 15]), ('normal control', {'price': 1200, 'period_days': 365, 'base_seats': 7, 'changes': []}, [0, 7, 7]), ('normal control', {'price': 1200, 'period_days': 30, 'base_seats': 13, 'changes': []}, [0, 13, 13])], [('regression', {'price': 1500, 'period_days': 30, 'base_seats': 9, 'changes': [[19, 10], [22, 3], [12, 12], [24, 3], [19, 20]]}, [7100, 20, 3]), ('regression', {'price': 1200, 'period_days': 30, 'base_seats': 11, 'changes': [[6, 20], [12, 8], [15, 1], [7, 5], [0, 11]]}, [8640, 20, 1]), ('partial-repair probe', {'price': 1500, 'period_days': 28, 'base_seats': 12, 'changes': [[0, 4], [0, 9], [6, 24], [23, 1], [9, 21]]}, [14143, 24, 1]), ('partial-repair probe', {'price': 5820, 'period_days': 365, 'base_seats': 15, 'changes': [[14, 25], [190, 23], [339, 10], [22, 7], [14, 1]]}, [55968, 25, 10]), ('normal control', {'price': 800, 'period_days': 30, 'base_seats': 1, 'changes': []}, [0, 1, 1]), ('normal control', {'price': 800, 'period_days': 28, 'base_seats': 11, 'changes': []}, [0, 11, 11]), ('normal control', {'price': 1200, 'period_days': 365, 'base_seats': 4, 'changes': [[333, 15], [352, 23], [4, 5]]}, [2581, 23, 23]), ('normal control', {'price': 1200, 'period_days': 31, 'base_seats': 1, 'changes': [[19, 14], [24, 18]]}, [7123, 18, 18])], [('regression', {'price': 1200, 'period_days': 30, 'base_seats': 11, 'changes': [[6, 20], [12, 8], [15, 1], [7, 5], [0, 11]]}, [8640, 20, 1]), ('regression', {'price': 1500, 'period_days': 28, 'base_seats': 10, 'changes': [[1, 16], [20, 13]]}, [8679, 16, 13]), ('partial-repair probe', {'price': 7507, 'period_days': 31, 'base_seats': 15, 'changes': [[15, 8]]}, [0, 15, 8]), ('partial-repair probe', {'price': 2726, 'period_days': 365, 'base_seats': 15, 'changes': [[171, 14], [284, 12], [141, 18], [171, 5]]}, [5019, 18, 12]), ('normal control', {'price': 800, 'period_days': 30, 'base_seats': 4, 'changes': [[21, 22], [29, 24]]}, [4373, 24, 24]), ('normal control', {'price': 6240, 'period_days': 28, 'base_seats': 1, 'changes': []}, [0, 1, 1]), ('normal control', {'price': 1200, 'period_days': 365, 'base_seats': 2, 'changes': []}, [0, 2, 2]), ('normal control', {'price': 1200, 'period_days': 28, 'base_seats': 9, 'changes': []}, [0, 9, 9])], [('regression', {'price': 1500, 'period_days': 28, 'base_seats': 12, 'changes': [[0, 4], [0, 9], [6, 24], [23, 1], [9, 21]]}, [14143, 24, 1]), ('regression', {'price': 1500, 'period_days': 28, 'base_seats': 10, 'changes': [[1, 16], [20, 13]]}, [8679, 16, 13]), ('partial-repair probe', {'price': 800, 'period_days': 31, 'base_seats': 7, 'changes': [[14, 11], [13, 12], [19, 0], [30, 25], [23, 8]]}, [2658, 25, 25]), ('partial-repair probe', {'price': 1500, 'period_days': 28, 'base_seats': 2, 'changes': [[26, 6], [4, 0], [26, 2]]}, [429, 6, 2]), ('normal control', {'price': 1200, 'period_days': 31, 'base_seats': 2, 'changes': [[3, 10]]}, [8671, 10, 10]), ('normal control', {'price': 8587, 'period_days': 30, 'base_seats': 12, 'changes': []}, [0, 12, 12]), ('normal control', {'price': 1200, 'period_days': 365, 'base_seats': 11, 'changes': []}, [0, 11, 11]), ('normal control', {'price': 8445, 'period_days': 365, 'base_seats': 1, 'changes': [[278, 2], [278, 7]]}, [12078, 7, 7])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    ch = sorted(x['changes'], key=lambda c: c[0])
    hwm = current = x['base_seats']
    charge = 0
    for day, count in ch:
        if count > hwm:
            added = count - hwm
            left = x['period_days'] - day
            charge += (x['price'] * added * left * 2 + x['period_days']) // (2 * x['period_days'])
            hwm = count
        if count < x['base_seats']:
            charge -= x['price'] * (x['base_seats'] - count)
        current = count
    final = ch[-1][1] if ch else x['base_seats']
    return [charge, hwm, final]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression (boundary)', {'price': 1000, 'period_days': 30, 'base_seats': 5, 'changes': [[3, 3], [10, 5], [12, 7]]}, [1200, 7, 7]), ('regression', {'price': 800, 'period_days': 30, 'base_seats': 13, 'changes': [[15, 1]]}, [0, 13, 1]), ('partial-repair probe', {'price': 1500, 'period_days': 30, 'base_seats': 9, 'changes': [[19, 10], [22, 3], [12, 12], [24, 3], [19, 20]]}, [7100, 20, 3]), ('partial-repair probe', {'price': 1200, 'period_days': 30, 'base_seats': 11, 'changes': [[6, 20], [12, 8], [15, 1], [7, 5], [0, 11]]}, [8640, 20, 1]), ('normal control', {'price': 800, 'period_days': 31, 'base_seats': 8, 'changes': []}, [0, 8, 8]), ('normal control', {'price': 1200, 'period_days': 31, 'base_seats': 11, 'changes': []}, [0, 11, 11]), ('normal control', {'price': 5360, 'period_days': 28, 'base_seats': 12, 'changes': []}, [0, 12, 12]), ('normal control', {'price': 800, 'period_days': 28, 'base_seats': 6, 'changes': [[27, 25], [1, 17], [12, 18]]}, [9143, 25, 25])], [('regression', {'price': 800, 'period_days': 30, 'base_seats': 13, 'changes': [[15, 1]]}, [0, 13, 1]), ('regression', {'price': 1500, 'period_days': 30, 'base_seats': 9, 'changes': [[19, 10], [22, 3], [12, 12], [24, 3], [19, 20]]}, [7100, 20, 3]), ('partial-repair probe', {'price': 1200, 'period_days': 30, 'base_seats': 11, 'changes': [[6, 20], [12, 8], [15, 1], [7, 5], [0, 11]]}, [8640, 20, 1]), ('partial-repair probe', {'price': 1500, 'period_days': 28, 'base_seats': 12, 'changes': [[0, 4], [0, 9], [6, 24], [23, 1], [9, 21]]}, [14143, 24, 1]), ('normal control', {'price': 1500, 'period_days': 31, 'base_seats': 6, 'changes': []}, [0, 6, 6]), ('normal control', {'price': 800, 'period_days': 365, 'base_seats': 15, 'changes': []}, [0, 15, 15]), ('normal control', {'price': 1200, 'period_days': 365, 'base_seats': 7, 'changes': []}, [0, 7, 7]), ('normal control', {'price': 1200, 'period_days': 30, 'base_seats': 13, 'changes': []}, [0, 13, 13])], [('regression', {'price': 1500, 'period_days': 30, 'base_seats': 9, 'changes': [[19, 10], [22, 3], [12, 12], [24, 3], [19, 20]]}, [7100, 20, 3]), ('regression', {'price': 1200, 'period_days': 30, 'base_seats': 11, 'changes': [[6, 20], [12, 8], [15, 1], [7, 5], [0, 11]]}, [8640, 20, 1]), ('partial-repair probe', {'price': 1500, 'period_days': 28, 'base_seats': 12, 'changes': [[0, 4], [0, 9], [6, 24], [23, 1], [9, 21]]}, [14143, 24, 1]), ('partial-repair probe', {'price': 5820, 'period_days': 365, 'base_seats': 15, 'changes': [[14, 25], [190, 23], [339, 10], [22, 7], [14, 1]]}, [55968, 25, 10]), ('normal control', {'price': 800, 'period_days': 30, 'base_seats': 1, 'changes': []}, [0, 1, 1]), ('normal control', {'price': 800, 'period_days': 28, 'base_seats': 11, 'changes': []}, [0, 11, 11]), ('normal control', {'price': 1200, 'period_days': 365, 'base_seats': 4, 'changes': [[333, 15], [352, 23], [4, 5]]}, [2581, 23, 23]), ('normal control', {'price': 1200, 'period_days': 31, 'base_seats': 1, 'changes': [[19, 14], [24, 18]]}, [7123, 18, 18])], [('regression', {'price': 1200, 'period_days': 30, 'base_seats': 11, 'changes': [[6, 20], [12, 8], [15, 1], [7, 5], [0, 11]]}, [8640, 20, 1]), ('regression', {'price': 1500, 'period_days': 28, 'base_seats': 10, 'changes': [[1, 16], [20, 13]]}, [8679, 16, 13]), ('partial-repair probe', {'price': 7507, 'period_days': 31, 'base_seats': 15, 'changes': [[15, 8]]}, [0, 15, 8]), ('partial-repair probe', {'price': 2726, 'period_days': 365, 'base_seats': 15, 'changes': [[171, 14], [284, 12], [141, 18], [171, 5]]}, [5019, 18, 12]), ('normal control', {'price': 800, 'period_days': 30, 'base_seats': 4, 'changes': [[21, 22], [29, 24]]}, [4373, 24, 24]), ('normal control', {'price': 6240, 'period_days': 28, 'base_seats': 1, 'changes': []}, [0, 1, 1]), ('normal control', {'price': 1200, 'period_days': 365, 'base_seats': 2, 'changes': []}, [0, 2, 2]), ('normal control', {'price': 1200, 'period_days': 28, 'base_seats': 9, 'changes': []}, [0, 9, 9])], [('regression', {'price': 1500, 'period_days': 28, 'base_seats': 12, 'changes': [[0, 4], [0, 9], [6, 24], [23, 1], [9, 21]]}, [14143, 24, 1]), ('regression', {'price': 1500, 'period_days': 28, 'base_seats': 10, 'changes': [[1, 16], [20, 13]]}, [8679, 16, 13]), ('partial-repair probe', {'price': 800, 'period_days': 31, 'base_seats': 7, 'changes': [[14, 11], [13, 12], [19, 0], [30, 25], [23, 8]]}, [2658, 25, 25]), ('partial-repair probe', {'price': 1500, 'period_days': 28, 'base_seats': 2, 'changes': [[26, 6], [4, 0], [26, 2]]}, [429, 6, 2]), ('normal control', {'price': 1200, 'period_days': 31, 'base_seats': 2, 'changes': [[3, 10]]}, [8671, 10, 10]), ('normal control', {'price': 8587, 'period_days': 30, 'base_seats': 12, 'changes': []}, [0, 12, 12]), ('normal control', {'price': 1200, 'period_days': 365, 'base_seats': 11, 'changes': []}, [0, 11, 11]), ('normal control', {'price': 8445, 'period_days': 365, 'base_seats': 1, 'changes': [[278, 2], [278, 7]]}, [12078, 7, 7])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Removing seats mid-cycle reduces the invoice although the contract grants credit only at renewal.

Input {price per seat per period, period_days, base_seats, changes: [[day, seat_count]]}. Changes apply in day order (same-day changes keep input order). Seats above the period high-water mark are charged price*added*(period_days - day)/period_days half-up; decreases earn no mid-cycle credit. Return [prorated charges, high-water mark, renewal seat count (the last count)].

split: open-access


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

N = 1
observations = []
def solve(x):
    ch = x['changes']
    hwm = current = x['base_seats']
    charge = 0
    for day, count in ch:
        if count > hwm:
            added = count - hwm
            left = x['period_days'] - day
            charge += (x['price'] * added * left * 2 + x['period_days']) // (2 * x['period_days'])
            hwm = count
        current = count
    final = ch[-1][1] if ch else x['base_seats']
    return [charge, hwm, final]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'price': 800, 'period_days': 30, 'base_seats': 11, 'changes': [[20, 22], [5, 15], [20, 14]]}, [4534, 22, 14]), ('regression', {'price': 1500, 'period_days': 30, 'base_seats': 9, 'changes': [[19, 10], [22, 3], [12, 12], [24, 3], [19, 20]]}, [7100, 20, 3]), ('partial-repair probe', {'price': 1500, 'period_days': 28, 'base_seats': 2, 'changes': [[26, 6], [4, 0], [26, 2]]}, [429, 6, 2]), ('partial-repair probe', {'price': 1200, 'period_days': 30, 'base_seats': 5, 'changes': [[22, 12], [22, 9]]}, [2240, 12, 9]), ('boundary control', {'price': 1000, 'period_days': 30, 'base_seats': 5, 'changes': [[3, 3], [10, 5], [12, 7]]}, [1200, 7, 7]), ('normal control', {'price': 800, 'period_days': 31, 'base_seats': 8, 'changes': []}, [0, 8, 8]), ('normal control', {'price': 800, 'period_days': 30, 'base_seats': 13, 'changes': [[15, 1]]}, [0, 13, 1]), ('normal control', {'price': 1200, 'period_days': 31, 'base_seats': 11, 'changes': []}, [0, 11, 11]), ('normal control', {'price': 5360, 'period_days': 28, 'base_seats': 12, 'changes': []}, [0, 12, 12])], [('regression', {'price': 800, 'period_days': 28, 'base_seats': 1, 'changes': [[8, 6], [20, 16], [14, 24], [20, 8], [8, 18]]}, [12114, 24, 8]), ('regression', {'price': 1200, 'period_days': 30, 'base_seats': 11, 'changes': [[6, 20], [12, 8], [15, 1], [7, 5], [0, 11]]}, [8640, 20, 1]), ('partial-repair probe', {'price': 1200, 'period_days': 30, 'base_seats': 5, 'changes': [[22, 12], [22, 9]]}, [2240, 12, 9]), ('partial-repair probe', {'price': 800, 'period_days': 28, 'base_seats': 12, 'changes': [[10, 22], [10, 5]]}, [5143, 22, 5]), ('boundary control', {'price': 1000, 'period_days': 30, 'base_seats': 5, 'changes': [[3, 3], [10, 5], [12, 7]]}, [1200, 7, 7]), ('normal control', {'price': 1500, 'period_days': 28, 'base_seats': 10, 'changes': [[1, 16], [20, 13]]}, [8679, 16, 13]), ('normal control', {'price': 7507, 'period_days': 31, 'base_seats': 15, 'changes': [[15, 8]]}, [0, 15, 8]), ('normal control', {'price': 1500, 'period_days': 31, 'base_seats': 6, 'changes': []}, [0, 6, 6]), ('normal control', {'price': 800, 'period_days': 365, 'base_seats': 15, 'changes': []}, [0, 15, 15])], [('regression', {'price': 6996, 'period_days': 31, 'base_seats': 1, 'changes': [[20, 25], [20, 21], [14, 19], [5, 9], [20, 18]]}, [100201, 25, 18]), ('regression', {'price': 800, 'period_days': 28, 'base_seats': 6, 'changes': [[27, 25], [1, 17], [12, 18]]}, [9143, 25, 25]), ('partial-repair probe', {'price': 800, 'period_days': 28, 'base_seats': 12, 'changes': [[10, 22], [10, 5]]}, [5143, 22, 5]), ('partial-repair probe', {'price': 800, 'period_days': 31, 'base_seats': 6, 'changes': [[4, 17], [4, 6]]}, [7665, 17, 6]), ('boundary control', {'price': 1000, 'period_days': 30, 'base_seats': 5, 'changes': [[3, 3], [10, 5], [12, 7]]}, [1200, 7, 7]), ('normal control', {'price': 1200, 'period_days': 365, 'base_seats': 7, 'changes': []}, [0, 7, 7]), ('normal control', {'price': 800, 'period_days': 31, 'base_seats': 9, 'changes': [[0, 4], [4, 7]]}, [0, 9, 7]), ('normal control', {'price': 1200, 'period_days': 30, 'base_seats': 13, 'changes': []}, [0, 13, 13]), ('normal control', {'price': 800, 'period_days': 28, 'base_seats': 2, 'changes': [[14, 0]]}, [0, 2, 0])], [('regression', {'price': 800, 'period_days': 30, 'base_seats': 4, 'changes': [[26, 12], [9, 10], [26, 2], [8, 24], [12, 2], [26, 6]]}, [11733, 24, 6]), ('regression', {'price': 1500, 'period_days': 28, 'base_seats': 12, 'changes': [[0, 4], [0, 9], [6, 24], [23, 1], [9, 21]]}, [14143, 24, 1]), ('partial-repair probe', {'price': 1500, 'period_days': 28, 'base_seats': 11, 'changes': [[3, 14], [6, 7], [15, 20], [15, 9]]}, [8197, 20, 9]), ('partial-repair probe', {'price': 6996, 'period_days': 31, 'base_seats': 1, 'changes': [[20, 25], [20, 21], [14, 19], [5, 9], [20, 18]]}, [100201, 25, 18]), ('boundary control', {'price': 1000, 'period_days': 30, 'base_seats': 5, 'changes': [[3, 3], [10, 5], [12, 7]]}, [1200, 7, 7]), ('normal control', {'price': 800, 'period_days': 30, 'base_seats': 1, 'changes': []}, [0, 1, 1]), ('normal control', {'price': 1500, 'period_days': 30, 'base_seats': 1, 'changes': [[18, 0], [27, 5]]}, [600, 5, 5]), ('normal control', {'price': 1500, 'period_days': 31, 'base_seats': 13, 'changes': [[24, 7]]}, [0, 13, 7]), ('normal control', {'price': 800, 'period_days': 28, 'base_seats': 11, 'changes': []}, [0, 11, 11])], [('regression', {'price': 2883, 'period_days': 30, 'base_seats': 5, 'changes': [[21, 11], [0, 6], [21, 10]]}, [7208, 11, 10]), ('regression', {'price': 5820, 'period_days': 365, 'base_seats': 15, 'changes': [[14, 25], [190, 23], [339, 10], [22, 7], [14, 1]]}, [55968, 25, 10]), ('partial-repair probe', {'price': 800, 'period_days': 30, 'base_seats': 4, 'changes': [[26, 12], [9, 10], [26, 2], [8, 24], [12, 2], [26, 6]]}, [11733, 24, 6]), ('partial-repair probe', {'price': 1500, 'period_days': 28, 'base_seats': 5, 'changes': [[24, 9], [24, 19], [24, 10]]}, [3000, 19, 10]), ('boundary control', {'price': 1000, 'period_days': 30, 'base_seats': 5, 'changes': [[3, 3], [10, 5], [12, 7]]}, [1200, 7, 7]), ('normal control', {'price': 1200, 'period_days': 31, 'base_seats': 1, 'changes': [[19, 14], [24, 18]]}, [7123, 18, 18]), ('normal control', {'price': 800, 'period_days': 30, 'base_seats': 4, 'changes': [[21, 22], [29, 24]]}, [4373, 24, 24]), ('normal control', {'price': 6240, 'period_days': 28, 'base_seats': 1, 'changes': []}, [0, 1, 1]), ('normal control', {'price': 1200, 'period_days': 365, 'base_seats': 2, 'changes': []}, [0, 2, 2])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    ch = sorted(x['changes'], key=lambda c: (c[0], c[1]))
    hwm = current = x['base_seats']
    charge = 0
    for day, count in ch:
        if count > hwm:
            added = count - hwm
            left = x['period_days'] - day
            charge += (x['price'] * added * left * 2 + x['period_days']) // (2 * x['period_days'])
            hwm = count
        current = count
    final = ch[-1][1] if ch else x['base_seats']
    return [charge, hwm, final]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'price': 800, 'period_days': 30, 'base_seats': 11, 'changes': [[20, 22], [5, 15], [20, 14]]}, [4534, 22, 14]), ('regression', {'price': 1500, 'period_days': 30, 'base_seats': 9, 'changes': [[19, 10], [22, 3], [12, 12], [24, 3], [19, 20]]}, [7100, 20, 3]), ('partial-repair probe', {'price': 1500, 'period_days': 28, 'base_seats': 2, 'changes': [[26, 6], [4, 0], [26, 2]]}, [429, 6, 2]), ('partial-repair probe', {'price': 1200, 'period_days': 30, 'base_seats': 5, 'changes': [[22, 12], [22, 9]]}, [2240, 12, 9]), ('boundary control', {'price': 1000, 'period_days': 30, 'base_seats': 5, 'changes': [[3, 3], [10, 5], [12, 7]]}, [1200, 7, 7]), ('normal control', {'price': 800, 'period_days': 31, 'base_seats': 8, 'changes': []}, [0, 8, 8]), ('normal control', {'price': 800, 'period_days': 30, 'base_seats': 13, 'changes': [[15, 1]]}, [0, 13, 1]), ('normal control', {'price': 1200, 'period_days': 31, 'base_seats': 11, 'changes': []}, [0, 11, 11]), ('normal control', {'price': 5360, 'period_days': 28, 'base_seats': 12, 'changes': []}, [0, 12, 12])], [('regression', {'price': 800, 'period_days': 28, 'base_seats': 1, 'changes': [[8, 6], [20, 16], [14, 24], [20, 8], [8, 18]]}, [12114, 24, 8]), ('regression', {'price': 1200, 'period_days': 30, 'base_seats': 11, 'changes': [[6, 20], [12, 8], [15, 1], [7, 5], [0, 11]]}, [8640, 20, 1]), ('partial-repair probe', {'price': 1200, 'period_days': 30, 'base_seats': 5, 'changes': [[22, 12], [22, 9]]}, [2240, 12, 9]), ('partial-repair probe', {'price': 800, 'period_days': 28, 'base_seats': 12, 'changes': [[10, 22], [10, 5]]}, [5143, 22, 5]), ('boundary control', {'price': 1000, 'period_days': 30, 'base_seats': 5, 'changes': [[3, 3], [10, 5], [12, 7]]}, [1200, 7, 7]), ('normal control', {'price': 1500, 'period_days': 28, 'base_seats': 10, 'changes': [[1, 16], [20, 13]]}, [8679, 16, 13]), ('normal control', {'price': 7507, 'period_days': 31, 'base_seats': 15, 'changes': [[15, 8]]}, [0, 15, 8]), ('normal control', {'price': 1500, 'period_days': 31, 'base_seats': 6, 'changes': []}, [0, 6, 6]), ('normal control', {'price': 800, 'period_days': 365, 'base_seats': 15, 'changes': []}, [0, 15, 15])], [('regression', {'price': 6996, 'period_days': 31, 'base_seats': 1, 'changes': [[20, 25], [20, 21], [14, 19], [5, 9], [20, 18]]}, [100201, 25, 18]), ('regression', {'price': 800, 'period_days': 28, 'base_seats': 6, 'changes': [[27, 25], [1, 17], [12, 18]]}, [9143, 25, 25]), ('partial-repair probe', {'price': 800, 'period_days': 28, 'base_seats': 12, 'changes': [[10, 22], [10, 5]]}, [5143, 22, 5]), ('partial-repair probe', {'price': 800, 'period_days': 31, 'base_seats': 6, 'changes': [[4, 17], [4, 6]]}, [7665, 17, 6]), ('boundary control', {'price': 1000, 'period_days': 30, 'base_seats': 5, 'changes': [[3, 3], [10, 5], [12, 7]]}, [1200, 7, 7]), ('normal control', {'price': 1200, 'period_days': 365, 'base_seats': 7, 'changes': []}, [0, 7, 7]), ('normal control', {'price': 800, 'period_days': 31, 'base_seats': 9, 'changes': [[0, 4], [4, 7]]}, [0, 9, 7]), ('normal control', {'price': 1200, 'period_days': 30, 'base_seats': 13, 'changes': []}, [0, 13, 13]), ('normal control', {'price': 800, 'period_days': 28, 'base_seats': 2, 'changes': [[14, 0]]}, [0, 2, 0])], [('regression', {'price': 800, 'period_days': 30, 'base_seats': 4, 'changes': [[26, 12], [9, 10], [26, 2], [8, 24], [12, 2], [26, 6]]}, [11733, 24, 6]), ('regression', {'price': 1500, 'period_days': 28, 'base_seats': 12, 'changes': [[0, 4], [0, 9], [6, 24], [23, 1], [9, 21]]}, [14143, 24, 1]), ('partial-repair probe', {'price': 1500, 'period_days': 28, 'base_seats': 11, 'changes': [[3, 14], [6, 7], [15, 20], [15, 9]]}, [8197, 20, 9]), ('partial-repair probe', {'price': 6996, 'period_days': 31, 'base_seats': 1, 'changes': [[20, 25], [20, 21], [14, 19], [5, 9], [20, 18]]}, [100201, 25, 18]), ('boundary control', {'price': 1000, 'period_days': 30, 'base_seats': 5, 'changes': [[3, 3], [10, 5], [12, 7]]}, [1200, 7, 7]), ('normal control', {'price': 800, 'period_days': 30, 'base_seats': 1, 'changes': []}, [0, 1, 1]), ('normal control', {'price': 1500, 'period_days': 30, 'base_seats': 1, 'changes': [[18, 0], [27, 5]]}, [600, 5, 5]), ('normal control', {'price': 1500, 'period_days': 31, 'base_seats': 13, 'changes': [[24, 7]]}, [0, 13, 7]), ('normal control', {'price': 800, 'period_days': 28, 'base_seats': 11, 'changes': []}, [0, 11, 11])], [('regression', {'price': 2883, 'period_days': 30, 'base_seats': 5, 'changes': [[21, 11], [0, 6], [21, 10]]}, [7208, 11, 10]), ('regression', {'price': 5820, 'period_days': 365, 'base_seats': 15, 'changes': [[14, 25], [190, 23], [339, 10], [22, 7], [14, 1]]}, [55968, 25, 10]), ('partial-repair probe', {'price': 800, 'period_days': 30, 'base_seats': 4, 'changes': [[26, 12], [9, 10], [26, 2], [8, 24], [12, 2], [26, 6]]}, [11733, 24, 6]), ('partial-repair probe', {'price': 1500, 'period_days': 28, 'base_seats': 5, 'changes': [[24, 9], [24, 19], [24, 10]]}, [3000, 19, 10]), ('boundary control', {'price': 1000, 'period_days': 30, 'base_seats': 5, 'changes': [[3, 3], [10, 5], [12, 7]]}, [1200, 7, 7]), ('normal control', {'price': 1200, 'period_days': 31, 'base_seats': 1, 'changes': [[19, 14], [24, 18]]}, [7123, 18, 18]), ('normal control', {'price': 800, 'period_days': 30, 'base_seats': 4, 'changes': [[21, 22], [29, 24]]}, [4373, 24, 24]), ('normal control', {'price': 6240, 'period_days': 28, 'base_seats': 1, 'changes': []}, [0, 1, 1]), ('normal control', {'price': 1200, 'period_days': 365, 'base_seats': 2, 'changes': []}, [0, 2, 2])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Out-of-order change logs charge seats for the wrong number of days.

Input {price per seat per period, period_days, base_seats, changes: [[day, seat_count]]}. Changes apply in day order (same-day changes keep input order). Seats above the period high-water mark are charged price*added*(period_days - day)/period_days half-up; decreases earn no mid-cycle credit. Return [prorated charges, high-water mark, renewal seat count (the last count)].

split: open-access


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

N = 1
observations = []
def solve(x):
    ch = sorted(x['changes'], key=lambda c: c[0])
    hwm = current = x['base_seats']
    charge = 0
    for day, count in ch:
        if count > hwm:
            added = count - hwm
            left = x['period_days'] - day
            charge += (x['price'] * added * left * 2 + x['period_days']) // (2 * x['period_days'])
            hwm = count
        current = count
    final = hwm
    return [charge, hwm, final]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'price': 1500, 'period_days': 30, 'base_seats': 9, 'changes': [[19, 10], [22, 3], [12, 12], [24, 3], [19, 20]]}, [7100, 20, 3]), ('regression', {'price': 800, 'period_days': 30, 'base_seats': 13, 'changes': [[15, 1]]}, [0, 13, 1]), ('partial-repair probe', {'price': 1200, 'period_days': 30, 'base_seats': 11, 'changes': [[6, 20], [12, 8], [15, 1], [7, 5], [0, 11]]}, [8640, 20, 1]), ('partial-repair probe', {'price': 800, 'period_days': 28, 'base_seats': 6, 'changes': [[27, 25], [1, 17], [12, 18]]}, [9143, 25, 25]), ('boundary control', {'price': 1000, 'period_days': 30, 'base_seats': 5, 'changes': [[3, 3], [10, 5], [12, 7]]}, [1200, 7, 7]), ('normal control', {'price': 800, 'period_days': 31, 'base_seats': 8, 'changes': []}, [0, 8, 8]), ('normal control', {'price': 1200, 'period_days': 31, 'base_seats': 11, 'changes': []}, [0, 11, 11]), ('normal control', {'price': 5360, 'period_days': 28, 'base_seats': 12, 'changes': []}, [0, 12, 12]), ('normal control', {'price': 1500, 'period_days': 31, 'base_seats': 6, 'changes': []}, [0, 6, 6])], [('regression', {'price': 1200, 'period_days': 30, 'base_seats': 11, 'changes': [[6, 20], [12, 8], [15, 1], [7, 5], [0, 11]]}, [8640, 20, 1]), ('regression', {'price': 1500, 'period_days': 30, 'base_seats': 9, 'changes': [[19, 10], [22, 3], [12, 12], [24, 3], [19, 20]]}, [7100, 20, 3]), ('partial-repair probe', {'price': 800, 'period_days': 28, 'base_seats': 6, 'changes': [[27, 25], [1, 17], [12, 18]]}, [9143, 25, 25]), ('partial-repair probe', {'price': 1500, 'period_days': 28, 'base_seats': 12, 'changes': [[0, 4], [0, 9], [6, 24], [23, 1], [9, 21]]}, [14143, 24, 1]), ('boundary control', {'price': 1000, 'period_days': 30, 'base_seats': 5, 'changes': [[3, 3], [10, 5], [12, 7]]}, [1200, 7, 7]), ('normal control', {'price': 800, 'period_days': 365, 'base_seats': 15, 'changes': []}, [0, 15, 15]), ('normal control', {'price': 1200, 'period_days': 365, 'base_seats': 7, 'changes': []}, [0, 7, 7]), ('normal control', {'price': 1200, 'period_days': 30, 'base_seats': 13, 'changes': []}, [0, 13, 13]), ('normal control', {'price': 800, 'period_days': 30, 'base_seats': 1, 'changes': []}, [0, 1, 1])], [('regression', {'price': 1500, 'period_days': 28, 'base_seats': 12, 'changes': [[0, 4], [0, 9], [6, 24], [23, 1], [9, 21]]}, [14143, 24, 1]), ('regression', {'price': 1200, 'period_days': 30, 'base_seats': 11, 'changes': [[6, 20], [12, 8], [15, 1], [7, 5], [0, 11]]}, [8640, 20, 1]), ('partial-repair probe', {'price': 5820, 'period_days': 365, 'base_seats': 15, 'changes': [[14, 25], [190, 23], [339, 10], [22, 7], [14, 1]]}, [55968, 25, 10]), ('partial-repair probe', {'price': 2726, 'period_days': 365, 'base_seats': 15, 'changes': [[171, 14], [284, 12], [141, 18], [171, 5]]}, [5019, 18, 12]), ('boundary control', {'price': 1000, 'period_days': 30, 'base_seats': 5, 'changes': [[3, 3], [10, 5], [12, 7]]}, [1200, 7, 7]), ('normal control', {'price': 1500, 'period_days': 365, 'base_seats': 10, 'changes': [[41, 3], [46, 0], [12, 3], [315, 24], [41, 24]]}, [18641, 24, 24]), ('normal control', {'price': 1500, 'period_days': 30, 'base_seats': 1, 'changes': [[18, 0], [27, 5]]}, [600, 5, 5]), ('normal control', {'price': 800, 'period_days': 28, 'base_seats': 11, 'changes': []}, [0, 11, 11]), ('normal control', {'price': 1200, 'period_days': 31, 'base_seats': 1, 'changes': [[19, 14], [24, 18]]}, [7123, 18, 18])], [('regression', {'price': 5820, 'period_days': 365, 'base_seats': 15, 'changes': [[14, 25], [190, 23], [339, 10], [22, 7], [14, 1]]}, [55968, 25, 10]), ('regression', {'price': 1500, 'period_days': 28, 'base_seats': 10, 'changes': [[1, 16], [20, 13]]}, [8679, 16, 13]), ('partial-repair probe', {'price': 800, 'period_days': 30, 'base_seats': 8, 'changes': [[19, 24], [23, 8], [10, 24], [12, 12]]}, [8533, 24, 8]), ('partial-repair probe', {'price': 800, 'period_days': 31, 'base_seats': 7, 'changes': [[14, 11], [13, 12], [19, 0], [30, 25], [23, 8]]}, [2658, 25, 25]), ('boundary control', {'price': 1000, 'period_days': 30, 'base_seats': 5, 'changes': [[3, 3], [10, 5], [12, 7]]}, [1200, 7, 7]), ('normal control', {'price': 800, 'period_days': 30, 'base_seats': 4, 'changes': [[21, 22], [29, 24]]}, [4373, 24, 24]), ('normal control', {'price': 6240, 'period_days': 28, 'base_seats': 1, 'changes': []}, [0, 1, 1]), ('normal control', {'price': 1200, 'period_days': 365, 'base_seats': 2, 'changes': []}, [0, 2, 2]), ('normal control', {'price': 1200, 'period_days': 28, 'base_seats': 9, 'changes': []}, [0, 9, 9])], [('regression', {'price': 2726, 'period_days': 365, 'base_seats': 15, 'changes': [[171, 14], [284, 12], [141, 18], [171, 5]]}, [5019, 18, 12]), ('regression', {'price': 1500, 'period_days': 28, 'base_seats': 12, 'changes': [[0, 4], [0, 9], [6, 24], [23, 1], [9, 21]]}, [14143, 24, 1]), ('partial-repair probe', {'price': 1500, 'period_days': 28, 'base_seats': 7, 'changes': [[17, 25], [9, 11], [4, 16], [3, 0], [0, 15]]}, [18590, 25, 25]), ('partial-repair probe', {'price': 800, 'period_days': 30, 'base_seats': 14, 'changes': [[5, 14], [28, 7], [18, 5], [7, 10], [5, 4]]}, [0, 14, 7]), ('boundary control', {'price': 1000, 'period_days': 30, 'base_seats': 5, 'changes': [[3, 3], [10, 5], [12, 7]]}, [1200, 7, 7]), ('normal control', {'price': 1200, 'period_days': 31, 'base_seats': 2, 'changes': [[3, 10]]}, [8671, 10, 10]), ('normal control', {'price': 8587, 'period_days': 30, 'base_seats': 12, 'changes': []}, [0, 12, 12]), ('normal control', {'price': 1200, 'period_days': 365, 'base_seats': 11, 'changes': []}, [0, 11, 11]), ('normal control', {'price': 8445, 'period_days': 365, 'base_seats': 1, 'changes': [[278, 2], [278, 7]]}, [12078, 7, 7])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    ch = sorted(x['changes'], key=lambda c: c[0])
    hwm = current = x['base_seats']
    charge = 0
    for day, count in ch:
        if count > hwm:
            added = count - hwm
            left = x['period_days'] - day
            charge += (x['price'] * added * left * 2 + x['period_days']) // (2 * x['period_days'])
            hwm = count
        current = count
    final = x['changes'][-1][1] if ch else x['base_seats']
    return [charge, hwm, final]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'price': 1500, 'period_days': 30, 'base_seats': 9, 'changes': [[19, 10], [22, 3], [12, 12], [24, 3], [19, 20]]}, [7100, 20, 3]), ('regression', {'price': 800, 'period_days': 30, 'base_seats': 13, 'changes': [[15, 1]]}, [0, 13, 1]), ('partial-repair probe', {'price': 1200, 'period_days': 30, 'base_seats': 11, 'changes': [[6, 20], [12, 8], [15, 1], [7, 5], [0, 11]]}, [8640, 20, 1]), ('partial-repair probe', {'price': 800, 'period_days': 28, 'base_seats': 6, 'changes': [[27, 25], [1, 17], [12, 18]]}, [9143, 25, 25]), ('boundary control', {'price': 1000, 'period_days': 30, 'base_seats': 5, 'changes': [[3, 3], [10, 5], [12, 7]]}, [1200, 7, 7]), ('normal control', {'price': 800, 'period_days': 31, 'base_seats': 8, 'changes': []}, [0, 8, 8]), ('normal control', {'price': 1200, 'period_days': 31, 'base_seats': 11, 'changes': []}, [0, 11, 11]), ('normal control', {'price': 5360, 'period_days': 28, 'base_seats': 12, 'changes': []}, [0, 12, 12]), ('normal control', {'price': 1500, 'period_days': 31, 'base_seats': 6, 'changes': []}, [0, 6, 6])], [('regression', {'price': 1200, 'period_days': 30, 'base_seats': 11, 'changes': [[6, 20], [12, 8], [15, 1], [7, 5], [0, 11]]}, [8640, 20, 1]), ('regression', {'price': 1500, 'period_days': 30, 'base_seats': 9, 'changes': [[19, 10], [22, 3], [12, 12], [24, 3], [19, 20]]}, [7100, 20, 3]), ('partial-repair probe', {'price': 800, 'period_days': 28, 'base_seats': 6, 'changes': [[27, 25], [1, 17], [12, 18]]}, [9143, 25, 25]), ('partial-repair probe', {'price': 1500, 'period_days': 28, 'base_seats': 12, 'changes': [[0, 4], [0, 9], [6, 24], [23, 1], [9, 21]]}, [14143, 24, 1]), ('boundary control', {'price': 1000, 'period_days': 30, 'base_seats': 5, 'changes': [[3, 3], [10, 5], [12, 7]]}, [1200, 7, 7]), ('normal control', {'price': 800, 'period_days': 365, 'base_seats': 15, 'changes': []}, [0, 15, 15]), ('normal control', {'price': 1200, 'period_days': 365, 'base_seats': 7, 'changes': []}, [0, 7, 7]), ('normal control', {'price': 1200, 'period_days': 30, 'base_seats': 13, 'changes': []}, [0, 13, 13]), ('normal control', {'price': 800, 'period_days': 30, 'base_seats': 1, 'changes': []}, [0, 1, 1])], [('regression', {'price': 1500, 'period_days': 28, 'base_seats': 12, 'changes': [[0, 4], [0, 9], [6, 24], [23, 1], [9, 21]]}, [14143, 24, 1]), ('regression', {'price': 1200, 'period_days': 30, 'base_seats': 11, 'changes': [[6, 20], [12, 8], [15, 1], [7, 5], [0, 11]]}, [8640, 20, 1]), ('partial-repair probe', {'price': 5820, 'period_days': 365, 'base_seats': 15, 'changes': [[14, 25], [190, 23], [339, 10], [22, 7], [14, 1]]}, [55968, 25, 10]), ('partial-repair probe', {'price': 2726, 'period_days': 365, 'base_seats': 15, 'changes': [[171, 14], [284, 12], [141, 18], [171, 5]]}, [5019, 18, 12]), ('boundary control', {'price': 1000, 'period_days': 30, 'base_seats': 5, 'changes': [[3, 3], [10, 5], [12, 7]]}, [1200, 7, 7]), ('normal control', {'price': 1500, 'period_days': 365, 'base_seats': 10, 'changes': [[41, 3], [46, 0], [12, 3], [315, 24], [41, 24]]}, [18641, 24, 24]), ('normal control', {'price': 1500, 'period_days': 30, 'base_seats': 1, 'changes': [[18, 0], [27, 5]]}, [600, 5, 5]), ('normal control', {'price': 800, 'period_days': 28, 'base_seats': 11, 'changes': []}, [0, 11, 11]), ('normal control', {'price': 1200, 'period_days': 31, 'base_seats': 1, 'changes': [[19, 14], [24, 18]]}, [7123, 18, 18])], [('regression', {'price': 5820, 'period_days': 365, 'base_seats': 15, 'changes': [[14, 25], [190, 23], [339, 10], [22, 7], [14, 1]]}, [55968, 25, 10]), ('regression', {'price': 1500, 'period_days': 28, 'base_seats': 10, 'changes': [[1, 16], [20, 13]]}, [8679, 16, 13]), ('partial-repair probe', {'price': 800, 'period_days': 30, 'base_seats': 8, 'changes': [[19, 24], [23, 8], [10, 24], [12, 12]]}, [8533, 24, 8]), ('partial-repair probe', {'price': 800, 'period_days': 31, 'base_seats': 7, 'changes': [[14, 11], [13, 12], [19, 0], [30, 25], [23, 8]]}, [2658, 25, 25]), ('boundary control', {'price': 1000, 'period_days': 30, 'base_seats': 5, 'changes': [[3, 3], [10, 5], [12, 7]]}, [1200, 7, 7]), ('normal control', {'price': 800, 'period_days': 30, 'base_seats': 4, 'changes': [[21, 22], [29, 24]]}, [4373, 24, 24]), ('normal control', {'price': 6240, 'period_days': 28, 'base_seats': 1, 'changes': []}, [0, 1, 1]), ('normal control', {'price': 1200, 'period_days': 365, 'base_seats': 2, 'changes': []}, [0, 2, 2]), ('normal control', {'price': 1200, 'period_days': 28, 'base_seats': 9, 'changes': []}, [0, 9, 9])], [('regression', {'price': 2726, 'period_days': 365, 'base_seats': 15, 'changes': [[171, 14], [284, 12], [141, 18], [171, 5]]}, [5019, 18, 12]), ('regression', {'price': 1500, 'period_days': 28, 'base_seats': 12, 'changes': [[0, 4], [0, 9], [6, 24], [23, 1], [9, 21]]}, [14143, 24, 1]), ('partial-repair probe', {'price': 1500, 'period_days': 28, 'base_seats': 7, 'changes': [[17, 25], [9, 11], [4, 16], [3, 0], [0, 15]]}, [18590, 25, 25]), ('partial-repair probe', {'price': 800, 'period_days': 30, 'base_seats': 14, 'changes': [[5, 14], [28, 7], [18, 5], [7, 10], [5, 4]]}, [0, 14, 7]), ('boundary control', {'price': 1000, 'period_days': 30, 'base_seats': 5, 'changes': [[3, 3], [10, 5], [12, 7]]}, [1200, 7, 7]), ('normal control', {'price': 1200, 'period_days': 31, 'base_seats': 2, 'changes': [[3, 10]]}, [8671, 10, 10]), ('normal control', {'price': 8587, 'period_days': 30, 'base_seats': 12, 'changes': []}, [0, 12, 12]), ('normal control', {'price': 1200, 'period_days': 365, 'base_seats': 11, 'changes': []}, [0, 11, 11]), ('normal control', {'price': 8445, 'period_days': 365, 'base_seats': 1, 'changes': [[278, 2], [278, 7]]}, [12078, 7, 7])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Renewal invoices bill the peak seat count even after seats were removed.

Input {price per seat per period, period_days, base_seats, changes: [[day, seat_count]]}. Changes apply in day order (same-day changes keep input order). Seats above the period high-water mark are charged price*added*(period_days - day)/period_days half-up; decreases earn no mid-cycle credit. Return [prorated charges, high-water mark, renewal seat count (the last count)].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
import calendar
N = 1
observations = []
def solve(x):
    t = datetime.date(*x['trial_end'])
    a = x['anchor_day']
    if t.day == a:
        ny, nm = (t.year + 1, 1) if t.month == 12 else (t.year, t.month + 1)
        return [x['price'], datetime.date(ny, nm, a).isoformat()]
    if t.day < a:
        nxt = datetime.date(t.year, t.month, a)
        py, pm = (t.year - 1, 12) if t.month == 1 else (t.year, t.month - 1)
        prev = datetime.date(py, pm, a)
    else:
        ey, em = (t.year + 1, 1) if t.month == 12 else (t.year, t.month + 1)
        nxt = datetime.date(ey, em, a)
        prev = datetime.date(t.year, t.month, a)
    days = (nxt - t).days
    cycle = 30
    return [(x['price'] * days * 2 + cycle) // (2 * cycle), nxt.isoformat()]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'trial_end': [2024, 4, 27], 'anchor_day': 28, 'price': 999}, [32, '2024-04-28']), ('regression', {'trial_end': [2024, 4, 1], 'anchor_day': 28, 'price': 78891}, [68712, '2024-04-28']), ('partial-repair probe', {'trial_end': [2024, 12, 16], 'anchor_day': 28, 'price': 2900}, [1160, '2024-12-28']), ('partial-repair probe', {'trial_end': [2025, 2, 6], 'anchor_day': 15, 'price': 2900}, [842, '2025-02-15']), ('normal control', {'trial_end': [2023, 4, 14], 'anchor_day': 1, 'price': 999}, [566, '2023-05-01']), ('normal control', {'trial_end': [2023, 6, 15], 'anchor_day': 15, 'price': 999}, [999, '2023-07-15']), ('normal control', {'trial_end': [2025, 3, 15], 'anchor_day': 15, 'price': 2900}, [2900, '2025-04-15']), ('normal control', {'trial_end': [2024, 2, 8], 'anchor_day': 8, 'price': 999}, [999, '2024-03-08'])], [('regression', {'trial_end': [2024, 4, 1], 'anchor_day': 28, 'price': 78891}, [68712, '2024-04-28']), ('regression', {'trial_end': [2024, 12, 25], 'anchor_day': 1, 'price': 12600}, [2845, '2025-01-01']), ('partial-repair probe', {'trial_end': [2025, 2, 6], 'anchor_day': 15, 'price': 2900}, [842, '2025-02-15']), ('partial-repair probe', {'trial_end': [2024, 6, 4], 'anchor_day': 28, 'price': 999}, [773, '2024-06-28']), ('normal control', {'trial_end': [2024, 6, 25], 'anchor_day': 1, 'price': 2900}, [580, '2024-07-01']), ('normal control', {'trial_end': [2023, 4, 30], 'anchor_day': 15, 'price': 44760}, [22380, '2023-05-15']), ('normal control', {'trial_end': [2024, 6, 14], 'anchor_day': 1, 'price': 999}, [566, '2024-07-01']), ('normal control', {'trial_end': [2024, 7, 15], 'anchor_day': 15, 'price': 999}, [999, '2024-08-15'])], [('regression', {'trial_end': [2025, 2, 6], 'anchor_day': 15, 'price': 2900}, [842, '2025-02-15']), ('regression', {'trial_end': [2024, 12, 25], 'anchor_day': 1, 'price': 12600}, [2845, '2025-01-01']), ('partial-repair probe', {'trial_end': [2024, 6, 4], 'anchor_day': 28, 'price': 999}, [773, '2024-06-28']), ('partial-repair probe', {'trial_end': [2024, 4, 10], 'anchor_day': 15, 'price': 2900}, [468, '2024-04-15']), ('normal control', {'trial_end': [2023, 3, 26], 'anchor_day': 26, 'price': 2900}, [2900, '2023-04-26']), ('normal control', {'trial_end': [2023, 5, 22], 'anchor_day': 22, 'price': 47810}, [47810, '2023-06-22']), ('normal control', {'trial_end': [2025, 6, 10], 'anchor_day': 10, 'price': 999}, [999, '2025-07-10']), ('normal control', {'trial_end': [2023, 12, 2], 'anchor_day': 2, 'price': 999}, [999, '2024-01-02'])], [('regression', {'trial_end': [2024, 6, 4], 'anchor_day': 28, 'price': 999}, [773, '2024-06-28']), ('regression', {'trial_end': [2025, 2, 6], 'anchor_day': 15, 'price': 2900}, [842, '2025-02-15']), ('partial-repair probe', {'trial_end': [2023, 10, 3], 'anchor_day': 16, 'price': 999}, [433, '2023-10-16']), ('partial-repair probe', {'trial_end': [2023, 6, 18], 'anchor_day': 28, 'price': 2900}, [935, '2023-06-28']), ('normal control', {'trial_end': [2023, 5, 29], 'anchor_day': 29, 'price': 15548}, [15548, '2023-06-29']), ('normal control', {'trial_end': [2024, 6, 15], 'anchor_day': 15, 'price': 8594}, [8594, '2024-07-15']), ('normal control', {'trial_end': [2023, 4, 17], 'anchor_day': 1, 'price': 2900}, [1353, '2023-05-01']), ('normal control', {'trial_end': [2023, 4, 6], 'anchor_day': 6, 'price': 999}, [999, '2023-05-06'])], [('regression', {'trial_end': [2024, 4, 10], 'anchor_day': 15, 'price': 2900}, [468, '2024-04-15']), ('regression', {'trial_end': [2023, 12, 16], 'anchor_day': 15, 'price': 2900}, [2806, '2024-01-15']), ('partial-repair probe', {'trial_end': [2025, 3, 22], 'anchor_day': 28, 'price': 58121}, [12455, '2025-03-28']), ('partial-repair probe', {'trial_end': [2024, 3, 15], 'anchor_day': 28, 'price': 999}, [448, '2024-03-28']), ('normal control', {'trial_end': [2023, 11, 28], 'anchor_day': 28, 'price': 2900}, [2900, '2023-12-28']), ('normal control', {'trial_end': [2024, 4, 11], 'anchor_day': 1, 'price': 999}, [666, '2024-05-01']), ('normal control', {'trial_end': [2023, 3, 1], 'anchor_day': 1, 'price': 7363}, [7363, '2023-04-01']), ('normal control', {'trial_end': [2025, 4, 29], 'anchor_day': 15, 'price': 2900}, [1547, '2025-05-15'])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
import calendar
N = 1
observations = []
def solve(x):
    t = datetime.date(*x['trial_end'])
    a = x['anchor_day']
    if t.day == a:
        ny, nm = (t.year + 1, 1) if t.month == 12 else (t.year, t.month + 1)
        return [x['price'], datetime.date(ny, nm, a).isoformat()]
    if t.day < a:
        nxt = datetime.date(t.year, t.month, a)
        py, pm = (t.year - 1, 12) if t.month == 1 else (t.year, t.month - 1)
        prev = datetime.date(py, pm, a)
    else:
        ey, em = (t.year + 1, 1) if t.month == 12 else (t.year, t.month + 1)
        nxt = datetime.date(ey, em, a)
        prev = datetime.date(t.year, t.month, a)
    days = (nxt - t).days
    cycle = (datetime.date(t.year + t.month // 12, t.month % 12 + 1, 1) - datetime.date(t.year, t.month, 1)).days
    return [(x['price'] * days * 2 + cycle) // (2 * cycle), nxt.isoformat()]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'trial_end': [2024, 4, 27], 'anchor_day': 28, 'price': 999}, [32, '2024-04-28']), ('regression', {'trial_end': [2024, 4, 1], 'anchor_day': 28, 'price': 78891}, [68712, '2024-04-28']), ('partial-repair probe', {'trial_end': [2024, 12, 16], 'anchor_day': 28, 'price': 2900}, [1160, '2024-12-28']), ('partial-repair probe', {'trial_end': [2025, 2, 6], 'anchor_day': 15, 'price': 2900}, [842, '2025-02-15']), ('normal control', {'trial_end': [2023, 4, 14], 'anchor_day': 1, 'price': 999}, [566, '2023-05-01']), ('normal control', {'trial_end': [2023, 6, 15], 'anchor_day': 15, 'price': 999}, [999, '2023-07-15']), ('normal control', {'trial_end': [2025, 3, 15], 'anchor_day': 15, 'price': 2900}, [2900, '2025-04-15']), ('normal control', {'trial_end': [2024, 2, 8], 'anchor_day': 8, 'price': 999}, [999, '2024-03-08'])], [('regression', {'trial_end': [2024, 4, 1], 'anchor_day': 28, 'price': 78891}, [68712, '2024-04-28']), ('regression', {'trial_end': [2024, 12, 25], 'anchor_day': 1, 'price': 12600}, [2845, '2025-01-01']), ('partial-repair probe', {'trial_end': [2025, 2, 6], 'anchor_day': 15, 'price': 2900}, [842, '2025-02-15']), ('partial-repair probe', {'trial_end': [2024, 6, 4], 'anchor_day': 28, 'price': 999}, [773, '2024-06-28']), ('normal control', {'trial_end': [2024, 6, 25], 'anchor_day': 1, 'price': 2900}, [580, '2024-07-01']), ('normal control', {'trial_end': [2023, 4, 30], 'anchor_day': 15, 'price': 44760}, [22380, '2023-05-15']), ('normal control', {'trial_end': [2024, 6, 14], 'anchor_day': 1, 'price': 999}, [566, '2024-07-01']), ('normal control', {'trial_end': [2024, 7, 15], 'anchor_day': 15, 'price': 999}, [999, '2024-08-15'])], [('regression', {'trial_end': [2025, 2, 6], 'anchor_day': 15, 'price': 2900}, [842, '2025-02-15']), ('regression', {'trial_end': [2024, 12, 25], 'anchor_day': 1, 'price': 12600}, [2845, '2025-01-01']), ('partial-repair probe', {'trial_end': [2024, 6, 4], 'anchor_day': 28, 'price': 999}, [773, '2024-06-28']), ('partial-repair probe', {'trial_end': [2024, 4, 10], 'anchor_day': 15, 'price': 2900}, [468, '2024-04-15']), ('normal control', {'trial_end': [2023, 3, 26], 'anchor_day': 26, 'price': 2900}, [2900, '2023-04-26']), ('normal control', {'trial_end': [2023, 5, 22], 'anchor_day': 22, 'price': 47810}, [47810, '2023-06-22']), ('normal control', {'trial_end': [2025, 6, 10], 'anchor_day': 10, 'price': 999}, [999, '2025-07-10']), ('normal control', {'trial_end': [2023, 12, 2], 'anchor_day': 2, 'price': 999}, [999, '2024-01-02'])], [('regression', {'trial_end': [2024, 6, 4], 'anchor_day': 28, 'price': 999}, [773, '2024-06-28']), ('regression', {'trial_end': [2025, 2, 6], 'anchor_day': 15, 'price': 2900}, [842, '2025-02-15']), ('partial-repair probe', {'trial_end': [2023, 10, 3], 'anchor_day': 16, 'price': 999}, [433, '2023-10-16']), ('partial-repair probe', {'trial_end': [2023, 6, 18], 'anchor_day': 28, 'price': 2900}, [935, '2023-06-28']), ('normal control', {'trial_end': [2023, 5, 29], 'anchor_day': 29, 'price': 15548}, [15548, '2023-06-29']), ('normal control', {'trial_end': [2024, 6, 15], 'anchor_day': 15, 'price': 8594}, [8594, '2024-07-15']), ('normal control', {'trial_end': [2023, 4, 17], 'anchor_day': 1, 'price': 2900}, [1353, '2023-05-01']), ('normal control', {'trial_end': [2023, 4, 6], 'anchor_day': 6, 'price': 999}, [999, '2023-05-06'])], [('regression', {'trial_end': [2024, 4, 10], 'anchor_day': 15, 'price': 2900}, [468, '2024-04-15']), ('regression', {'trial_end': [2023, 12, 16], 'anchor_day': 15, 'price': 2900}, [2806, '2024-01-15']), ('partial-repair probe', {'trial_end': [2025, 3, 22], 'anchor_day': 28, 'price': 58121}, [12455, '2025-03-28']), ('partial-repair probe', {'trial_end': [2024, 3, 15], 'anchor_day': 28, 'price': 999}, [448, '2024-03-28']), ('normal control', {'trial_end': [2023, 11, 28], 'anchor_day': 28, 'price': 2900}, [2900, '2023-12-28']), ('normal control', {'trial_end': [2024, 4, 11], 'anchor_day': 1, 'price': 999}, [666, '2024-05-01']), ('normal control', {'trial_end': [2023, 3, 1], 'anchor_day': 1, 'price': 7363}, [7363, '2023-04-01']), ('normal control', {'trial_end': [2025, 4, 29], 'anchor_day': 15, 'price': 2900}, [1547, '2025-05-15'])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Stub invoices after a trial exceed the monthly price when the stub spans a 31-day cycle.

Input {trial_end date, anchor_day 1..28, price}. If trial_end.day equals anchor_day, charge the full price and the next anchor is one month later. Otherwise charge price*days/cycle half-up, where days runs from trial_end to the next anchor date strictly after it and cycle is the length of the anchor-to-anchor month containing trial_end. Return [amount, next anchor ISO].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
import calendar
N = 1
observations = []
def solve(x):
    t = datetime.date(*x['trial_end'])
    a = x['anchor_day']
    if t.day == a:
        ny, nm = (t.year + 1, 1) if t.month == 12 else (t.year, t.month + 1)
        return [x['price'], datetime.date(ny, nm, a).isoformat()]
    if t.day < a:
        nxt = datetime.date(t.year, t.month, a)
        py, pm = (t.year - 1, 12) if t.month == 1 else (t.year, t.month - 1)
        prev = nxt - datetime.timedelta(days=30)
    else:
        ey, em = (t.year + 1, 1) if t.month == 12 else (t.year, t.month + 1)
        nxt = datetime.date(ey, em, a)
        prev = datetime.date(t.year, t.month, a)
    days = (nxt - t).days
    cycle = (nxt - prev).days
    return [(x['price'] * days * 2 + cycle) // (2 * cycle), nxt.isoformat()]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'trial_end': [2024, 4, 27], 'anchor_day': 28, 'price': 999}, [32, '2024-04-28']), ('regression', {'trial_end': [2024, 4, 1], 'anchor_day': 28, 'price': 78891}, [68712, '2024-04-28']), ('partial-repair probe', {'trial_end': [2024, 12, 16], 'anchor_day': 28, 'price': 2900}, [1160, '2024-12-28']), ('partial-repair probe', {'trial_end': [2025, 2, 6], 'anchor_day': 15, 'price': 2900}, [842, '2025-02-15']), ('normal control', {'trial_end': [2024, 12, 25], 'anchor_day': 1, 'price': 12600}, [2845, '2025-01-01']), ('normal control', {'trial_end': [2023, 4, 14], 'anchor_day': 1, 'price': 999}, [566, '2023-05-01']), ('normal control', {'trial_end': [2023, 6, 15], 'anchor_day': 15, 'price': 999}, [999, '2023-07-15']), ('normal control', {'trial_end': [2023, 12, 16], 'anchor_day': 15, 'price': 2900}, [2806, '2024-01-15'])], [('regression', {'trial_end': [2024, 4, 1], 'anchor_day': 28, 'price': 78891}, [68712, '2024-04-28']), ('regression', {'trial_end': [2025, 2, 6], 'anchor_day': 15, 'price': 2900}, [842, '2025-02-15']), ('partial-repair probe', {'trial_end': [2024, 6, 4], 'anchor_day': 28, 'price': 999}, [773, '2024-06-28']), ('partial-repair probe', {'trial_end': [2024, 4, 10], 'anchor_day': 15, 'price': 2900}, [468, '2024-04-15']), ('normal control', {'trial_end': [2025, 3, 15], 'anchor_day': 15, 'price': 2900}, [2900, '2025-04-15']), ('normal control', {'trial_end': [2023, 12, 15], 'anchor_day': 1, 'price': 47732}, [26176, '2024-01-01']), ('normal control', {'trial_end': [2024, 2, 8], 'anchor_day': 8, 'price': 999}, [999, '2024-03-08']), ('normal control', {'trial_end': [2024, 6, 25], 'anchor_day': 1, 'price': 2900}, [580, '2024-07-01'])], [('regression', {'trial_end': [2025, 2, 6], 'anchor_day': 15, 'price': 2900}, [842, '2025-02-15']), ('regression', {'trial_end': [2024, 6, 4], 'anchor_day': 28, 'price': 999}, [773, '2024-06-28']), ('partial-repair probe', {'trial_end': [2024, 4, 10], 'anchor_day': 15, 'price': 2900}, [468, '2024-04-15']), ('partial-repair probe', {'trial_end': [2023, 10, 3], 'anchor_day': 16, 'price': 999}, [433, '2023-10-16']), ('normal control', {'trial_end': [2023, 12, 26], 'anchor_day': 21, 'price': 999}, [838, '2024-01-21']), ('normal control', {'trial_end': [2023, 5, 26], 'anchor_day': 1, 'price': 62316}, [12061, '2023-06-01']), ('normal control', {'trial_end': [2023, 4, 30], 'anchor_day': 15, 'price': 44760}, [22380, '2023-05-15']), ('normal control', {'trial_end': [2025, 5, 3], 'anchor_day': 1, 'price': 2900}, [2713, '2025-06-01'])], [('regression', {'trial_end': [2024, 6, 4], 'anchor_day': 28, 'price': 999}, [773, '2024-06-28']), ('regression', {'trial_end': [2024, 4, 10], 'anchor_day': 15, 'price': 2900}, [468, '2024-04-15']), ('partial-repair probe', {'trial_end': [2023, 10, 3], 'anchor_day': 16, 'price': 999}, [433, '2023-10-16']), ('partial-repair probe', {'trial_end': [2023, 6, 18], 'anchor_day': 28, 'price': 2900}, [935, '2023-06-28']), ('normal control', {'trial_end': [2024, 6, 14], 'anchor_day': 1, 'price': 999}, [566, '2024-07-01']), ('normal control', {'trial_end': [2023, 5, 23], 'anchor_day': 15, 'price': 2900}, [2152, '2023-06-15']), ('normal control', {'trial_end': [2023, 5, 31], 'anchor_day': 4, 'price': 999}, [129, '2023-06-04']), ('normal control', {'trial_end': [2023, 3, 16], 'anchor_day': 15, 'price': 9250}, [8952, '2023-04-15'])], [('regression', {'trial_end': [2024, 4, 10], 'anchor_day': 15, 'price': 2900}, [468, '2024-04-15']), ('regression', {'trial_end': [2023, 6, 18], 'anchor_day': 28, 'price': 2900}, [935, '2023-06-28']), ('partial-repair probe', {'trial_end': [2025, 3, 22], 'anchor_day': 28, 'price': 58121}, [12455, '2025-03-28']), ('partial-repair probe', {'trial_end': [2024, 3, 15], 'anchor_day': 28, 'price': 999}, [448, '2024-03-28']), ('normal control', {'trial_end': [2025, 2, 28], 'anchor_day': 1, 'price': 999}, [36, '2025-03-01']), ('normal control', {'trial_end': [2023, 8, 18], 'anchor_day': 1, 'price': 2900}, [1310, '2023-09-01']), ('normal control', {'trial_end': [2025, 1, 4], 'anchor_day': 1, 'price': 39775}, [35926, '2025-02-01']), ('normal control', {'trial_end': [2024, 7, 15], 'anchor_day': 15, 'price': 999}, [999, '2024-08-15'])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
import calendar
N = 1
observations = []
def solve(x):
    t = datetime.date(*x['trial_end'])
    a = x['anchor_day']
    if t.day == a:
        ny, nm = (t.year + 1, 1) if t.month == 12 else (t.year, t.month + 1)
        return [x['price'], datetime.date(ny, nm, a).isoformat()]
    if t.day < a:
        nxt = datetime.date(t.year, t.month, a)
        py, pm = (t.year - 1, 12) if t.month == 1 else (t.year, t.month - 1)
        prev = datetime.date(t.year, t.month, 1)
    else:
        ey, em = (t.year + 1, 1) if t.month == 12 else (t.year, t.month + 1)
        nxt = datetime.date(ey, em, a)
        prev = datetime.date(t.year, t.month, a)
    days = (nxt - t).days
    cycle = (nxt - prev).days
    return [(x['price'] * days * 2 + cycle) // (2 * cycle), nxt.isoformat()]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'trial_end': [2024, 4, 27], 'anchor_day': 28, 'price': 999}, [32, '2024-04-28']), ('regression', {'trial_end': [2024, 4, 1], 'anchor_day': 28, 'price': 78891}, [68712, '2024-04-28']), ('partial-repair probe', {'trial_end': [2024, 12, 16], 'anchor_day': 28, 'price': 2900}, [1160, '2024-12-28']), ('partial-repair probe', {'trial_end': [2025, 2, 6], 'anchor_day': 15, 'price': 2900}, [842, '2025-02-15']), ('normal control', {'trial_end': [2024, 12, 25], 'anchor_day': 1, 'price': 12600}, [2845, '2025-01-01']), ('normal control', {'trial_end': [2023, 4, 14], 'anchor_day': 1, 'price': 999}, [566, '2023-05-01']), ('normal control', {'trial_end': [2023, 6, 15], 'anchor_day': 15, 'price': 999}, [999, '2023-07-15']), ('normal control', {'trial_end': [2023, 12, 16], 'anchor_day': 15, 'price': 2900}, [2806, '2024-01-15'])], [('regression', {'trial_end': [2024, 4, 1], 'anchor_day': 28, 'price': 78891}, [68712, '2024-04-28']), ('regression', {'trial_end': [2025, 2, 6], 'anchor_day': 15, 'price': 2900}, [842, '2025-02-15']), ('partial-repair probe', {'trial_end': [2024, 6, 4], 'anchor_day': 28, 'price': 999}, [773, '2024-06-28']), ('partial-repair probe', {'trial_end': [2024, 4, 10], 'anchor_day': 15, 'price': 2900}, [468, '2024-04-15']), ('normal control', {'trial_end': [2025, 3, 15], 'anchor_day': 15, 'price': 2900}, [2900, '2025-04-15']), ('normal control', {'trial_end': [2023, 12, 15], 'anchor_day': 1, 'price': 47732}, [26176, '2024-01-01']), ('normal control', {'trial_end': [2024, 2, 8], 'anchor_day': 8, 'price': 999}, [999, '2024-03-08']), ('normal control', {'trial_end': [2024, 6, 25], 'anchor_day': 1, 'price': 2900}, [580, '2024-07-01'])], [('regression', {'trial_end': [2025, 2, 6], 'anchor_day': 15, 'price': 2900}, [842, '2025-02-15']), ('regression', {'trial_end': [2024, 6, 4], 'anchor_day': 28, 'price': 999}, [773, '2024-06-28']), ('partial-repair probe', {'trial_end': [2024, 4, 10], 'anchor_day': 15, 'price': 2900}, [468, '2024-04-15']), ('partial-repair probe', {'trial_end': [2023, 10, 3], 'anchor_day': 16, 'price': 999}, [433, '2023-10-16']), ('normal control', {'trial_end': [2023, 12, 26], 'anchor_day': 21, 'price': 999}, [838, '2024-01-21']), ('normal control', {'trial_end': [2023, 5, 26], 'anchor_day': 1, 'price': 62316}, [12061, '2023-06-01']), ('normal control', {'trial_end': [2023, 4, 30], 'anchor_day': 15, 'price': 44760}, [22380, '2023-05-15']), ('normal control', {'trial_end': [2025, 5, 3], 'anchor_day': 1, 'price': 2900}, [2713, '2025-06-01'])], [('regression', {'trial_end': [2024, 6, 4], 'anchor_day': 28, 'price': 999}, [773, '2024-06-28']), ('regression', {'trial_end': [2024, 4, 10], 'anchor_day': 15, 'price': 2900}, [468, '2024-04-15']), ('partial-repair probe', {'trial_end': [2023, 10, 3], 'anchor_day': 16, 'price': 999}, [433, '2023-10-16']), ('partial-repair probe', {'trial_end': [2023, 6, 18], 'anchor_day': 28, 'price': 2900}, [935, '2023-06-28']), ('normal control', {'trial_end': [2024, 6, 14], 'anchor_day': 1, 'price': 999}, [566, '2024-07-01']), ('normal control', {'trial_end': [2023, 5, 23], 'anchor_day': 15, 'price': 2900}, [2152, '2023-06-15']), ('normal control', {'trial_end': [2023, 5, 31], 'anchor_day': 4, 'price': 999}, [129, '2023-06-04']), ('normal control', {'trial_end': [2023, 3, 16], 'anchor_day': 15, 'price': 9250}, [8952, '2023-04-15'])], [('regression', {'trial_end': [2024, 4, 10], 'anchor_day': 15, 'price': 2900}, [468, '2024-04-15']), ('regression', {'trial_end': [2023, 6, 18], 'anchor_day': 28, 'price': 2900}, [935, '2023-06-28']), ('partial-repair probe', {'trial_end': [2025, 3, 22], 'anchor_day': 28, 'price': 58121}, [12455, '2025-03-28']), ('partial-repair probe', {'trial_end': [2024, 3, 15], 'anchor_day': 28, 'price': 999}, [448, '2024-03-28']), ('normal control', {'trial_end': [2025, 2, 28], 'anchor_day': 1, 'price': 999}, [36, '2025-03-01']), ('normal control', {'trial_end': [2023, 8, 18], 'anchor_day': 1, 'price': 2900}, [1310, '2023-09-01']), ('normal control', {'trial_end': [2025, 1, 4], 'anchor_day': 1, 'price': 39775}, [35926, '2025-02-01']), ('normal control', {'trial_end': [2024, 7, 15], 'anchor_day': 15, 'price': 999}, [999, '2024-08-15'])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Stub invoices for trials ending early in the month use a 30-day cycle regardless of the real anchor cycle.

Input {trial_end date, anchor_day 1..28, price}. If trial_end.day equals anchor_day, charge the full price and the next anchor is one month later. Otherwise charge price*days/cycle half-up, where days runs from trial_end to the next anchor date strictly after it and cycle is the length of the anchor-to-anchor month containing trial_end. Return [amount, next anchor ISO].

split: open-access