{"files": {"main.py": "from core import run\nfrom policy import POLICY\ndef evaluate(payload):\n    return run(payload, POLICY)\n", "policy.py": "POLICY = {\"adjacency_allowed\": False, \"blackout_day\": \"2026-11-02\", \"cancelled_blocks\": False, \"capacity\": 2, \"cutoff_hour\": 18, \"cutoff_inclusive\": False, \"duplicate_policy\": \"last\", \"duration_max\": 90, \"lead_minutes\": 60, \"priority_high_first\": False, \"report_order\": \"input\", \"timezone\": \"UTC\"}\n", "helpers.py": "from datetime import datetime, timedelta, timezone\n\n\ndef parse(s):\n    if s.endswith('Z'):\n        s = s[:-1] + '+00:00'\n    return datetime.fromisoformat(s)\n\n\ndef overlaps(a, b, adjacency_allowed):\n    if adjacency_allowed:\n        return a[0] < b[1] and b[0] < a[1]\n    return a[0] <= b[1] and b[0] <= a[1]\n", "core.py": "from datetime import datetime, timedelta, timezone\nfrom zoneinfo import ZoneInfo\nfrom helpers import parse, overlaps\n\n\ndef run(payload, policy):\n    tz = ZoneInfo(policy['timezone'])\n    utc = timezone.utc\n    now = parse(payload['now']).astimezone(utc)\n    rows = {}\n    order = []\n    for i, a in enumerate(payload['appointments']):\n        k = a['id']\n        if k not in rows:\n            order.append(k)\n            rows[k] = (i, a)\n        elif policy['duplicate_policy'] == 'last':\n            rows[k] = (i, a)\n    items = [rows[k] for k in order]\n    hf = policy['priority_high_first']\n    items.sort(key=lambda t: ((-t[1]['priority']) if hf else t[1]['priority'], t[0]))\n    accepted = []\n    sel, blk, rej = [], [], []\n    for idx, a in items:\n        ok = True\n        dur = a['duration']\n        if not (isinstance(dur, int) and 0 < dur <= policy['duration_max']):\n            ok = False\n        start = None\n        if ok:\n            try:\n                start = parse(a['start'])\n                if start.tzinfo is None:\n                    ok = False\n            except Exception:\n                ok = False\n        if ok:\n            su = start.astimezone(utc)\n            eu = su + timedelta(minutes=dur)\n            if su < now + timedelta(minutes=policy['lead_minutes']):\n                ok = False\n        if ok:\n            ls = su.astimezone(tz)\n            if ls.date().isoformat() == policy['blackout_day']:\n                ok = False\n        if ok:\n            cutoff = datetime(ls.year, ls.month, ls.day, policy['cutoff_hour'], 0, tzinfo=tz).astimezone(utc)\n            if policy['cutoff_inclusive']:\n                if not eu <= cutoff:\n                    ok = False\n            elif not eu < cutoff:\n                ok = False\n        if ok and a['cancelled'] and not policy['cancelled_blocks']:\n            ok = False\n        if ok:\n            iv = (su, eu)\n            n = sum(1 for x in accepted if overlaps(iv, x, policy['adjacency_allowed']))\n            if n >= policy['capacity']:\n                ok = False\n        if not ok:\n            rej.append((idx, a['id']))\n            continue\n        accepted.append(iv)\n        if a['cancelled']:\n            blk.append((idx, a['id']))\n        else:\n            sel.append((idx, a['id']))\n\n    def fin(l):\n        if policy['report_order'] == 'id':\n            return [x[1] for x in sorted(l, key=lambda t: t[1])]\n        return [x[1] for x in sorted(l, key=lambda t: t[0])]\n    return {'selected': fin(sel), 'blocked': fin(blk), 'rejected': fin(rej)}\n"}}