broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime as dt
import calendar
N = 1
observations = []
def solve(year):
    def nth(month, wd, n):
        first = dt.date(year, month, 1)
        return first + dt.timedelta(days=(wd - first.weekday()) % 7 + 7 * (n - 1))
    def last(month, wd):
        lastd = dt.date(year, month, calendar.monthrange(year, month)[1])
        return lastd - dt.timedelta(days=(lastd.weekday() - wd) % 7)
    def observed(d):
        return d - dt.timedelta(days=1) if d.weekday() == 5 else d + dt.timedelta(days=1) if d.weekday() == 6 else d
    thanks = nth(11, 3, 4)
    rows = [['new-year', observed(dt.date(year, 1, 1))], ['mlk', nth(1, 0, 3)], ['memorial', last(5, 0)],
            ['juneteenth', observed(dt.date(year, 6, 19))], ['independence', observed(dt.date(year, 7, 4))],
            ['labor', nth(9, 0, 1)], ['thanksgiving', thanks], ['day-after-thanksgiving', nth(11, 4, 4)],
            ['christmas', observed(dt.date(year, 12, 25))]]
    nxt = dt.date(year + 1, 1, 1)
    if nxt.weekday() == 5:
        rows.append(['new-year-observed', nxt - dt.timedelta(days=1)])
    rows = [r for r in rows if r[1].year == year]
    return [[name, d.isoformat()] for name, d in sorted(rows, key=lambda r: r[1])]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: 2022 new year on saturday',
   [2022],
   [['mlk', '2022-01-17'],
    ['memorial', '2022-05-30'],
    ['juneteenth', '2022-06-20'],
    ['independence', '2022-07-04'],
    ['labor', '2022-09-05'],
    ['thanksgiving', '2022-11-24'],
    ['day-after-thanksgiving', '2022-11-25'],
    ['christmas', '2022-12-26']]),
  ('2021 next new year saturday',
   [2021],
   [['new-year', '2021-01-01'],
    ['mlk', '2021-01-18'],
    ['memorial', '2021-05-31'],
    ['juneteenth', '2021-06-18'],
    ['independence', '2021-07-05'],
    ['labor', '2021-09-06'],
    ['thanksgiving', '2021-11-25'],
    ['day-after-thanksgiving', '2021-11-26'],
    ['christmas', '2021-12-24'],
    ['new-year-observed', '2021-12-31']]),
  ('2024 leap',
   [2024],
   [['new-year', '2024-01-01'],
    ['mlk', '2024-01-15'],
    ['memorial', '2024-05-27'],
    ['juneteenth', '2024-06-19'],
    ['independence', '2024-07-04'],
    ['labor', '2024-09-02'],
    ['thanksgiving', '2024-11-28'],
    ['day-after-thanksgiving', '2024-11-29'],
    ['christmas', '2024-12-25']]),
  ('2019 november starts friday',
   [2019],
   [['new-year', '2019-01-01'],
    ['mlk', '2019-01-21'],
    ['memorial', '2019-05-27'],
    ['juneteenth', '2019-06-19'],
    ['independence', '2019-07-04'],
    ['labor', '2019-09-02'],
    ['thanksgiving', '2019-11-28'],
    ['day-after-thanksgiving', '2019-11-29'],
    ['christmas', '2019-12-25']]),
  ('2020 july 4 saturday',
   [2020],
   [['new-year', '2020-01-01'],
    ['mlk', '2020-01-20'],
    ['memorial', '2020-05-25'],
    ['juneteenth', '2020-06-19'],
    ['independence', '2020-07-03'],
    ['labor', '2020-09-07'],
    ['thanksgiving', '2020-11-26'],
    ['day-after-thanksgiving', '2020-11-27'],
    ['christmas', '2020-12-25']]),
  ('2016 next new year sunday',
   [2016],
   [['new-year', '2016-01-01'],
    ['mlk', '2016-01-18'],
    ['memorial', '2016-05-30'],
    ['juneteenth', '2016-06-20'],
    ['independence', '2016-07-04'],
    ['labor', '2016-09-05'],
    ['thanksgiving', '2016-11-24'],
    ['day-after-thanksgiving', '2016-11-25'],
    ['christmas', '2016-12-26']]),
  ('2027 five mondays may',
   [2027],
   [['new-year', '2027-01-01'],
    ['mlk', '2027-01-18'],
    ['memorial', '2027-05-31'],
    ['juneteenth', '2027-06-18'],
    ['independence', '2027-07-05'],
    ['labor', '2027-09-06'],
    ['thanksgiving', '2027-11-25'],
    ['day-after-thanksgiving', '2027-11-26'],
    ['christmas', '2027-12-24'],
    ['new-year-observed', '2027-12-31']])],
 [('2024 leap',
   [2024],
   [['new-year', '2024-01-01'],
    ['mlk', '2024-01-15'],
    ['memorial', '2024-05-27'],
    ['juneteenth', '2024-06-19'],
    ['independence', '2024-07-04'],
    ['labor', '2024-09-02'],
    ['thanksgiving', '2024-11-28'],
    ['day-after-thanksgiving', '2024-11-29'],
    ['christmas', '2024-12-25']]),
  ('2019 november starts friday',
   [2019],
   [['new-year', '2019-01-01'],
    ['mlk', '2019-01-21'],
    ['memorial', '2019-05-27'],
    ['juneteenth', '2019-06-19'],
    ['independence', '2019-07-04'],
    ['labor', '2019-09-02'],
    ['thanksgiving', '2019-11-28'],
    ['day-after-thanksgiving', '2019-11-29'],
    ['christmas', '2019-12-25']]),
  ('2020 july 4 saturday',
   [2020],
   [['new-year', '2020-01-01'],
    ['mlk', '2020-01-20'],
    ['memorial', '2020-05-25'],
    ['juneteenth', '2020-06-19'],
    ['independence', '2020-07-03'],
    ['labor', '2020-09-07'],
    ['thanksgiving', '2020-11-26'],
    ['day-after-thanksgiving', '2020-11-27'],
    ['christmas', '2020-12-25']]),
  ('2016 next new year sunday',
   [2016],
   [['new-year', '2016-01-01'],
    ['mlk', '2016-01-18'],
    ['memorial', '2016-05-30'],
    ['juneteenth', '2016-06-20'],
    ['independence', '2016-07-04'],
    ['labor', '2016-09-05'],
    ['thanksgiving', '2016-11-24'],
    ['day-after-thanksgiving', '2016-11-25'],
    ['christmas', '2016-12-26']]),
  ('2027 five mondays may',
   [2027],
   [['new-year', '2027-01-01'],
    ['mlk', '2027-01-18'],
    ['memorial', '2027-05-31'],
    ['juneteenth', '2027-06-18'],
    ['independence', '2027-07-05'],
    ['labor', '2027-09-06'],
    ['thanksgiving', '2027-11-25'],
    ['day-after-thanksgiving', '2027-11-26'],
    ['christmas', '2027-12-24'],
    ['new-year-observed', '2027-12-31']]),
  ('2023',
   [2023],
   [['new-year', '2023-01-02'],
    ['mlk', '2023-01-16'],
    ['memorial', '2023-05-29'],
    ['juneteenth', '2023-06-19'],
    ['independence', '2023-07-04'],
    ['labor', '2023-09-04'],
    ['thanksgiving', '2023-11-23'],
    ['day-after-thanksgiving', '2023-11-24'],
    ['christmas', '2023-12-25']]),
  ('2030',
   [2030],
   [['new-year', '2030-01-01'],
    ['mlk', '2030-01-21'],
    ['memorial', '2030-05-27'],
    ['juneteenth', '2030-06-19'],
    ['independence', '2030-07-04'],
    ['labor', '2030-09-02'],
    ['thanksgiving', '2030-11-28'],
    ['day-after-thanksgiving', '2030-11-29'],
    ['christmas', '2030-12-25']])],
 [('2020 july 4 saturday',
   [2020],
   [['new-year', '2020-01-01'],
    ['mlk', '2020-01-20'],
    ['memorial', '2020-05-25'],
    ['juneteenth', '2020-06-19'],
    ['independence', '2020-07-03'],
    ['labor', '2020-09-07'],
    ['thanksgiving', '2020-11-26'],
    ['day-after-thanksgiving', '2020-11-27'],
    ['christmas', '2020-12-25']]),
  ('2016 next new year sunday',
   [2016],
   [['new-year', '2016-01-01'],
    ['mlk', '2016-01-18'],
    ['memorial', '2016-05-30'],
    ['juneteenth', '2016-06-20'],
    ['independence', '2016-07-04'],
    ['labor', '2016-09-05'],
    ['thanksgiving', '2016-11-24'],
    ['day-after-thanksgiving', '2016-11-25'],
    ['christmas', '2016-12-26']]),
  ('2027 five mondays may',
   [2027],
   [['new-year', '2027-01-01'],
    ['mlk', '2027-01-18'],
    ['memorial', '2027-05-31'],
    ['juneteenth', '2027-06-18'],
    ['independence', '2027-07-05'],
    ['labor', '2027-09-06'],
    ['thanksgiving', '2027-11-25'],
    ['day-after-thanksgiving', '2027-11-26'],
    ['christmas', '2027-12-24'],
    ['new-year-observed', '2027-12-31']]),
  ('2023',
   [2023],
   [['new-year', '2023-01-02'],
    ['mlk', '2023-01-16'],
    ['memorial', '2023-05-29'],
    ['juneteenth', '2023-06-19'],
    ['independence', '2023-07-04'],
    ['labor', '2023-09-04'],
    ['thanksgiving', '2023-11-23'],
    ['day-after-thanksgiving', '2023-11-24'],
    ['christmas', '2023-12-25']]),
  ('2030',
   [2030],
   [['new-year', '2030-01-01'],
    ['mlk', '2030-01-21'],
    ['memorial', '2030-05-27'],
    ['juneteenth', '2030-06-19'],
    ['independence', '2030-07-04'],
    ['labor', '2030-09-02'],
    ['thanksgiving', '2030-11-28'],
    ['day-after-thanksgiving', '2030-11-29'],
    ['christmas', '2030-12-25']]),
  ('2032 leap',
   [2032],
   [['new-year', '2032-01-01'],
    ['mlk', '2032-01-19'],
    ['memorial', '2032-05-31'],
    ['juneteenth', '2032-06-18'],
    ['independence', '2032-07-05'],
    ['labor', '2032-09-06'],
    ['thanksgiving', '2032-11-25'],
    ['day-after-thanksgiving', '2032-11-26'],
    ['christmas', '2032-12-24'],
    ['new-year-observed', '2032-12-31']]),
  ('2033 new year saturday',
   [2033],
   [['mlk', '2033-01-17'],
    ['memorial', '2033-05-30'],
    ['juneteenth', '2033-06-20'],
    ['independence', '2033-07-04'],
    ['labor', '2033-09-05'],
    ['thanksgiving', '2033-11-24'],
    ['day-after-thanksgiving', '2033-11-25'],
    ['christmas', '2033-12-26']])],
 [('2027 five mondays may',
   [2027],
   [['new-year', '2027-01-01'],
    ['mlk', '2027-01-18'],
    ['memorial', '2027-05-31'],
    ['juneteenth', '2027-06-18'],
    ['independence', '2027-07-05'],
    ['labor', '2027-09-06'],
    ['thanksgiving', '2027-11-25'],
    ['day-after-thanksgiving', '2027-11-26'],
    ['christmas', '2027-12-24'],
    ['new-year-observed', '2027-12-31']]),
  ('2023',
   [2023],
   [['new-year', '2023-01-02'],
    ['mlk', '2023-01-16'],
    ['memorial', '2023-05-29'],
    ['juneteenth', '2023-06-19'],
    ['independence', '2023-07-04'],
    ['labor', '2023-09-04'],
    ['thanksgiving', '2023-11-23'],
    ['day-after-thanksgiving', '2023-11-24'],
    ['christmas', '2023-12-25']]),
  ('2030',
   [2030],
   [['new-year', '2030-01-01'],
    ['mlk', '2030-01-21'],
    ['memorial', '2030-05-27'],
    ['juneteenth', '2030-06-19'],
    ['independence', '2030-07-04'],
    ['labor', '2030-09-02'],
    ['thanksgiving', '2030-11-28'],
    ['day-after-thanksgiving', '2030-11-29'],
    ['christmas', '2030-12-25']]),
  ('2032 leap',
   [2032],
   [['new-year', '2032-01-01'],
    ['mlk', '2032-01-19'],
    ['memorial', '2032-05-31'],
    ['juneteenth', '2032-06-18'],
    ['independence', '2032-07-05'],
    ['labor', '2032-09-06'],
    ['thanksgiving', '2032-11-25'],
    ['day-after-thanksgiving', '2032-11-26'],
    ['christmas', '2032-12-24'],
    ['new-year-observed', '2032-12-31']]),
  ('2033 new year saturday',
   [2033],
   [['mlk', '2033-01-17'],
    ['memorial', '2033-05-30'],
    ['juneteenth', '2033-06-20'],
    ['independence', '2033-07-04'],
    ['labor', '2033-09-05'],
    ['thanksgiving', '2033-11-24'],
    ['day-after-thanksgiving', '2033-11-25'],
    ['christmas', '2033-12-26']]),
  ('regression: 2022 new year on saturday',
   [2022],
   [['mlk', '2022-01-17'],
    ['memorial', '2022-05-30'],
    ['juneteenth', '2022-06-20'],
    ['independence', '2022-07-04'],
    ['labor', '2022-09-05'],
    ['thanksgiving', '2022-11-24'],
    ['day-after-thanksgiving', '2022-11-25'],
    ['christmas', '2022-12-26']]),
  ('2021 next new year saturday',
   [2021],
   [['new-year', '2021-01-01'],
    ['mlk', '2021-01-18'],
    ['memorial', '2021-05-31'],
    ['juneteenth', '2021-06-18'],
    ['independence', '2021-07-05'],
    ['labor', '2021-09-06'],
    ['thanksgiving', '2021-11-25'],
    ['day-after-thanksgiving', '2021-11-26'],
    ['christmas', '2021-12-24'],
    ['new-year-observed', '2021-12-31']])],
 [('2030',
   [2030],
   [['new-year', '2030-01-01'],
    ['mlk', '2030-01-21'],
    ['memorial', '2030-05-27'],
    ['juneteenth', '2030-06-19'],
    ['independence', '2030-07-04'],
    ['labor', '2030-09-02'],
    ['thanksgiving', '2030-11-28'],
    ['day-after-thanksgiving', '2030-11-29'],
    ['christmas', '2030-12-25']]),
  ('2032 leap',
   [2032],
   [['new-year', '2032-01-01'],
    ['mlk', '2032-01-19'],
    ['memorial', '2032-05-31'],
    ['juneteenth', '2032-06-18'],
    ['independence', '2032-07-05'],
    ['labor', '2032-09-06'],
    ['thanksgiving', '2032-11-25'],
    ['day-after-thanksgiving', '2032-11-26'],
    ['christmas', '2032-12-24'],
    ['new-year-observed', '2032-12-31']]),
  ('2033 new year saturday',
   [2033],
   [['mlk', '2033-01-17'],
    ['memorial', '2033-05-30'],
    ['juneteenth', '2033-06-20'],
    ['independence', '2033-07-04'],
    ['labor', '2033-09-05'],
    ['thanksgiving', '2033-11-24'],
    ['day-after-thanksgiving', '2033-11-25'],
    ['christmas', '2033-12-26']]),
  ('regression: 2022 new year on saturday',
   [2022],
   [['mlk', '2022-01-17'],
    ['memorial', '2022-05-30'],
    ['juneteenth', '2022-06-20'],
    ['independence', '2022-07-04'],
    ['labor', '2022-09-05'],
    ['thanksgiving', '2022-11-24'],
    ['day-after-thanksgiving', '2022-11-25'],
    ['christmas', '2022-12-26']]),
  ('2021 next new year saturday',
   [2021],
   [['new-year', '2021-01-01'],
    ['mlk', '2021-01-18'],
    ['memorial', '2021-05-31'],
    ['juneteenth', '2021-06-18'],
    ['independence', '2021-07-05'],
    ['labor', '2021-09-06'],
    ['thanksgiving', '2021-11-25'],
    ['day-after-thanksgiving', '2021-11-26'],
    ['christmas', '2021-12-24'],
    ['new-year-observed', '2021-12-31']]),
  ('2024 leap',
   [2024],
   [['new-year', '2024-01-01'],
    ['mlk', '2024-01-15'],
    ['memorial', '2024-05-27'],
    ['juneteenth', '2024-06-19'],
    ['independence', '2024-07-04'],
    ['labor', '2024-09-02'],
    ['thanksgiving', '2024-11-28'],
    ['day-after-thanksgiving', '2024-11-29'],
    ['christmas', '2024-12-25']]),
  ('2019 november starts friday',
   [2019],
   [['new-year', '2019-01-01'],
    ['mlk', '2019-01-21'],
    ['memorial', '2019-05-27'],
    ['juneteenth', '2019-06-19'],
    ['independence', '2019-07-04'],
    ['labor', '2019-09-02'],
    ['thanksgiving', '2019-11-28'],
    ['day-after-thanksgiving', '2019-11-29'],
    ['christmas', '2019-12-25']])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime as dt
import calendar
N = 1
observations = []
def solve(year):
    def nth(month, wd, n):
        first = dt.date(year, month, 1)
        return first + dt.timedelta(days=(wd - first.weekday()) % 7 + 7 * (n - 1))
    def last(month, wd):
        lastd = dt.date(year, month, calendar.monthrange(year, month)[1])
        return lastd - dt.timedelta(days=(lastd.weekday() - wd) % 7)
    def observed(d):
        return d - dt.timedelta(days=1) if d.weekday() == 5 else d + dt.timedelta(days=1) if d.weekday() == 6 else d
    thanks = nth(11, 3, 4)
    rows = [['new-year', observed(dt.date(year, 1, 1))], ['mlk', nth(1, 0, 3)], ['memorial', last(5, 0)],
            ['juneteenth', observed(dt.date(year, 6, 19))], ['independence', observed(dt.date(year, 7, 4))],
            ['labor', nth(9, 0, 1)], ['thanksgiving', thanks], ['day-after-thanksgiving', nth(11, 4, 4) if dt.date(year, 11, 1).weekday() == 4 else thanks + dt.timedelta(days=1)],
            ['christmas', observed(dt.date(year, 12, 25))]]
    nxt = dt.date(year + 1, 1, 1)
    if nxt.weekday() == 5:
        rows.append(['new-year-observed', nxt - dt.timedelta(days=1)])
    rows = [r for r in rows if r[1].year == year]
    return [[name, d.isoformat()] for name, d in sorted(rows, key=lambda r: r[1])]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: 2022 new year on saturday',
   [2022],
   [['mlk', '2022-01-17'],
    ['memorial', '2022-05-30'],
    ['juneteenth', '2022-06-20'],
    ['independence', '2022-07-04'],
    ['labor', '2022-09-05'],
    ['thanksgiving', '2022-11-24'],
    ['day-after-thanksgiving', '2022-11-25'],
    ['christmas', '2022-12-26']]),
  ('2021 next new year saturday',
   [2021],
   [['new-year', '2021-01-01'],
    ['mlk', '2021-01-18'],
    ['memorial', '2021-05-31'],
    ['juneteenth', '2021-06-18'],
    ['independence', '2021-07-05'],
    ['labor', '2021-09-06'],
    ['thanksgiving', '2021-11-25'],
    ['day-after-thanksgiving', '2021-11-26'],
    ['christmas', '2021-12-24'],
    ['new-year-observed', '2021-12-31']]),
  ('2024 leap',
   [2024],
   [['new-year', '2024-01-01'],
    ['mlk', '2024-01-15'],
    ['memorial', '2024-05-27'],
    ['juneteenth', '2024-06-19'],
    ['independence', '2024-07-04'],
    ['labor', '2024-09-02'],
    ['thanksgiving', '2024-11-28'],
    ['day-after-thanksgiving', '2024-11-29'],
    ['christmas', '2024-12-25']]),
  ('2019 november starts friday',
   [2019],
   [['new-year', '2019-01-01'],
    ['mlk', '2019-01-21'],
    ['memorial', '2019-05-27'],
    ['juneteenth', '2019-06-19'],
    ['independence', '2019-07-04'],
    ['labor', '2019-09-02'],
    ['thanksgiving', '2019-11-28'],
    ['day-after-thanksgiving', '2019-11-29'],
    ['christmas', '2019-12-25']]),
  ('2020 july 4 saturday',
   [2020],
   [['new-year', '2020-01-01'],
    ['mlk', '2020-01-20'],
    ['memorial', '2020-05-25'],
    ['juneteenth', '2020-06-19'],
    ['independence', '2020-07-03'],
    ['labor', '2020-09-07'],
    ['thanksgiving', '2020-11-26'],
    ['day-after-thanksgiving', '2020-11-27'],
    ['christmas', '2020-12-25']]),
  ('2016 next new year sunday',
   [2016],
   [['new-year', '2016-01-01'],
    ['mlk', '2016-01-18'],
    ['memorial', '2016-05-30'],
    ['juneteenth', '2016-06-20'],
    ['independence', '2016-07-04'],
    ['labor', '2016-09-05'],
    ['thanksgiving', '2016-11-24'],
    ['day-after-thanksgiving', '2016-11-25'],
    ['christmas', '2016-12-26']]),
  ('2027 five mondays may',
   [2027],
   [['new-year', '2027-01-01'],
    ['mlk', '2027-01-18'],
    ['memorial', '2027-05-31'],
    ['juneteenth', '2027-06-18'],
    ['independence', '2027-07-05'],
    ['labor', '2027-09-06'],
    ['thanksgiving', '2027-11-25'],
    ['day-after-thanksgiving', '2027-11-26'],
    ['christmas', '2027-12-24'],
    ['new-year-observed', '2027-12-31']])],
 [('2024 leap',
   [2024],
   [['new-year', '2024-01-01'],
    ['mlk', '2024-01-15'],
    ['memorial', '2024-05-27'],
    ['juneteenth', '2024-06-19'],
    ['independence', '2024-07-04'],
    ['labor', '2024-09-02'],
    ['thanksgiving', '2024-11-28'],
    ['day-after-thanksgiving', '2024-11-29'],
    ['christmas', '2024-12-25']]),
  ('2019 november starts friday',
   [2019],
   [['new-year', '2019-01-01'],
    ['mlk', '2019-01-21'],
    ['memorial', '2019-05-27'],
    ['juneteenth', '2019-06-19'],
    ['independence', '2019-07-04'],
    ['labor', '2019-09-02'],
    ['thanksgiving', '2019-11-28'],
    ['day-after-thanksgiving', '2019-11-29'],
    ['christmas', '2019-12-25']]),
  ('2020 july 4 saturday',
   [2020],
   [['new-year', '2020-01-01'],
    ['mlk', '2020-01-20'],
    ['memorial', '2020-05-25'],
    ['juneteenth', '2020-06-19'],
    ['independence', '2020-07-03'],
    ['labor', '2020-09-07'],
    ['thanksgiving', '2020-11-26'],
    ['day-after-thanksgiving', '2020-11-27'],
    ['christmas', '2020-12-25']]),
  ('2016 next new year sunday',
   [2016],
   [['new-year', '2016-01-01'],
    ['mlk', '2016-01-18'],
    ['memorial', '2016-05-30'],
    ['juneteenth', '2016-06-20'],
    ['independence', '2016-07-04'],
    ['labor', '2016-09-05'],
    ['thanksgiving', '2016-11-24'],
    ['day-after-thanksgiving', '2016-11-25'],
    ['christmas', '2016-12-26']]),
  ('2027 five mondays may',
   [2027],
   [['new-year', '2027-01-01'],
    ['mlk', '2027-01-18'],
    ['memorial', '2027-05-31'],
    ['juneteenth', '2027-06-18'],
    ['independence', '2027-07-05'],
    ['labor', '2027-09-06'],
    ['thanksgiving', '2027-11-25'],
    ['day-after-thanksgiving', '2027-11-26'],
    ['christmas', '2027-12-24'],
    ['new-year-observed', '2027-12-31']]),
  ('2023',
   [2023],
   [['new-year', '2023-01-02'],
    ['mlk', '2023-01-16'],
    ['memorial', '2023-05-29'],
    ['juneteenth', '2023-06-19'],
    ['independence', '2023-07-04'],
    ['labor', '2023-09-04'],
    ['thanksgiving', '2023-11-23'],
    ['day-after-thanksgiving', '2023-11-24'],
    ['christmas', '2023-12-25']]),
  ('2030',
   [2030],
   [['new-year', '2030-01-01'],
    ['mlk', '2030-01-21'],
    ['memorial', '2030-05-27'],
    ['juneteenth', '2030-06-19'],
    ['independence', '2030-07-04'],
    ['labor', '2030-09-02'],
    ['thanksgiving', '2030-11-28'],
    ['day-after-thanksgiving', '2030-11-29'],
    ['christmas', '2030-12-25']])],
 [('2020 july 4 saturday',
   [2020],
   [['new-year', '2020-01-01'],
    ['mlk', '2020-01-20'],
    ['memorial', '2020-05-25'],
    ['juneteenth', '2020-06-19'],
    ['independence', '2020-07-03'],
    ['labor', '2020-09-07'],
    ['thanksgiving', '2020-11-26'],
    ['day-after-thanksgiving', '2020-11-27'],
    ['christmas', '2020-12-25']]),
  ('2016 next new year sunday',
   [2016],
   [['new-year', '2016-01-01'],
    ['mlk', '2016-01-18'],
    ['memorial', '2016-05-30'],
    ['juneteenth', '2016-06-20'],
    ['independence', '2016-07-04'],
    ['labor', '2016-09-05'],
    ['thanksgiving', '2016-11-24'],
    ['day-after-thanksgiving', '2016-11-25'],
    ['christmas', '2016-12-26']]),
  ('2027 five mondays may',
   [2027],
   [['new-year', '2027-01-01'],
    ['mlk', '2027-01-18'],
    ['memorial', '2027-05-31'],
    ['juneteenth', '2027-06-18'],
    ['independence', '2027-07-05'],
    ['labor', '2027-09-06'],
    ['thanksgiving', '2027-11-25'],
    ['day-after-thanksgiving', '2027-11-26'],
    ['christmas', '2027-12-24'],
    ['new-year-observed', '2027-12-31']]),
  ('2023',
   [2023],
   [['new-year', '2023-01-02'],
    ['mlk', '2023-01-16'],
    ['memorial', '2023-05-29'],
    ['juneteenth', '2023-06-19'],
    ['independence', '2023-07-04'],
    ['labor', '2023-09-04'],
    ['thanksgiving', '2023-11-23'],
    ['day-after-thanksgiving', '2023-11-24'],
    ['christmas', '2023-12-25']]),
  ('2030',
   [2030],
   [['new-year', '2030-01-01'],
    ['mlk', '2030-01-21'],
    ['memorial', '2030-05-27'],
    ['juneteenth', '2030-06-19'],
    ['independence', '2030-07-04'],
    ['labor', '2030-09-02'],
    ['thanksgiving', '2030-11-28'],
    ['day-after-thanksgiving', '2030-11-29'],
    ['christmas', '2030-12-25']]),
  ('2032 leap',
   [2032],
   [['new-year', '2032-01-01'],
    ['mlk', '2032-01-19'],
    ['memorial', '2032-05-31'],
    ['juneteenth', '2032-06-18'],
    ['independence', '2032-07-05'],
    ['labor', '2032-09-06'],
    ['thanksgiving', '2032-11-25'],
    ['day-after-thanksgiving', '2032-11-26'],
    ['christmas', '2032-12-24'],
    ['new-year-observed', '2032-12-31']]),
  ('2033 new year saturday',
   [2033],
   [['mlk', '2033-01-17'],
    ['memorial', '2033-05-30'],
    ['juneteenth', '2033-06-20'],
    ['independence', '2033-07-04'],
    ['labor', '2033-09-05'],
    ['thanksgiving', '2033-11-24'],
    ['day-after-thanksgiving', '2033-11-25'],
    ['christmas', '2033-12-26']])],
 [('2027 five mondays may',
   [2027],
   [['new-year', '2027-01-01'],
    ['mlk', '2027-01-18'],
    ['memorial', '2027-05-31'],
    ['juneteenth', '2027-06-18'],
    ['independence', '2027-07-05'],
    ['labor', '2027-09-06'],
    ['thanksgiving', '2027-11-25'],
    ['day-after-thanksgiving', '2027-11-26'],
    ['christmas', '2027-12-24'],
    ['new-year-observed', '2027-12-31']]),
  ('2023',
   [2023],
   [['new-year', '2023-01-02'],
    ['mlk', '2023-01-16'],
    ['memorial', '2023-05-29'],
    ['juneteenth', '2023-06-19'],
    ['independence', '2023-07-04'],
    ['labor', '2023-09-04'],
    ['thanksgiving', '2023-11-23'],
    ['day-after-thanksgiving', '2023-11-24'],
    ['christmas', '2023-12-25']]),
  ('2030',
   [2030],
   [['new-year', '2030-01-01'],
    ['mlk', '2030-01-21'],
    ['memorial', '2030-05-27'],
    ['juneteenth', '2030-06-19'],
    ['independence', '2030-07-04'],
    ['labor', '2030-09-02'],
    ['thanksgiving', '2030-11-28'],
    ['day-after-thanksgiving', '2030-11-29'],
    ['christmas', '2030-12-25']]),
  ('2032 leap',
   [2032],
   [['new-year', '2032-01-01'],
    ['mlk', '2032-01-19'],
    ['memorial', '2032-05-31'],
    ['juneteenth', '2032-06-18'],
    ['independence', '2032-07-05'],
    ['labor', '2032-09-06'],
    ['thanksgiving', '2032-11-25'],
    ['day-after-thanksgiving', '2032-11-26'],
    ['christmas', '2032-12-24'],
    ['new-year-observed', '2032-12-31']]),
  ('2033 new year saturday',
   [2033],
   [['mlk', '2033-01-17'],
    ['memorial', '2033-05-30'],
    ['juneteenth', '2033-06-20'],
    ['independence', '2033-07-04'],
    ['labor', '2033-09-05'],
    ['thanksgiving', '2033-11-24'],
    ['day-after-thanksgiving', '2033-11-25'],
    ['christmas', '2033-12-26']]),
  ('regression: 2022 new year on saturday',
   [2022],
   [['mlk', '2022-01-17'],
    ['memorial', '2022-05-30'],
    ['juneteenth', '2022-06-20'],
    ['independence', '2022-07-04'],
    ['labor', '2022-09-05'],
    ['thanksgiving', '2022-11-24'],
    ['day-after-thanksgiving', '2022-11-25'],
    ['christmas', '2022-12-26']]),
  ('2021 next new year saturday',
   [2021],
   [['new-year', '2021-01-01'],
    ['mlk', '2021-01-18'],
    ['memorial', '2021-05-31'],
    ['juneteenth', '2021-06-18'],
    ['independence', '2021-07-05'],
    ['labor', '2021-09-06'],
    ['thanksgiving', '2021-11-25'],
    ['day-after-thanksgiving', '2021-11-26'],
    ['christmas', '2021-12-24'],
    ['new-year-observed', '2021-12-31']])],
 [('2030',
   [2030],
   [['new-year', '2030-01-01'],
    ['mlk', '2030-01-21'],
    ['memorial', '2030-05-27'],
    ['juneteenth', '2030-06-19'],
    ['independence', '2030-07-04'],
    ['labor', '2030-09-02'],
    ['thanksgiving', '2030-11-28'],
    ['day-after-thanksgiving', '2030-11-29'],
    ['christmas', '2030-12-25']]),
  ('2032 leap',
   [2032],
   [['new-year', '2032-01-01'],
    ['mlk', '2032-01-19'],
    ['memorial', '2032-05-31'],
    ['juneteenth', '2032-06-18'],
    ['independence', '2032-07-05'],
    ['labor', '2032-09-06'],
    ['thanksgiving', '2032-11-25'],
    ['day-after-thanksgiving', '2032-11-26'],
    ['christmas', '2032-12-24'],
    ['new-year-observed', '2032-12-31']]),
  ('2033 new year saturday',
   [2033],
   [['mlk', '2033-01-17'],
    ['memorial', '2033-05-30'],
    ['juneteenth', '2033-06-20'],
    ['independence', '2033-07-04'],
    ['labor', '2033-09-05'],
    ['thanksgiving', '2033-11-24'],
    ['day-after-thanksgiving', '2033-11-25'],
    ['christmas', '2033-12-26']]),
  ('regression: 2022 new year on saturday',
   [2022],
   [['mlk', '2022-01-17'],
    ['memorial', '2022-05-30'],
    ['juneteenth', '2022-06-20'],
    ['independence', '2022-07-04'],
    ['labor', '2022-09-05'],
    ['thanksgiving', '2022-11-24'],
    ['day-after-thanksgiving', '2022-11-25'],
    ['christmas', '2022-12-26']]),
  ('2021 next new year saturday',
   [2021],
   [['new-year', '2021-01-01'],
    ['mlk', '2021-01-18'],
    ['memorial', '2021-05-31'],
    ['juneteenth', '2021-06-18'],
    ['independence', '2021-07-05'],
    ['labor', '2021-09-06'],
    ['thanksgiving', '2021-11-25'],
    ['day-after-thanksgiving', '2021-11-26'],
    ['christmas', '2021-12-24'],
    ['new-year-observed', '2021-12-31']]),
  ('2024 leap',
   [2024],
   [['new-year', '2024-01-01'],
    ['mlk', '2024-01-15'],
    ['memorial', '2024-05-27'],
    ['juneteenth', '2024-06-19'],
    ['independence', '2024-07-04'],
    ['labor', '2024-09-02'],
    ['thanksgiving', '2024-11-28'],
    ['day-after-thanksgiving', '2024-11-29'],
    ['christmas', '2024-12-25']]),
  ('2019 november starts friday',
   [2019],
   [['new-year', '2019-01-01'],
    ['mlk', '2019-01-21'],
    ['memorial', '2019-05-27'],
    ['juneteenth', '2019-06-19'],
    ['independence', '2019-07-04'],
    ['labor', '2019-09-02'],
    ['thanksgiving', '2019-11-28'],
    ['day-after-thanksgiving', '2019-11-29'],
    ['christmas', '2019-12-25']])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
When November starts on a Friday, the day-after-Thanksgiving closure lands a week early.

Stipulated court holidays for a year: new-year (Jan 1), mlk (3rd Monday Jan), memorial (last Monday May), juneteenth (Jun 19), independence (Jul 4), labor (1st Monday Sep), thanksgiving (4th Thursday Nov), day-after-thanksgiving, christmas (Dec 25). Fixed-date holidays on Saturday are observed the Friday before and on Sunday the Monday after. When next year's January 1 is a Saturday, a new-year-observed entry falls on December 31 of this year; an observed date that falls in another year is not part of this year's calendar. Return [[name, date]] sorted by date.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime as dt
import calendar
N = 1
observations = []
def solve(year):
    def nth(month, wd, n):
        first = dt.date(year, month, 1)
        return first + dt.timedelta(days=(wd - first.weekday()) % 7 + 7 * (n - 1))
    def last(month, wd):
        lastd = dt.date(year, month, calendar.monthrange(year, month)[1])
        return lastd - dt.timedelta(days=(lastd.weekday() - wd) % 7)
    def observed(d):
        return d - dt.timedelta(days=1) if d.weekday() == 5 else d + dt.timedelta(days=1) if d.weekday() == 6 else d
    thanks = nth(11, 3, 4)
    rows = [['new-year', observed(dt.date(year, 1, 1))], ['mlk', nth(1, 0, 3)], ['memorial', last(5, 0)],
            ['juneteenth', observed(dt.date(year, 6, 19))], ['independence', observed(dt.date(year, 7, 4))],
            ['labor', nth(9, 0, 1)], ['thanksgiving', thanks], ['day-after-thanksgiving', thanks + dt.timedelta(days=1)],
            ['christmas', observed(dt.date(year, 12, 25))]]
    nxt = dt.date(year + 1, 1, 1)
    if nxt.weekday() == 6:
        rows.append(['new-year-observed', nxt - dt.timedelta(days=1)])
    rows = [r for r in rows if r[1].year == year]
    return [[name, d.isoformat()] for name, d in sorted(rows, key=lambda r: r[1])]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: 2022 new year on saturday',
   [2022],
   [['mlk', '2022-01-17'],
    ['memorial', '2022-05-30'],
    ['juneteenth', '2022-06-20'],
    ['independence', '2022-07-04'],
    ['labor', '2022-09-05'],
    ['thanksgiving', '2022-11-24'],
    ['day-after-thanksgiving', '2022-11-25'],
    ['christmas', '2022-12-26']]),
  ('2021 next new year saturday',
   [2021],
   [['new-year', '2021-01-01'],
    ['mlk', '2021-01-18'],
    ['memorial', '2021-05-31'],
    ['juneteenth', '2021-06-18'],
    ['independence', '2021-07-05'],
    ['labor', '2021-09-06'],
    ['thanksgiving', '2021-11-25'],
    ['day-after-thanksgiving', '2021-11-26'],
    ['christmas', '2021-12-24'],
    ['new-year-observed', '2021-12-31']]),
  ('2024 leap',
   [2024],
   [['new-year', '2024-01-01'],
    ['mlk', '2024-01-15'],
    ['memorial', '2024-05-27'],
    ['juneteenth', '2024-06-19'],
    ['independence', '2024-07-04'],
    ['labor', '2024-09-02'],
    ['thanksgiving', '2024-11-28'],
    ['day-after-thanksgiving', '2024-11-29'],
    ['christmas', '2024-12-25']]),
  ('2019 november starts friday',
   [2019],
   [['new-year', '2019-01-01'],
    ['mlk', '2019-01-21'],
    ['memorial', '2019-05-27'],
    ['juneteenth', '2019-06-19'],
    ['independence', '2019-07-04'],
    ['labor', '2019-09-02'],
    ['thanksgiving', '2019-11-28'],
    ['day-after-thanksgiving', '2019-11-29'],
    ['christmas', '2019-12-25']]),
  ('2020 july 4 saturday',
   [2020],
   [['new-year', '2020-01-01'],
    ['mlk', '2020-01-20'],
    ['memorial', '2020-05-25'],
    ['juneteenth', '2020-06-19'],
    ['independence', '2020-07-03'],
    ['labor', '2020-09-07'],
    ['thanksgiving', '2020-11-26'],
    ['day-after-thanksgiving', '2020-11-27'],
    ['christmas', '2020-12-25']]),
  ('2016 next new year sunday',
   [2016],
   [['new-year', '2016-01-01'],
    ['mlk', '2016-01-18'],
    ['memorial', '2016-05-30'],
    ['juneteenth', '2016-06-20'],
    ['independence', '2016-07-04'],
    ['labor', '2016-09-05'],
    ['thanksgiving', '2016-11-24'],
    ['day-after-thanksgiving', '2016-11-25'],
    ['christmas', '2016-12-26']]),
  ('2027 five mondays may',
   [2027],
   [['new-year', '2027-01-01'],
    ['mlk', '2027-01-18'],
    ['memorial', '2027-05-31'],
    ['juneteenth', '2027-06-18'],
    ['independence', '2027-07-05'],
    ['labor', '2027-09-06'],
    ['thanksgiving', '2027-11-25'],
    ['day-after-thanksgiving', '2027-11-26'],
    ['christmas', '2027-12-24'],
    ['new-year-observed', '2027-12-31']])],
 [('2024 leap',
   [2024],
   [['new-year', '2024-01-01'],
    ['mlk', '2024-01-15'],
    ['memorial', '2024-05-27'],
    ['juneteenth', '2024-06-19'],
    ['independence', '2024-07-04'],
    ['labor', '2024-09-02'],
    ['thanksgiving', '2024-11-28'],
    ['day-after-thanksgiving', '2024-11-29'],
    ['christmas', '2024-12-25']]),
  ('2019 november starts friday',
   [2019],
   [['new-year', '2019-01-01'],
    ['mlk', '2019-01-21'],
    ['memorial', '2019-05-27'],
    ['juneteenth', '2019-06-19'],
    ['independence', '2019-07-04'],
    ['labor', '2019-09-02'],
    ['thanksgiving', '2019-11-28'],
    ['day-after-thanksgiving', '2019-11-29'],
    ['christmas', '2019-12-25']]),
  ('2020 july 4 saturday',
   [2020],
   [['new-year', '2020-01-01'],
    ['mlk', '2020-01-20'],
    ['memorial', '2020-05-25'],
    ['juneteenth', '2020-06-19'],
    ['independence', '2020-07-03'],
    ['labor', '2020-09-07'],
    ['thanksgiving', '2020-11-26'],
    ['day-after-thanksgiving', '2020-11-27'],
    ['christmas', '2020-12-25']]),
  ('2016 next new year sunday',
   [2016],
   [['new-year', '2016-01-01'],
    ['mlk', '2016-01-18'],
    ['memorial', '2016-05-30'],
    ['juneteenth', '2016-06-20'],
    ['independence', '2016-07-04'],
    ['labor', '2016-09-05'],
    ['thanksgiving', '2016-11-24'],
    ['day-after-thanksgiving', '2016-11-25'],
    ['christmas', '2016-12-26']]),
  ('2027 five mondays may',
   [2027],
   [['new-year', '2027-01-01'],
    ['mlk', '2027-01-18'],
    ['memorial', '2027-05-31'],
    ['juneteenth', '2027-06-18'],
    ['independence', '2027-07-05'],
    ['labor', '2027-09-06'],
    ['thanksgiving', '2027-11-25'],
    ['day-after-thanksgiving', '2027-11-26'],
    ['christmas', '2027-12-24'],
    ['new-year-observed', '2027-12-31']]),
  ('2023',
   [2023],
   [['new-year', '2023-01-02'],
    ['mlk', '2023-01-16'],
    ['memorial', '2023-05-29'],
    ['juneteenth', '2023-06-19'],
    ['independence', '2023-07-04'],
    ['labor', '2023-09-04'],
    ['thanksgiving', '2023-11-23'],
    ['day-after-thanksgiving', '2023-11-24'],
    ['christmas', '2023-12-25']]),
  ('2030',
   [2030],
   [['new-year', '2030-01-01'],
    ['mlk', '2030-01-21'],
    ['memorial', '2030-05-27'],
    ['juneteenth', '2030-06-19'],
    ['independence', '2030-07-04'],
    ['labor', '2030-09-02'],
    ['thanksgiving', '2030-11-28'],
    ['day-after-thanksgiving', '2030-11-29'],
    ['christmas', '2030-12-25']])],
 [('2020 july 4 saturday',
   [2020],
   [['new-year', '2020-01-01'],
    ['mlk', '2020-01-20'],
    ['memorial', '2020-05-25'],
    ['juneteenth', '2020-06-19'],
    ['independence', '2020-07-03'],
    ['labor', '2020-09-07'],
    ['thanksgiving', '2020-11-26'],
    ['day-after-thanksgiving', '2020-11-27'],
    ['christmas', '2020-12-25']]),
  ('2016 next new year sunday',
   [2016],
   [['new-year', '2016-01-01'],
    ['mlk', '2016-01-18'],
    ['memorial', '2016-05-30'],
    ['juneteenth', '2016-06-20'],
    ['independence', '2016-07-04'],
    ['labor', '2016-09-05'],
    ['thanksgiving', '2016-11-24'],
    ['day-after-thanksgiving', '2016-11-25'],
    ['christmas', '2016-12-26']]),
  ('2027 five mondays may',
   [2027],
   [['new-year', '2027-01-01'],
    ['mlk', '2027-01-18'],
    ['memorial', '2027-05-31'],
    ['juneteenth', '2027-06-18'],
    ['independence', '2027-07-05'],
    ['labor', '2027-09-06'],
    ['thanksgiving', '2027-11-25'],
    ['day-after-thanksgiving', '2027-11-26'],
    ['christmas', '2027-12-24'],
    ['new-year-observed', '2027-12-31']]),
  ('2023',
   [2023],
   [['new-year', '2023-01-02'],
    ['mlk', '2023-01-16'],
    ['memorial', '2023-05-29'],
    ['juneteenth', '2023-06-19'],
    ['independence', '2023-07-04'],
    ['labor', '2023-09-04'],
    ['thanksgiving', '2023-11-23'],
    ['day-after-thanksgiving', '2023-11-24'],
    ['christmas', '2023-12-25']]),
  ('2030',
   [2030],
   [['new-year', '2030-01-01'],
    ['mlk', '2030-01-21'],
    ['memorial', '2030-05-27'],
    ['juneteenth', '2030-06-19'],
    ['independence', '2030-07-04'],
    ['labor', '2030-09-02'],
    ['thanksgiving', '2030-11-28'],
    ['day-after-thanksgiving', '2030-11-29'],
    ['christmas', '2030-12-25']]),
  ('2032 leap',
   [2032],
   [['new-year', '2032-01-01'],
    ['mlk', '2032-01-19'],
    ['memorial', '2032-05-31'],
    ['juneteenth', '2032-06-18'],
    ['independence', '2032-07-05'],
    ['labor', '2032-09-06'],
    ['thanksgiving', '2032-11-25'],
    ['day-after-thanksgiving', '2032-11-26'],
    ['christmas', '2032-12-24'],
    ['new-year-observed', '2032-12-31']]),
  ('2033 new year saturday',
   [2033],
   [['mlk', '2033-01-17'],
    ['memorial', '2033-05-30'],
    ['juneteenth', '2033-06-20'],
    ['independence', '2033-07-04'],
    ['labor', '2033-09-05'],
    ['thanksgiving', '2033-11-24'],
    ['day-after-thanksgiving', '2033-11-25'],
    ['christmas', '2033-12-26']])],
 [('2027 five mondays may',
   [2027],
   [['new-year', '2027-01-01'],
    ['mlk', '2027-01-18'],
    ['memorial', '2027-05-31'],
    ['juneteenth', '2027-06-18'],
    ['independence', '2027-07-05'],
    ['labor', '2027-09-06'],
    ['thanksgiving', '2027-11-25'],
    ['day-after-thanksgiving', '2027-11-26'],
    ['christmas', '2027-12-24'],
    ['new-year-observed', '2027-12-31']]),
  ('2023',
   [2023],
   [['new-year', '2023-01-02'],
    ['mlk', '2023-01-16'],
    ['memorial', '2023-05-29'],
    ['juneteenth', '2023-06-19'],
    ['independence', '2023-07-04'],
    ['labor', '2023-09-04'],
    ['thanksgiving', '2023-11-23'],
    ['day-after-thanksgiving', '2023-11-24'],
    ['christmas', '2023-12-25']]),
  ('2030',
   [2030],
   [['new-year', '2030-01-01'],
    ['mlk', '2030-01-21'],
    ['memorial', '2030-05-27'],
    ['juneteenth', '2030-06-19'],
    ['independence', '2030-07-04'],
    ['labor', '2030-09-02'],
    ['thanksgiving', '2030-11-28'],
    ['day-after-thanksgiving', '2030-11-29'],
    ['christmas', '2030-12-25']]),
  ('2032 leap',
   [2032],
   [['new-year', '2032-01-01'],
    ['mlk', '2032-01-19'],
    ['memorial', '2032-05-31'],
    ['juneteenth', '2032-06-18'],
    ['independence', '2032-07-05'],
    ['labor', '2032-09-06'],
    ['thanksgiving', '2032-11-25'],
    ['day-after-thanksgiving', '2032-11-26'],
    ['christmas', '2032-12-24'],
    ['new-year-observed', '2032-12-31']]),
  ('2033 new year saturday',
   [2033],
   [['mlk', '2033-01-17'],
    ['memorial', '2033-05-30'],
    ['juneteenth', '2033-06-20'],
    ['independence', '2033-07-04'],
    ['labor', '2033-09-05'],
    ['thanksgiving', '2033-11-24'],
    ['day-after-thanksgiving', '2033-11-25'],
    ['christmas', '2033-12-26']]),
  ('regression: 2022 new year on saturday',
   [2022],
   [['mlk', '2022-01-17'],
    ['memorial', '2022-05-30'],
    ['juneteenth', '2022-06-20'],
    ['independence', '2022-07-04'],
    ['labor', '2022-09-05'],
    ['thanksgiving', '2022-11-24'],
    ['day-after-thanksgiving', '2022-11-25'],
    ['christmas', '2022-12-26']]),
  ('2021 next new year saturday',
   [2021],
   [['new-year', '2021-01-01'],
    ['mlk', '2021-01-18'],
    ['memorial', '2021-05-31'],
    ['juneteenth', '2021-06-18'],
    ['independence', '2021-07-05'],
    ['labor', '2021-09-06'],
    ['thanksgiving', '2021-11-25'],
    ['day-after-thanksgiving', '2021-11-26'],
    ['christmas', '2021-12-24'],
    ['new-year-observed', '2021-12-31']])],
 [('2030',
   [2030],
   [['new-year', '2030-01-01'],
    ['mlk', '2030-01-21'],
    ['memorial', '2030-05-27'],
    ['juneteenth', '2030-06-19'],
    ['independence', '2030-07-04'],
    ['labor', '2030-09-02'],
    ['thanksgiving', '2030-11-28'],
    ['day-after-thanksgiving', '2030-11-29'],
    ['christmas', '2030-12-25']]),
  ('2032 leap',
   [2032],
   [['new-year', '2032-01-01'],
    ['mlk', '2032-01-19'],
    ['memorial', '2032-05-31'],
    ['juneteenth', '2032-06-18'],
    ['independence', '2032-07-05'],
    ['labor', '2032-09-06'],
    ['thanksgiving', '2032-11-25'],
    ['day-after-thanksgiving', '2032-11-26'],
    ['christmas', '2032-12-24'],
    ['new-year-observed', '2032-12-31']]),
  ('2033 new year saturday',
   [2033],
   [['mlk', '2033-01-17'],
    ['memorial', '2033-05-30'],
    ['juneteenth', '2033-06-20'],
    ['independence', '2033-07-04'],
    ['labor', '2033-09-05'],
    ['thanksgiving', '2033-11-24'],
    ['day-after-thanksgiving', '2033-11-25'],
    ['christmas', '2033-12-26']]),
  ('regression: 2022 new year on saturday',
   [2022],
   [['mlk', '2022-01-17'],
    ['memorial', '2022-05-30'],
    ['juneteenth', '2022-06-20'],
    ['independence', '2022-07-04'],
    ['labor', '2022-09-05'],
    ['thanksgiving', '2022-11-24'],
    ['day-after-thanksgiving', '2022-11-25'],
    ['christmas', '2022-12-26']]),
  ('2021 next new year saturday',
   [2021],
   [['new-year', '2021-01-01'],
    ['mlk', '2021-01-18'],
    ['memorial', '2021-05-31'],
    ['juneteenth', '2021-06-18'],
    ['independence', '2021-07-05'],
    ['labor', '2021-09-06'],
    ['thanksgiving', '2021-11-25'],
    ['day-after-thanksgiving', '2021-11-26'],
    ['christmas', '2021-12-24'],
    ['new-year-observed', '2021-12-31']]),
  ('2024 leap',
   [2024],
   [['new-year', '2024-01-01'],
    ['mlk', '2024-01-15'],
    ['memorial', '2024-05-27'],
    ['juneteenth', '2024-06-19'],
    ['independence', '2024-07-04'],
    ['labor', '2024-09-02'],
    ['thanksgiving', '2024-11-28'],
    ['day-after-thanksgiving', '2024-11-29'],
    ['christmas', '2024-12-25']]),
  ('2019 november starts friday',
   [2019],
   [['new-year', '2019-01-01'],
    ['mlk', '2019-01-21'],
    ['memorial', '2019-05-27'],
    ['juneteenth', '2019-06-19'],
    ['independence', '2019-07-04'],
    ['labor', '2019-09-02'],
    ['thanksgiving', '2019-11-28'],
    ['day-after-thanksgiving', '2019-11-29'],
    ['christmas', '2019-12-25']])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime as dt
import calendar
N = 1
observations = []
def solve(year):
    def nth(month, wd, n):
        first = dt.date(year, month, 1)
        return first + dt.timedelta(days=(wd - first.weekday()) % 7 + 7 * (n - 1))
    def last(month, wd):
        lastd = dt.date(year, month, calendar.monthrange(year, month)[1])
        return lastd - dt.timedelta(days=(lastd.weekday() - wd) % 7)
    def observed(d):
        return d - dt.timedelta(days=1) if d.weekday() == 5 else d + dt.timedelta(days=1) if d.weekday() == 6 else d
    thanks = nth(11, 3, 4)
    rows = [['new-year', observed(dt.date(year, 1, 1))], ['mlk', nth(1, 0, 3)], ['memorial', last(5, 0)],
            ['juneteenth', observed(dt.date(year, 6, 19))], ['independence', observed(dt.date(year, 7, 4))],
            ['labor', nth(9, 0, 1)], ['thanksgiving', thanks], ['day-after-thanksgiving', thanks + dt.timedelta(days=1)],
            ['christmas', observed(dt.date(year, 12, 25))]]
    nxt = dt.date(year + 1, 1, 1)
    if nxt.weekday() >= 5:
        rows.append(['new-year-observed', nxt - dt.timedelta(days=1)])
    rows = [r for r in rows if r[1].year == year]
    return [[name, d.isoformat()] for name, d in sorted(rows, key=lambda r: r[1])]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: 2022 new year on saturday',
   [2022],
   [['mlk', '2022-01-17'],
    ['memorial', '2022-05-30'],
    ['juneteenth', '2022-06-20'],
    ['independence', '2022-07-04'],
    ['labor', '2022-09-05'],
    ['thanksgiving', '2022-11-24'],
    ['day-after-thanksgiving', '2022-11-25'],
    ['christmas', '2022-12-26']]),
  ('2021 next new year saturday',
   [2021],
   [['new-year', '2021-01-01'],
    ['mlk', '2021-01-18'],
    ['memorial', '2021-05-31'],
    ['juneteenth', '2021-06-18'],
    ['independence', '2021-07-05'],
    ['labor', '2021-09-06'],
    ['thanksgiving', '2021-11-25'],
    ['day-after-thanksgiving', '2021-11-26'],
    ['christmas', '2021-12-24'],
    ['new-year-observed', '2021-12-31']]),
  ('2024 leap',
   [2024],
   [['new-year', '2024-01-01'],
    ['mlk', '2024-01-15'],
    ['memorial', '2024-05-27'],
    ['juneteenth', '2024-06-19'],
    ['independence', '2024-07-04'],
    ['labor', '2024-09-02'],
    ['thanksgiving', '2024-11-28'],
    ['day-after-thanksgiving', '2024-11-29'],
    ['christmas', '2024-12-25']]),
  ('2019 november starts friday',
   [2019],
   [['new-year', '2019-01-01'],
    ['mlk', '2019-01-21'],
    ['memorial', '2019-05-27'],
    ['juneteenth', '2019-06-19'],
    ['independence', '2019-07-04'],
    ['labor', '2019-09-02'],
    ['thanksgiving', '2019-11-28'],
    ['day-after-thanksgiving', '2019-11-29'],
    ['christmas', '2019-12-25']]),
  ('2020 july 4 saturday',
   [2020],
   [['new-year', '2020-01-01'],
    ['mlk', '2020-01-20'],
    ['memorial', '2020-05-25'],
    ['juneteenth', '2020-06-19'],
    ['independence', '2020-07-03'],
    ['labor', '2020-09-07'],
    ['thanksgiving', '2020-11-26'],
    ['day-after-thanksgiving', '2020-11-27'],
    ['christmas', '2020-12-25']]),
  ('2016 next new year sunday',
   [2016],
   [['new-year', '2016-01-01'],
    ['mlk', '2016-01-18'],
    ['memorial', '2016-05-30'],
    ['juneteenth', '2016-06-20'],
    ['independence', '2016-07-04'],
    ['labor', '2016-09-05'],
    ['thanksgiving', '2016-11-24'],
    ['day-after-thanksgiving', '2016-11-25'],
    ['christmas', '2016-12-26']]),
  ('2027 five mondays may',
   [2027],
   [['new-year', '2027-01-01'],
    ['mlk', '2027-01-18'],
    ['memorial', '2027-05-31'],
    ['juneteenth', '2027-06-18'],
    ['independence', '2027-07-05'],
    ['labor', '2027-09-06'],
    ['thanksgiving', '2027-11-25'],
    ['day-after-thanksgiving', '2027-11-26'],
    ['christmas', '2027-12-24'],
    ['new-year-observed', '2027-12-31']])],
 [('2024 leap',
   [2024],
   [['new-year', '2024-01-01'],
    ['mlk', '2024-01-15'],
    ['memorial', '2024-05-27'],
    ['juneteenth', '2024-06-19'],
    ['independence', '2024-07-04'],
    ['labor', '2024-09-02'],
    ['thanksgiving', '2024-11-28'],
    ['day-after-thanksgiving', '2024-11-29'],
    ['christmas', '2024-12-25']]),
  ('2019 november starts friday',
   [2019],
   [['new-year', '2019-01-01'],
    ['mlk', '2019-01-21'],
    ['memorial', '2019-05-27'],
    ['juneteenth', '2019-06-19'],
    ['independence', '2019-07-04'],
    ['labor', '2019-09-02'],
    ['thanksgiving', '2019-11-28'],
    ['day-after-thanksgiving', '2019-11-29'],
    ['christmas', '2019-12-25']]),
  ('2020 july 4 saturday',
   [2020],
   [['new-year', '2020-01-01'],
    ['mlk', '2020-01-20'],
    ['memorial', '2020-05-25'],
    ['juneteenth', '2020-06-19'],
    ['independence', '2020-07-03'],
    ['labor', '2020-09-07'],
    ['thanksgiving', '2020-11-26'],
    ['day-after-thanksgiving', '2020-11-27'],
    ['christmas', '2020-12-25']]),
  ('2016 next new year sunday',
   [2016],
   [['new-year', '2016-01-01'],
    ['mlk', '2016-01-18'],
    ['memorial', '2016-05-30'],
    ['juneteenth', '2016-06-20'],
    ['independence', '2016-07-04'],
    ['labor', '2016-09-05'],
    ['thanksgiving', '2016-11-24'],
    ['day-after-thanksgiving', '2016-11-25'],
    ['christmas', '2016-12-26']]),
  ('2027 five mondays may',
   [2027],
   [['new-year', '2027-01-01'],
    ['mlk', '2027-01-18'],
    ['memorial', '2027-05-31'],
    ['juneteenth', '2027-06-18'],
    ['independence', '2027-07-05'],
    ['labor', '2027-09-06'],
    ['thanksgiving', '2027-11-25'],
    ['day-after-thanksgiving', '2027-11-26'],
    ['christmas', '2027-12-24'],
    ['new-year-observed', '2027-12-31']]),
  ('2023',
   [2023],
   [['new-year', '2023-01-02'],
    ['mlk', '2023-01-16'],
    ['memorial', '2023-05-29'],
    ['juneteenth', '2023-06-19'],
    ['independence', '2023-07-04'],
    ['labor', '2023-09-04'],
    ['thanksgiving', '2023-11-23'],
    ['day-after-thanksgiving', '2023-11-24'],
    ['christmas', '2023-12-25']]),
  ('2030',
   [2030],
   [['new-year', '2030-01-01'],
    ['mlk', '2030-01-21'],
    ['memorial', '2030-05-27'],
    ['juneteenth', '2030-06-19'],
    ['independence', '2030-07-04'],
    ['labor', '2030-09-02'],
    ['thanksgiving', '2030-11-28'],
    ['day-after-thanksgiving', '2030-11-29'],
    ['christmas', '2030-12-25']])],
 [('2020 july 4 saturday',
   [2020],
   [['new-year', '2020-01-01'],
    ['mlk', '2020-01-20'],
    ['memorial', '2020-05-25'],
    ['juneteenth', '2020-06-19'],
    ['independence', '2020-07-03'],
    ['labor', '2020-09-07'],
    ['thanksgiving', '2020-11-26'],
    ['day-after-thanksgiving', '2020-11-27'],
    ['christmas', '2020-12-25']]),
  ('2016 next new year sunday',
   [2016],
   [['new-year', '2016-01-01'],
    ['mlk', '2016-01-18'],
    ['memorial', '2016-05-30'],
    ['juneteenth', '2016-06-20'],
    ['independence', '2016-07-04'],
    ['labor', '2016-09-05'],
    ['thanksgiving', '2016-11-24'],
    ['day-after-thanksgiving', '2016-11-25'],
    ['christmas', '2016-12-26']]),
  ('2027 five mondays may',
   [2027],
   [['new-year', '2027-01-01'],
    ['mlk', '2027-01-18'],
    ['memorial', '2027-05-31'],
    ['juneteenth', '2027-06-18'],
    ['independence', '2027-07-05'],
    ['labor', '2027-09-06'],
    ['thanksgiving', '2027-11-25'],
    ['day-after-thanksgiving', '2027-11-26'],
    ['christmas', '2027-12-24'],
    ['new-year-observed', '2027-12-31']]),
  ('2023',
   [2023],
   [['new-year', '2023-01-02'],
    ['mlk', '2023-01-16'],
    ['memorial', '2023-05-29'],
    ['juneteenth', '2023-06-19'],
    ['independence', '2023-07-04'],
    ['labor', '2023-09-04'],
    ['thanksgiving', '2023-11-23'],
    ['day-after-thanksgiving', '2023-11-24'],
    ['christmas', '2023-12-25']]),
  ('2030',
   [2030],
   [['new-year', '2030-01-01'],
    ['mlk', '2030-01-21'],
    ['memorial', '2030-05-27'],
    ['juneteenth', '2030-06-19'],
    ['independence', '2030-07-04'],
    ['labor', '2030-09-02'],
    ['thanksgiving', '2030-11-28'],
    ['day-after-thanksgiving', '2030-11-29'],
    ['christmas', '2030-12-25']]),
  ('2032 leap',
   [2032],
   [['new-year', '2032-01-01'],
    ['mlk', '2032-01-19'],
    ['memorial', '2032-05-31'],
    ['juneteenth', '2032-06-18'],
    ['independence', '2032-07-05'],
    ['labor', '2032-09-06'],
    ['thanksgiving', '2032-11-25'],
    ['day-after-thanksgiving', '2032-11-26'],
    ['christmas', '2032-12-24'],
    ['new-year-observed', '2032-12-31']]),
  ('2033 new year saturday',
   [2033],
   [['mlk', '2033-01-17'],
    ['memorial', '2033-05-30'],
    ['juneteenth', '2033-06-20'],
    ['independence', '2033-07-04'],
    ['labor', '2033-09-05'],
    ['thanksgiving', '2033-11-24'],
    ['day-after-thanksgiving', '2033-11-25'],
    ['christmas', '2033-12-26']])],
 [('2027 five mondays may',
   [2027],
   [['new-year', '2027-01-01'],
    ['mlk', '2027-01-18'],
    ['memorial', '2027-05-31'],
    ['juneteenth', '2027-06-18'],
    ['independence', '2027-07-05'],
    ['labor', '2027-09-06'],
    ['thanksgiving', '2027-11-25'],
    ['day-after-thanksgiving', '2027-11-26'],
    ['christmas', '2027-12-24'],
    ['new-year-observed', '2027-12-31']]),
  ('2023',
   [2023],
   [['new-year', '2023-01-02'],
    ['mlk', '2023-01-16'],
    ['memorial', '2023-05-29'],
    ['juneteenth', '2023-06-19'],
    ['independence', '2023-07-04'],
    ['labor', '2023-09-04'],
    ['thanksgiving', '2023-11-23'],
    ['day-after-thanksgiving', '2023-11-24'],
    ['christmas', '2023-12-25']]),
  ('2030',
   [2030],
   [['new-year', '2030-01-01'],
    ['mlk', '2030-01-21'],
    ['memorial', '2030-05-27'],
    ['juneteenth', '2030-06-19'],
    ['independence', '2030-07-04'],
    ['labor', '2030-09-02'],
    ['thanksgiving', '2030-11-28'],
    ['day-after-thanksgiving', '2030-11-29'],
    ['christmas', '2030-12-25']]),
  ('2032 leap',
   [2032],
   [['new-year', '2032-01-01'],
    ['mlk', '2032-01-19'],
    ['memorial', '2032-05-31'],
    ['juneteenth', '2032-06-18'],
    ['independence', '2032-07-05'],
    ['labor', '2032-09-06'],
    ['thanksgiving', '2032-11-25'],
    ['day-after-thanksgiving', '2032-11-26'],
    ['christmas', '2032-12-24'],
    ['new-year-observed', '2032-12-31']]),
  ('2033 new year saturday',
   [2033],
   [['mlk', '2033-01-17'],
    ['memorial', '2033-05-30'],
    ['juneteenth', '2033-06-20'],
    ['independence', '2033-07-04'],
    ['labor', '2033-09-05'],
    ['thanksgiving', '2033-11-24'],
    ['day-after-thanksgiving', '2033-11-25'],
    ['christmas', '2033-12-26']]),
  ('regression: 2022 new year on saturday',
   [2022],
   [['mlk', '2022-01-17'],
    ['memorial', '2022-05-30'],
    ['juneteenth', '2022-06-20'],
    ['independence', '2022-07-04'],
    ['labor', '2022-09-05'],
    ['thanksgiving', '2022-11-24'],
    ['day-after-thanksgiving', '2022-11-25'],
    ['christmas', '2022-12-26']]),
  ('2021 next new year saturday',
   [2021],
   [['new-year', '2021-01-01'],
    ['mlk', '2021-01-18'],
    ['memorial', '2021-05-31'],
    ['juneteenth', '2021-06-18'],
    ['independence', '2021-07-05'],
    ['labor', '2021-09-06'],
    ['thanksgiving', '2021-11-25'],
    ['day-after-thanksgiving', '2021-11-26'],
    ['christmas', '2021-12-24'],
    ['new-year-observed', '2021-12-31']])],
 [('2030',
   [2030],
   [['new-year', '2030-01-01'],
    ['mlk', '2030-01-21'],
    ['memorial', '2030-05-27'],
    ['juneteenth', '2030-06-19'],
    ['independence', '2030-07-04'],
    ['labor', '2030-09-02'],
    ['thanksgiving', '2030-11-28'],
    ['day-after-thanksgiving', '2030-11-29'],
    ['christmas', '2030-12-25']]),
  ('2032 leap',
   [2032],
   [['new-year', '2032-01-01'],
    ['mlk', '2032-01-19'],
    ['memorial', '2032-05-31'],
    ['juneteenth', '2032-06-18'],
    ['independence', '2032-07-05'],
    ['labor', '2032-09-06'],
    ['thanksgiving', '2032-11-25'],
    ['day-after-thanksgiving', '2032-11-26'],
    ['christmas', '2032-12-24'],
    ['new-year-observed', '2032-12-31']]),
  ('2033 new year saturday',
   [2033],
   [['mlk', '2033-01-17'],
    ['memorial', '2033-05-30'],
    ['juneteenth', '2033-06-20'],
    ['independence', '2033-07-04'],
    ['labor', '2033-09-05'],
    ['thanksgiving', '2033-11-24'],
    ['day-after-thanksgiving', '2033-11-25'],
    ['christmas', '2033-12-26']]),
  ('regression: 2022 new year on saturday',
   [2022],
   [['mlk', '2022-01-17'],
    ['memorial', '2022-05-30'],
    ['juneteenth', '2022-06-20'],
    ['independence', '2022-07-04'],
    ['labor', '2022-09-05'],
    ['thanksgiving', '2022-11-24'],
    ['day-after-thanksgiving', '2022-11-25'],
    ['christmas', '2022-12-26']]),
  ('2021 next new year saturday',
   [2021],
   [['new-year', '2021-01-01'],
    ['mlk', '2021-01-18'],
    ['memorial', '2021-05-31'],
    ['juneteenth', '2021-06-18'],
    ['independence', '2021-07-05'],
    ['labor', '2021-09-06'],
    ['thanksgiving', '2021-11-25'],
    ['day-after-thanksgiving', '2021-11-26'],
    ['christmas', '2021-12-24'],
    ['new-year-observed', '2021-12-31']]),
  ('2024 leap',
   [2024],
   [['new-year', '2024-01-01'],
    ['mlk', '2024-01-15'],
    ['memorial', '2024-05-27'],
    ['juneteenth', '2024-06-19'],
    ['independence', '2024-07-04'],
    ['labor', '2024-09-02'],
    ['thanksgiving', '2024-11-28'],
    ['day-after-thanksgiving', '2024-11-29'],
    ['christmas', '2024-12-25']]),
  ('2019 november starts friday',
   [2019],
   [['new-year', '2019-01-01'],
    ['mlk', '2019-01-21'],
    ['memorial', '2019-05-27'],
    ['juneteenth', '2019-06-19'],
    ['independence', '2019-07-04'],
    ['labor', '2019-09-02'],
    ['thanksgiving', '2019-11-28'],
    ['day-after-thanksgiving', '2019-11-29'],
    ['christmas', '2019-12-25']])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
When next New Year falls on Saturday, December 31 is missing from the calendar.

Stipulated court holidays for a year: new-year (Jan 1), mlk (3rd Monday Jan), memorial (last Monday May), juneteenth (Jun 19), independence (Jul 4), labor (1st Monday Sep), thanksgiving (4th Thursday Nov), day-after-thanksgiving, christmas (Dec 25). Fixed-date holidays on Saturday are observed the Friday before and on Sunday the Monday after. When next year's January 1 is a Saturday, a new-year-observed entry falls on December 31 of this year; an observed date that falls in another year is not part of this year's calendar. Return [[name, date]] sorted by date.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime as dt
import calendar
N = 1
observations = []
def solve(year):
    def nth(month, wd, n):
        first = dt.date(year, month, 1)
        return first + dt.timedelta(days=(wd - first.weekday()) % 7 + 7 * (n - 1))
    def last(month, wd):
        lastd = dt.date(year, month, calendar.monthrange(year, month)[1])
        return lastd - dt.timedelta(days=(lastd.weekday() - wd) % 7)
    def observed(d):
        return d - dt.timedelta(days=1) if d.weekday() == 5 else d + dt.timedelta(days=1) if d.weekday() == 6 else d
    thanks = nth(11, 3, 4)
    rows = [['new-year', observed(dt.date(year, 1, 1))], ['mlk', nth(1, 0, 3)], ['memorial', last(5, 0)],
            ['juneteenth', observed(dt.date(year, 6, 19))], ['independence', observed(dt.date(year, 7, 4))],
            ['labor', nth(9, 0, 1)], ['thanksgiving', thanks], ['day-after-thanksgiving', thanks + dt.timedelta(days=1)],
            ['christmas', observed(dt.date(year, 12, 25))]]
    nxt = dt.date(year + 1, 1, 1)
    if nxt.weekday() == 5:
        rows.append(['new-year-observed', nxt - dt.timedelta(days=1)])
    rows = [r for r in rows if r[1] <= dt.date(year, 12, 31)]
    return [[name, d.isoformat()] for name, d in sorted(rows, key=lambda r: r[1])]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: 2022 new year on saturday',
   [2022],
   [['mlk', '2022-01-17'],
    ['memorial', '2022-05-30'],
    ['juneteenth', '2022-06-20'],
    ['independence', '2022-07-04'],
    ['labor', '2022-09-05'],
    ['thanksgiving', '2022-11-24'],
    ['day-after-thanksgiving', '2022-11-25'],
    ['christmas', '2022-12-26']]),
  ('2021 next new year saturday',
   [2021],
   [['new-year', '2021-01-01'],
    ['mlk', '2021-01-18'],
    ['memorial', '2021-05-31'],
    ['juneteenth', '2021-06-18'],
    ['independence', '2021-07-05'],
    ['labor', '2021-09-06'],
    ['thanksgiving', '2021-11-25'],
    ['day-after-thanksgiving', '2021-11-26'],
    ['christmas', '2021-12-24'],
    ['new-year-observed', '2021-12-31']]),
  ('2024 leap',
   [2024],
   [['new-year', '2024-01-01'],
    ['mlk', '2024-01-15'],
    ['memorial', '2024-05-27'],
    ['juneteenth', '2024-06-19'],
    ['independence', '2024-07-04'],
    ['labor', '2024-09-02'],
    ['thanksgiving', '2024-11-28'],
    ['day-after-thanksgiving', '2024-11-29'],
    ['christmas', '2024-12-25']]),
  ('2019 november starts friday',
   [2019],
   [['new-year', '2019-01-01'],
    ['mlk', '2019-01-21'],
    ['memorial', '2019-05-27'],
    ['juneteenth', '2019-06-19'],
    ['independence', '2019-07-04'],
    ['labor', '2019-09-02'],
    ['thanksgiving', '2019-11-28'],
    ['day-after-thanksgiving', '2019-11-29'],
    ['christmas', '2019-12-25']]),
  ('2020 july 4 saturday',
   [2020],
   [['new-year', '2020-01-01'],
    ['mlk', '2020-01-20'],
    ['memorial', '2020-05-25'],
    ['juneteenth', '2020-06-19'],
    ['independence', '2020-07-03'],
    ['labor', '2020-09-07'],
    ['thanksgiving', '2020-11-26'],
    ['day-after-thanksgiving', '2020-11-27'],
    ['christmas', '2020-12-25']]),
  ('2016 next new year sunday',
   [2016],
   [['new-year', '2016-01-01'],
    ['mlk', '2016-01-18'],
    ['memorial', '2016-05-30'],
    ['juneteenth', '2016-06-20'],
    ['independence', '2016-07-04'],
    ['labor', '2016-09-05'],
    ['thanksgiving', '2016-11-24'],
    ['day-after-thanksgiving', '2016-11-25'],
    ['christmas', '2016-12-26']]),
  ('2027 five mondays may',
   [2027],
   [['new-year', '2027-01-01'],
    ['mlk', '2027-01-18'],
    ['memorial', '2027-05-31'],
    ['juneteenth', '2027-06-18'],
    ['independence', '2027-07-05'],
    ['labor', '2027-09-06'],
    ['thanksgiving', '2027-11-25'],
    ['day-after-thanksgiving', '2027-11-26'],
    ['christmas', '2027-12-24'],
    ['new-year-observed', '2027-12-31']])],
 [('2024 leap',
   [2024],
   [['new-year', '2024-01-01'],
    ['mlk', '2024-01-15'],
    ['memorial', '2024-05-27'],
    ['juneteenth', '2024-06-19'],
    ['independence', '2024-07-04'],
    ['labor', '2024-09-02'],
    ['thanksgiving', '2024-11-28'],
    ['day-after-thanksgiving', '2024-11-29'],
    ['christmas', '2024-12-25']]),
  ('2019 november starts friday',
   [2019],
   [['new-year', '2019-01-01'],
    ['mlk', '2019-01-21'],
    ['memorial', '2019-05-27'],
    ['juneteenth', '2019-06-19'],
    ['independence', '2019-07-04'],
    ['labor', '2019-09-02'],
    ['thanksgiving', '2019-11-28'],
    ['day-after-thanksgiving', '2019-11-29'],
    ['christmas', '2019-12-25']]),
  ('2020 july 4 saturday',
   [2020],
   [['new-year', '2020-01-01'],
    ['mlk', '2020-01-20'],
    ['memorial', '2020-05-25'],
    ['juneteenth', '2020-06-19'],
    ['independence', '2020-07-03'],
    ['labor', '2020-09-07'],
    ['thanksgiving', '2020-11-26'],
    ['day-after-thanksgiving', '2020-11-27'],
    ['christmas', '2020-12-25']]),
  ('2016 next new year sunday',
   [2016],
   [['new-year', '2016-01-01'],
    ['mlk', '2016-01-18'],
    ['memorial', '2016-05-30'],
    ['juneteenth', '2016-06-20'],
    ['independence', '2016-07-04'],
    ['labor', '2016-09-05'],
    ['thanksgiving', '2016-11-24'],
    ['day-after-thanksgiving', '2016-11-25'],
    ['christmas', '2016-12-26']]),
  ('2027 five mondays may',
   [2027],
   [['new-year', '2027-01-01'],
    ['mlk', '2027-01-18'],
    ['memorial', '2027-05-31'],
    ['juneteenth', '2027-06-18'],
    ['independence', '2027-07-05'],
    ['labor', '2027-09-06'],
    ['thanksgiving', '2027-11-25'],
    ['day-after-thanksgiving', '2027-11-26'],
    ['christmas', '2027-12-24'],
    ['new-year-observed', '2027-12-31']]),
  ('2023',
   [2023],
   [['new-year', '2023-01-02'],
    ['mlk', '2023-01-16'],
    ['memorial', '2023-05-29'],
    ['juneteenth', '2023-06-19'],
    ['independence', '2023-07-04'],
    ['labor', '2023-09-04'],
    ['thanksgiving', '2023-11-23'],
    ['day-after-thanksgiving', '2023-11-24'],
    ['christmas', '2023-12-25']]),
  ('2030',
   [2030],
   [['new-year', '2030-01-01'],
    ['mlk', '2030-01-21'],
    ['memorial', '2030-05-27'],
    ['juneteenth', '2030-06-19'],
    ['independence', '2030-07-04'],
    ['labor', '2030-09-02'],
    ['thanksgiving', '2030-11-28'],
    ['day-after-thanksgiving', '2030-11-29'],
    ['christmas', '2030-12-25']]),
  ('regression: 2022 new year on saturday',
   [2022],
   [['mlk', '2022-01-17'],
    ['memorial', '2022-05-30'],
    ['juneteenth', '2022-06-20'],
    ['independence', '2022-07-04'],
    ['labor', '2022-09-05'],
    ['thanksgiving', '2022-11-24'],
    ['day-after-thanksgiving', '2022-11-25'],
    ['christmas', '2022-12-26']])],
 [('2020 july 4 saturday',
   [2020],
   [['new-year', '2020-01-01'],
    ['mlk', '2020-01-20'],
    ['memorial', '2020-05-25'],
    ['juneteenth', '2020-06-19'],
    ['independence', '2020-07-03'],
    ['labor', '2020-09-07'],
    ['thanksgiving', '2020-11-26'],
    ['day-after-thanksgiving', '2020-11-27'],
    ['christmas', '2020-12-25']]),
  ('2016 next new year sunday',
   [2016],
   [['new-year', '2016-01-01'],
    ['mlk', '2016-01-18'],
    ['memorial', '2016-05-30'],
    ['juneteenth', '2016-06-20'],
    ['independence', '2016-07-04'],
    ['labor', '2016-09-05'],
    ['thanksgiving', '2016-11-24'],
    ['day-after-thanksgiving', '2016-11-25'],
    ['christmas', '2016-12-26']]),
  ('2027 five mondays may',
   [2027],
   [['new-year', '2027-01-01'],
    ['mlk', '2027-01-18'],
    ['memorial', '2027-05-31'],
    ['juneteenth', '2027-06-18'],
    ['independence', '2027-07-05'],
    ['labor', '2027-09-06'],
    ['thanksgiving', '2027-11-25'],
    ['day-after-thanksgiving', '2027-11-26'],
    ['christmas', '2027-12-24'],
    ['new-year-observed', '2027-12-31']]),
  ('2023',
   [2023],
   [['new-year', '2023-01-02'],
    ['mlk', '2023-01-16'],
    ['memorial', '2023-05-29'],
    ['juneteenth', '2023-06-19'],
    ['independence', '2023-07-04'],
    ['labor', '2023-09-04'],
    ['thanksgiving', '2023-11-23'],
    ['day-after-thanksgiving', '2023-11-24'],
    ['christmas', '2023-12-25']]),
  ('2030',
   [2030],
   [['new-year', '2030-01-01'],
    ['mlk', '2030-01-21'],
    ['memorial', '2030-05-27'],
    ['juneteenth', '2030-06-19'],
    ['independence', '2030-07-04'],
    ['labor', '2030-09-02'],
    ['thanksgiving', '2030-11-28'],
    ['day-after-thanksgiving', '2030-11-29'],
    ['christmas', '2030-12-25']]),
  ('2032 leap',
   [2032],
   [['new-year', '2032-01-01'],
    ['mlk', '2032-01-19'],
    ['memorial', '2032-05-31'],
    ['juneteenth', '2032-06-18'],
    ['independence', '2032-07-05'],
    ['labor', '2032-09-06'],
    ['thanksgiving', '2032-11-25'],
    ['day-after-thanksgiving', '2032-11-26'],
    ['christmas', '2032-12-24'],
    ['new-year-observed', '2032-12-31']]),
  ('2033 new year saturday',
   [2033],
   [['mlk', '2033-01-17'],
    ['memorial', '2033-05-30'],
    ['juneteenth', '2033-06-20'],
    ['independence', '2033-07-04'],
    ['labor', '2033-09-05'],
    ['thanksgiving', '2033-11-24'],
    ['day-after-thanksgiving', '2033-11-25'],
    ['christmas', '2033-12-26']])],
 [('2027 five mondays may',
   [2027],
   [['new-year', '2027-01-01'],
    ['mlk', '2027-01-18'],
    ['memorial', '2027-05-31'],
    ['juneteenth', '2027-06-18'],
    ['independence', '2027-07-05'],
    ['labor', '2027-09-06'],
    ['thanksgiving', '2027-11-25'],
    ['day-after-thanksgiving', '2027-11-26'],
    ['christmas', '2027-12-24'],
    ['new-year-observed', '2027-12-31']]),
  ('2023',
   [2023],
   [['new-year', '2023-01-02'],
    ['mlk', '2023-01-16'],
    ['memorial', '2023-05-29'],
    ['juneteenth', '2023-06-19'],
    ['independence', '2023-07-04'],
    ['labor', '2023-09-04'],
    ['thanksgiving', '2023-11-23'],
    ['day-after-thanksgiving', '2023-11-24'],
    ['christmas', '2023-12-25']]),
  ('2030',
   [2030],
   [['new-year', '2030-01-01'],
    ['mlk', '2030-01-21'],
    ['memorial', '2030-05-27'],
    ['juneteenth', '2030-06-19'],
    ['independence', '2030-07-04'],
    ['labor', '2030-09-02'],
    ['thanksgiving', '2030-11-28'],
    ['day-after-thanksgiving', '2030-11-29'],
    ['christmas', '2030-12-25']]),
  ('2032 leap',
   [2032],
   [['new-year', '2032-01-01'],
    ['mlk', '2032-01-19'],
    ['memorial', '2032-05-31'],
    ['juneteenth', '2032-06-18'],
    ['independence', '2032-07-05'],
    ['labor', '2032-09-06'],
    ['thanksgiving', '2032-11-25'],
    ['day-after-thanksgiving', '2032-11-26'],
    ['christmas', '2032-12-24'],
    ['new-year-observed', '2032-12-31']]),
  ('2033 new year saturday',
   [2033],
   [['mlk', '2033-01-17'],
    ['memorial', '2033-05-30'],
    ['juneteenth', '2033-06-20'],
    ['independence', '2033-07-04'],
    ['labor', '2033-09-05'],
    ['thanksgiving', '2033-11-24'],
    ['day-after-thanksgiving', '2033-11-25'],
    ['christmas', '2033-12-26']]),
  ('regression: 2022 new year on saturday',
   [2022],
   [['mlk', '2022-01-17'],
    ['memorial', '2022-05-30'],
    ['juneteenth', '2022-06-20'],
    ['independence', '2022-07-04'],
    ['labor', '2022-09-05'],
    ['thanksgiving', '2022-11-24'],
    ['day-after-thanksgiving', '2022-11-25'],
    ['christmas', '2022-12-26']]),
  ('2021 next new year saturday',
   [2021],
   [['new-year', '2021-01-01'],
    ['mlk', '2021-01-18'],
    ['memorial', '2021-05-31'],
    ['juneteenth', '2021-06-18'],
    ['independence', '2021-07-05'],
    ['labor', '2021-09-06'],
    ['thanksgiving', '2021-11-25'],
    ['day-after-thanksgiving', '2021-11-26'],
    ['christmas', '2021-12-24'],
    ['new-year-observed', '2021-12-31']])],
 [('2030',
   [2030],
   [['new-year', '2030-01-01'],
    ['mlk', '2030-01-21'],
    ['memorial', '2030-05-27'],
    ['juneteenth', '2030-06-19'],
    ['independence', '2030-07-04'],
    ['labor', '2030-09-02'],
    ['thanksgiving', '2030-11-28'],
    ['day-after-thanksgiving', '2030-11-29'],
    ['christmas', '2030-12-25']]),
  ('2032 leap',
   [2032],
   [['new-year', '2032-01-01'],
    ['mlk', '2032-01-19'],
    ['memorial', '2032-05-31'],
    ['juneteenth', '2032-06-18'],
    ['independence', '2032-07-05'],
    ['labor', '2032-09-06'],
    ['thanksgiving', '2032-11-25'],
    ['day-after-thanksgiving', '2032-11-26'],
    ['christmas', '2032-12-24'],
    ['new-year-observed', '2032-12-31']]),
  ('2033 new year saturday',
   [2033],
   [['mlk', '2033-01-17'],
    ['memorial', '2033-05-30'],
    ['juneteenth', '2033-06-20'],
    ['independence', '2033-07-04'],
    ['labor', '2033-09-05'],
    ['thanksgiving', '2033-11-24'],
    ['day-after-thanksgiving', '2033-11-25'],
    ['christmas', '2033-12-26']]),
  ('regression: 2022 new year on saturday',
   [2022],
   [['mlk', '2022-01-17'],
    ['memorial', '2022-05-30'],
    ['juneteenth', '2022-06-20'],
    ['independence', '2022-07-04'],
    ['labor', '2022-09-05'],
    ['thanksgiving', '2022-11-24'],
    ['day-after-thanksgiving', '2022-11-25'],
    ['christmas', '2022-12-26']]),
  ('2021 next new year saturday',
   [2021],
   [['new-year', '2021-01-01'],
    ['mlk', '2021-01-18'],
    ['memorial', '2021-05-31'],
    ['juneteenth', '2021-06-18'],
    ['independence', '2021-07-05'],
    ['labor', '2021-09-06'],
    ['thanksgiving', '2021-11-25'],
    ['day-after-thanksgiving', '2021-11-26'],
    ['christmas', '2021-12-24'],
    ['new-year-observed', '2021-12-31']]),
  ('2024 leap',
   [2024],
   [['new-year', '2024-01-01'],
    ['mlk', '2024-01-15'],
    ['memorial', '2024-05-27'],
    ['juneteenth', '2024-06-19'],
    ['independence', '2024-07-04'],
    ['labor', '2024-09-02'],
    ['thanksgiving', '2024-11-28'],
    ['day-after-thanksgiving', '2024-11-29'],
    ['christmas', '2024-12-25']]),
  ('2019 november starts friday',
   [2019],
   [['new-year', '2019-01-01'],
    ['mlk', '2019-01-21'],
    ['memorial', '2019-05-27'],
    ['juneteenth', '2019-06-19'],
    ['independence', '2019-07-04'],
    ['labor', '2019-09-02'],
    ['thanksgiving', '2019-11-28'],
    ['day-after-thanksgiving', '2019-11-29'],
    ['christmas', '2019-12-25']])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime as dt
import calendar
N = 1
observations = []
def solve(year):
    def nth(month, wd, n):
        first = dt.date(year, month, 1)
        return first + dt.timedelta(days=(wd - first.weekday()) % 7 + 7 * (n - 1))
    def last(month, wd):
        lastd = dt.date(year, month, calendar.monthrange(year, month)[1])
        return lastd - dt.timedelta(days=(lastd.weekday() - wd) % 7)
    def observed(d):
        return d - dt.timedelta(days=1) if d.weekday() == 5 else d + dt.timedelta(days=1) if d.weekday() == 6 else d
    thanks = nth(11, 3, 4)
    rows = [['new-year', observed(dt.date(year, 1, 1))], ['mlk', nth(1, 0, 3)], ['memorial', last(5, 0)],
            ['juneteenth', observed(dt.date(year, 6, 19))], ['independence', observed(dt.date(year, 7, 4))],
            ['labor', nth(9, 0, 1)], ['thanksgiving', thanks], ['day-after-thanksgiving', thanks + dt.timedelta(days=1)],
            ['christmas', observed(dt.date(year, 12, 25))]]
    nxt = dt.date(year + 1, 1, 1)
    if nxt.weekday() == 5:
        rows.append(['new-year-observed', nxt - dt.timedelta(days=1)])
    rows = [r for r in rows if r[0] != 'new-year']
    return [[name, d.isoformat()] for name, d in sorted(rows, key=lambda r: r[1])]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: 2022 new year on saturday',
   [2022],
   [['mlk', '2022-01-17'],
    ['memorial', '2022-05-30'],
    ['juneteenth', '2022-06-20'],
    ['independence', '2022-07-04'],
    ['labor', '2022-09-05'],
    ['thanksgiving', '2022-11-24'],
    ['day-after-thanksgiving', '2022-11-25'],
    ['christmas', '2022-12-26']]),
  ('2021 next new year saturday',
   [2021],
   [['new-year', '2021-01-01'],
    ['mlk', '2021-01-18'],
    ['memorial', '2021-05-31'],
    ['juneteenth', '2021-06-18'],
    ['independence', '2021-07-05'],
    ['labor', '2021-09-06'],
    ['thanksgiving', '2021-11-25'],
    ['day-after-thanksgiving', '2021-11-26'],
    ['christmas', '2021-12-24'],
    ['new-year-observed', '2021-12-31']]),
  ('2024 leap',
   [2024],
   [['new-year', '2024-01-01'],
    ['mlk', '2024-01-15'],
    ['memorial', '2024-05-27'],
    ['juneteenth', '2024-06-19'],
    ['independence', '2024-07-04'],
    ['labor', '2024-09-02'],
    ['thanksgiving', '2024-11-28'],
    ['day-after-thanksgiving', '2024-11-29'],
    ['christmas', '2024-12-25']]),
  ('2019 november starts friday',
   [2019],
   [['new-year', '2019-01-01'],
    ['mlk', '2019-01-21'],
    ['memorial', '2019-05-27'],
    ['juneteenth', '2019-06-19'],
    ['independence', '2019-07-04'],
    ['labor', '2019-09-02'],
    ['thanksgiving', '2019-11-28'],
    ['day-after-thanksgiving', '2019-11-29'],
    ['christmas', '2019-12-25']]),
  ('2020 july 4 saturday',
   [2020],
   [['new-year', '2020-01-01'],
    ['mlk', '2020-01-20'],
    ['memorial', '2020-05-25'],
    ['juneteenth', '2020-06-19'],
    ['independence', '2020-07-03'],
    ['labor', '2020-09-07'],
    ['thanksgiving', '2020-11-26'],
    ['day-after-thanksgiving', '2020-11-27'],
    ['christmas', '2020-12-25']]),
  ('2016 next new year sunday',
   [2016],
   [['new-year', '2016-01-01'],
    ['mlk', '2016-01-18'],
    ['memorial', '2016-05-30'],
    ['juneteenth', '2016-06-20'],
    ['independence', '2016-07-04'],
    ['labor', '2016-09-05'],
    ['thanksgiving', '2016-11-24'],
    ['day-after-thanksgiving', '2016-11-25'],
    ['christmas', '2016-12-26']]),
  ('2027 five mondays may',
   [2027],
   [['new-year', '2027-01-01'],
    ['mlk', '2027-01-18'],
    ['memorial', '2027-05-31'],
    ['juneteenth', '2027-06-18'],
    ['independence', '2027-07-05'],
    ['labor', '2027-09-06'],
    ['thanksgiving', '2027-11-25'],
    ['day-after-thanksgiving', '2027-11-26'],
    ['christmas', '2027-12-24'],
    ['new-year-observed', '2027-12-31']])],
 [('2024 leap',
   [2024],
   [['new-year', '2024-01-01'],
    ['mlk', '2024-01-15'],
    ['memorial', '2024-05-27'],
    ['juneteenth', '2024-06-19'],
    ['independence', '2024-07-04'],
    ['labor', '2024-09-02'],
    ['thanksgiving', '2024-11-28'],
    ['day-after-thanksgiving', '2024-11-29'],
    ['christmas', '2024-12-25']]),
  ('2019 november starts friday',
   [2019],
   [['new-year', '2019-01-01'],
    ['mlk', '2019-01-21'],
    ['memorial', '2019-05-27'],
    ['juneteenth', '2019-06-19'],
    ['independence', '2019-07-04'],
    ['labor', '2019-09-02'],
    ['thanksgiving', '2019-11-28'],
    ['day-after-thanksgiving', '2019-11-29'],
    ['christmas', '2019-12-25']]),
  ('2020 july 4 saturday',
   [2020],
   [['new-year', '2020-01-01'],
    ['mlk', '2020-01-20'],
    ['memorial', '2020-05-25'],
    ['juneteenth', '2020-06-19'],
    ['independence', '2020-07-03'],
    ['labor', '2020-09-07'],
    ['thanksgiving', '2020-11-26'],
    ['day-after-thanksgiving', '2020-11-27'],
    ['christmas', '2020-12-25']]),
  ('2016 next new year sunday',
   [2016],
   [['new-year', '2016-01-01'],
    ['mlk', '2016-01-18'],
    ['memorial', '2016-05-30'],
    ['juneteenth', '2016-06-20'],
    ['independence', '2016-07-04'],
    ['labor', '2016-09-05'],
    ['thanksgiving', '2016-11-24'],
    ['day-after-thanksgiving', '2016-11-25'],
    ['christmas', '2016-12-26']]),
  ('2027 five mondays may',
   [2027],
   [['new-year', '2027-01-01'],
    ['mlk', '2027-01-18'],
    ['memorial', '2027-05-31'],
    ['juneteenth', '2027-06-18'],
    ['independence', '2027-07-05'],
    ['labor', '2027-09-06'],
    ['thanksgiving', '2027-11-25'],
    ['day-after-thanksgiving', '2027-11-26'],
    ['christmas', '2027-12-24'],
    ['new-year-observed', '2027-12-31']]),
  ('2023',
   [2023],
   [['new-year', '2023-01-02'],
    ['mlk', '2023-01-16'],
    ['memorial', '2023-05-29'],
    ['juneteenth', '2023-06-19'],
    ['independence', '2023-07-04'],
    ['labor', '2023-09-04'],
    ['thanksgiving', '2023-11-23'],
    ['day-after-thanksgiving', '2023-11-24'],
    ['christmas', '2023-12-25']]),
  ('2030',
   [2030],
   [['new-year', '2030-01-01'],
    ['mlk', '2030-01-21'],
    ['memorial', '2030-05-27'],
    ['juneteenth', '2030-06-19'],
    ['independence', '2030-07-04'],
    ['labor', '2030-09-02'],
    ['thanksgiving', '2030-11-28'],
    ['day-after-thanksgiving', '2030-11-29'],
    ['christmas', '2030-12-25']]),
  ('regression: 2022 new year on saturday',
   [2022],
   [['mlk', '2022-01-17'],
    ['memorial', '2022-05-30'],
    ['juneteenth', '2022-06-20'],
    ['independence', '2022-07-04'],
    ['labor', '2022-09-05'],
    ['thanksgiving', '2022-11-24'],
    ['day-after-thanksgiving', '2022-11-25'],
    ['christmas', '2022-12-26']])],
 [('2020 july 4 saturday',
   [2020],
   [['new-year', '2020-01-01'],
    ['mlk', '2020-01-20'],
    ['memorial', '2020-05-25'],
    ['juneteenth', '2020-06-19'],
    ['independence', '2020-07-03'],
    ['labor', '2020-09-07'],
    ['thanksgiving', '2020-11-26'],
    ['day-after-thanksgiving', '2020-11-27'],
    ['christmas', '2020-12-25']]),
  ('2016 next new year sunday',
   [2016],
   [['new-year', '2016-01-01'],
    ['mlk', '2016-01-18'],
    ['memorial', '2016-05-30'],
    ['juneteenth', '2016-06-20'],
    ['independence', '2016-07-04'],
    ['labor', '2016-09-05'],
    ['thanksgiving', '2016-11-24'],
    ['day-after-thanksgiving', '2016-11-25'],
    ['christmas', '2016-12-26']]),
  ('2027 five mondays may',
   [2027],
   [['new-year', '2027-01-01'],
    ['mlk', '2027-01-18'],
    ['memorial', '2027-05-31'],
    ['juneteenth', '2027-06-18'],
    ['independence', '2027-07-05'],
    ['labor', '2027-09-06'],
    ['thanksgiving', '2027-11-25'],
    ['day-after-thanksgiving', '2027-11-26'],
    ['christmas', '2027-12-24'],
    ['new-year-observed', '2027-12-31']]),
  ('2023',
   [2023],
   [['new-year', '2023-01-02'],
    ['mlk', '2023-01-16'],
    ['memorial', '2023-05-29'],
    ['juneteenth', '2023-06-19'],
    ['independence', '2023-07-04'],
    ['labor', '2023-09-04'],
    ['thanksgiving', '2023-11-23'],
    ['day-after-thanksgiving', '2023-11-24'],
    ['christmas', '2023-12-25']]),
  ('2030',
   [2030],
   [['new-year', '2030-01-01'],
    ['mlk', '2030-01-21'],
    ['memorial', '2030-05-27'],
    ['juneteenth', '2030-06-19'],
    ['independence', '2030-07-04'],
    ['labor', '2030-09-02'],
    ['thanksgiving', '2030-11-28'],
    ['day-after-thanksgiving', '2030-11-29'],
    ['christmas', '2030-12-25']]),
  ('2032 leap',
   [2032],
   [['new-year', '2032-01-01'],
    ['mlk', '2032-01-19'],
    ['memorial', '2032-05-31'],
    ['juneteenth', '2032-06-18'],
    ['independence', '2032-07-05'],
    ['labor', '2032-09-06'],
    ['thanksgiving', '2032-11-25'],
    ['day-after-thanksgiving', '2032-11-26'],
    ['christmas', '2032-12-24'],
    ['new-year-observed', '2032-12-31']]),
  ('2033 new year saturday',
   [2033],
   [['mlk', '2033-01-17'],
    ['memorial', '2033-05-30'],
    ['juneteenth', '2033-06-20'],
    ['independence', '2033-07-04'],
    ['labor', '2033-09-05'],
    ['thanksgiving', '2033-11-24'],
    ['day-after-thanksgiving', '2033-11-25'],
    ['christmas', '2033-12-26']])],
 [('2027 five mondays may',
   [2027],
   [['new-year', '2027-01-01'],
    ['mlk', '2027-01-18'],
    ['memorial', '2027-05-31'],
    ['juneteenth', '2027-06-18'],
    ['independence', '2027-07-05'],
    ['labor', '2027-09-06'],
    ['thanksgiving', '2027-11-25'],
    ['day-after-thanksgiving', '2027-11-26'],
    ['christmas', '2027-12-24'],
    ['new-year-observed', '2027-12-31']]),
  ('2023',
   [2023],
   [['new-year', '2023-01-02'],
    ['mlk', '2023-01-16'],
    ['memorial', '2023-05-29'],
    ['juneteenth', '2023-06-19'],
    ['independence', '2023-07-04'],
    ['labor', '2023-09-04'],
    ['thanksgiving', '2023-11-23'],
    ['day-after-thanksgiving', '2023-11-24'],
    ['christmas', '2023-12-25']]),
  ('2030',
   [2030],
   [['new-year', '2030-01-01'],
    ['mlk', '2030-01-21'],
    ['memorial', '2030-05-27'],
    ['juneteenth', '2030-06-19'],
    ['independence', '2030-07-04'],
    ['labor', '2030-09-02'],
    ['thanksgiving', '2030-11-28'],
    ['day-after-thanksgiving', '2030-11-29'],
    ['christmas', '2030-12-25']]),
  ('2032 leap',
   [2032],
   [['new-year', '2032-01-01'],
    ['mlk', '2032-01-19'],
    ['memorial', '2032-05-31'],
    ['juneteenth', '2032-06-18'],
    ['independence', '2032-07-05'],
    ['labor', '2032-09-06'],
    ['thanksgiving', '2032-11-25'],
    ['day-after-thanksgiving', '2032-11-26'],
    ['christmas', '2032-12-24'],
    ['new-year-observed', '2032-12-31']]),
  ('2033 new year saturday',
   [2033],
   [['mlk', '2033-01-17'],
    ['memorial', '2033-05-30'],
    ['juneteenth', '2033-06-20'],
    ['independence', '2033-07-04'],
    ['labor', '2033-09-05'],
    ['thanksgiving', '2033-11-24'],
    ['day-after-thanksgiving', '2033-11-25'],
    ['christmas', '2033-12-26']]),
  ('regression: 2022 new year on saturday',
   [2022],
   [['mlk', '2022-01-17'],
    ['memorial', '2022-05-30'],
    ['juneteenth', '2022-06-20'],
    ['independence', '2022-07-04'],
    ['labor', '2022-09-05'],
    ['thanksgiving', '2022-11-24'],
    ['day-after-thanksgiving', '2022-11-25'],
    ['christmas', '2022-12-26']]),
  ('2021 next new year saturday',
   [2021],
   [['new-year', '2021-01-01'],
    ['mlk', '2021-01-18'],
    ['memorial', '2021-05-31'],
    ['juneteenth', '2021-06-18'],
    ['independence', '2021-07-05'],
    ['labor', '2021-09-06'],
    ['thanksgiving', '2021-11-25'],
    ['day-after-thanksgiving', '2021-11-26'],
    ['christmas', '2021-12-24'],
    ['new-year-observed', '2021-12-31']])],
 [('2030',
   [2030],
   [['new-year', '2030-01-01'],
    ['mlk', '2030-01-21'],
    ['memorial', '2030-05-27'],
    ['juneteenth', '2030-06-19'],
    ['independence', '2030-07-04'],
    ['labor', '2030-09-02'],
    ['thanksgiving', '2030-11-28'],
    ['day-after-thanksgiving', '2030-11-29'],
    ['christmas', '2030-12-25']]),
  ('2032 leap',
   [2032],
   [['new-year', '2032-01-01'],
    ['mlk', '2032-01-19'],
    ['memorial', '2032-05-31'],
    ['juneteenth', '2032-06-18'],
    ['independence', '2032-07-05'],
    ['labor', '2032-09-06'],
    ['thanksgiving', '2032-11-25'],
    ['day-after-thanksgiving', '2032-11-26'],
    ['christmas', '2032-12-24'],
    ['new-year-observed', '2032-12-31']]),
  ('2033 new year saturday',
   [2033],
   [['mlk', '2033-01-17'],
    ['memorial', '2033-05-30'],
    ['juneteenth', '2033-06-20'],
    ['independence', '2033-07-04'],
    ['labor', '2033-09-05'],
    ['thanksgiving', '2033-11-24'],
    ['day-after-thanksgiving', '2033-11-25'],
    ['christmas', '2033-12-26']]),
  ('regression: 2022 new year on saturday',
   [2022],
   [['mlk', '2022-01-17'],
    ['memorial', '2022-05-30'],
    ['juneteenth', '2022-06-20'],
    ['independence', '2022-07-04'],
    ['labor', '2022-09-05'],
    ['thanksgiving', '2022-11-24'],
    ['day-after-thanksgiving', '2022-11-25'],
    ['christmas', '2022-12-26']]),
  ('2021 next new year saturday',
   [2021],
   [['new-year', '2021-01-01'],
    ['mlk', '2021-01-18'],
    ['memorial', '2021-05-31'],
    ['juneteenth', '2021-06-18'],
    ['independence', '2021-07-05'],
    ['labor', '2021-09-06'],
    ['thanksgiving', '2021-11-25'],
    ['day-after-thanksgiving', '2021-11-26'],
    ['christmas', '2021-12-24'],
    ['new-year-observed', '2021-12-31']]),
  ('2024 leap',
   [2024],
   [['new-year', '2024-01-01'],
    ['mlk', '2024-01-15'],
    ['memorial', '2024-05-27'],
    ['juneteenth', '2024-06-19'],
    ['independence', '2024-07-04'],
    ['labor', '2024-09-02'],
    ['thanksgiving', '2024-11-28'],
    ['day-after-thanksgiving', '2024-11-29'],
    ['christmas', '2024-12-25']]),
  ('2019 november starts friday',
   [2019],
   [['new-year', '2019-01-01'],
    ['mlk', '2019-01-21'],
    ['memorial', '2019-05-27'],
    ['juneteenth', '2019-06-19'],
    ['independence', '2019-07-04'],
    ['labor', '2019-09-02'],
    ['thanksgiving', '2019-11-28'],
    ['day-after-thanksgiving', '2019-11-29'],
    ['christmas', '2019-12-25']])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
In a year whose January 1 is Saturday, the calendar lists December 31 of the previous year.

Stipulated court holidays for a year: new-year (Jan 1), mlk (3rd Monday Jan), memorial (last Monday May), juneteenth (Jun 19), independence (Jul 4), labor (1st Monday Sep), thanksgiving (4th Thursday Nov), day-after-thanksgiving, christmas (Dec 25). Fixed-date holidays on Saturday are observed the Friday before and on Sunday the Monday after. When next year's January 1 is a Saturday, a new-year-observed entry falls on December 31 of this year; an observed date that falls in another year is not part of this year's calendar. Return [[name, date]] sorted by date.

split: open-access


prompt:
A Saturday and the following Sunday publication are treated as the same week.

Stipulated: service by publication requires at least four publications, one in each of successive calendar weeks (weeks run Sunday to Saturday), with no two in the same week. Service is complete on the 28th day after the first publication, and the response is due 30 days after completion (a closed last day moves to the next open day). Return {"valid": false} or {"valid": true, "complete", "respond"}.

split: open-access


prompt:
Two publications in the same week are accepted as covering two weeks.

Stipulated: service by publication requires at least four publications, one in each of successive calendar weeks (weeks run Sunday to Saturday), with no two in the same week. Service is complete on the 28th day after the first publication, and the response is due 30 days after completion (a closed last day moves to the next open day). Return {"valid": false} or {"valid": true, "complete", "respond"}.

split: open-access


prompt:
A schedule publishing Monday then Friday of the next week is rejected although the weeks are successive.

Stipulated: service by publication requires at least four publications, one in each of successive calendar weeks (weeks run Sunday to Saturday), with no two in the same week. Service is complete on the 28th day after the first publication, and the response is due 30 days after completion (a closed last day moves to the next open day). Return {"valid": false} or {"valid": true, "complete", "respond"}.

split: open-access


prompt:
Completion is computed from the last publication, delaying the response deadline.

Stipulated: service by publication requires at least four publications, one in each of successive calendar weeks (weeks run Sunday to Saturday), with no two in the same week. Service is complete on the 28th day after the first publication, and the response is due 30 days after completion (a closed last day moves to the next open day). Return {"valid": false} or {"valid": true, "complete", "respond"}.

split: open-access


prompt:
On the deadline day the court-day count is blank instead of zero.

For today and a deadline, return [calendar days remaining, court days remaining, status]. Court days remaining counts open days (not Saturday, Sunday or a listed holiday) after today up to and including the deadline; it is None when the deadline has passed. Status is "overdue" if the deadline is before today, "due today" if equal, "due soon" if at most 3 court days remain, else "open".

split: open-access


prompt:
Today is counted and the deadline day is not.

For today and a deadline, return [calendar days remaining, court days remaining, status]. Court days remaining counts open days (not Saturday, Sunday or a listed holiday) after today up to and including the deadline; it is None when the deadline has passed. Status is "overdue" if the deadline is before today, "due today" if equal, "due soon" if at most 3 court days remain, else "open".

split: open-access


prompt:
A Monday deadline viewed on Saturday is reported as due today.

For today and a deadline, return [calendar days remaining, court days remaining, status]. Court days remaining counts open days (not Saturday, Sunday or a listed holiday) after today up to and including the deadline; it is None when the deadline has passed. Status is "overdue" if the deadline is before today, "due today" if equal, "due soon" if at most 3 court days remain, else "open".

split: open-access


prompt:
A deadline three calendar days away over a long weekend is flagged later than the court-day rule requires.

For today and a deadline, return [calendar days remaining, court days remaining, status]. Court days remaining counts open days (not Saturday, Sunday or a listed holiday) after today up to and including the deadline; it is None when the deadline has passed. Status is "overdue" if the deadline is before today, "due today" if equal, "due soon" if at most 3 court days remain, else "open".

split: open-access


prompt:
A second stipulation signed after the original deadline but within the extended one is ignored.

Stipulated: the original deadline (rolled forward to an open day) may be extended by stipulations [signed, days] processed in order, without court order, up to 30 days in total across all stipulations. A stipulation is valid only if signed on or before the then-current deadline; it grants min(days, remaining cap), added to the current deadline, and the result is rolled forward to an open day (not weekend or listed holiday). Return [final deadline, total days granted].

split: open-access


prompt:
Three 14-day stipulations extend the deadline by 42 days.

Stipulated: the original deadline (rolled forward to an open day) may be extended by stipulations [signed, days] processed in order, without court order, up to 30 days in total across all stipulations. A stipulation is valid only if signed on or before the then-current deadline; it grants min(days, remaining cap), added to the current deadline, and the result is rolled forward to an open day (not weekend or listed holiday). Return [final deadline, total days granted].

split: open-access


prompt:
A second extension is added to the original deadline, so extensions do not stack.

Stipulated: the original deadline (rolled forward to an open day) may be extended by stipulations [signed, days] processed in order, without court order, up to 30 days in total across all stipulations. A stipulation is valid only if signed on or before the then-current deadline; it grants min(days, remaining cap), added to the current deadline, and the result is rolled forward to an open day (not weekend or listed holiday). Return [final deadline, total days granted].

split: open-access


prompt:
An extension ending on a Saturday leaves the deadline on the Saturday.

Stipulated: the original deadline (rolled forward to an open day) may be extended by stipulations [signed, days] processed in order, without court order, up to 30 days in total across all stipulations. A stipulation is valid only if signed on or before the then-current deadline; it grants min(days, remaining cap), added to the current deadline, and the result is rolled forward to an open day (not weekend or listed holiday). Return [final deadline, total days granted].

split: open-access