diff --git a/tasks/construct-ae-p38-factorial-factors-l3-s1/environment/Dockerfile b/tasks/construct-ae-p38-factorial-factors-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l3-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-ae-p38-factorial-factors-l3-s1/environment/instance.json b/tasks/construct-ae-p38-factorial-factors-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..52d8c66c9b3f8b711b804f45ba0fe71446d455d8 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"N": 231, "t": 69, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l3-s1/solution/solve.sh b/tasks/construct-ae-p38-factorial-factors-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..005d1ce6894311c98a29b4d54abb24473b81b1ef --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l3-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"factors": [69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 71, 71, 71, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 73, 73, 73, 74, 74, 74, 74, 74, 74, 75, 75, 75, 75, 75, 75, 75, 75, 75, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 79, 79, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 82, 82, 82, 82, 82, 83, 83, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 86, 86, 86, 86, 86, 87, 87, 87, 87, 87, 87, 87, 89, 89, 93, 93, 93, 93, 93, 93, 93, 94, 94, 94, 94, 97, 97, 101, 101, 102, 103, 103, 106, 106, 106, 106, 107, 107, 109, 109, 113, 113, 118, 118, 118, 122, 122, 122, 127, 131, 134, 134, 134, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229]} +RLMATH_EOF diff --git a/tasks/construct-ae-p38-factorial-factors-l3-s1/tests/check.py b/tasks/construct-ae-p38-factorial-factors-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..93ec67a19039afa8b4ce6e39811691b802132562 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l3-s1/tests/check.py @@ -0,0 +1,12 @@ +"""Factor N! into N factors, each >= t (AlphaEvolve problem 38 / OEIS A034258). Exact big-integer check.""" +import math + +from run import Invalid, int_list + + +def check(inst, ans): + n, t = inst["N"], inst["t"] + f = int_list(ans.get("factors"), n, t, None, "factors") + if math.prod(f) != math.factorial(n): + raise Invalid(f"the product of the factors is not {n}!") + return None, {"min_factor": min(f)} diff --git a/tasks/construct-ae-p38-factorial-factors-l3-s1/tests/instance.json b/tasks/construct-ae-p38-factorial-factors-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..52d8c66c9b3f8b711b804f45ba0fe71446d455d8 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"N": 231, "t": 69, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l3-s1/tests/run.py b/tasks/construct-ae-p38-factorial-factors-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l3-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-ae-p38-factorial-factors-l3-s1/tests/test.sh b/tasks/construct-ae-p38-factorial-factors-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l3-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-ae-p38-factorial-factors-l3-s6/environment/Dockerfile b/tasks/construct-ae-p38-factorial-factors-l3-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l3-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-ae-p38-factorial-factors-l3-s6/environment/instance.json b/tasks/construct-ae-p38-factorial-factors-l3-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a245b9cea90693cfdc8cffbff4487e52d38586b7 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l3-s6/environment/instance.json @@ -0,0 +1 @@ +{"N": 339, "t": 103, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l3-s6/solution/solve.sh b/tasks/construct-ae-p38-factorial-factors-l3-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8edc66a4ce6bdb72b2fc1c643ba6c1b622f51c2f --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l3-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"factors": [103, 103, 103, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 106, 106, 106, 106, 106, 106, 107, 107, 107, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 109, 109, 109, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 111, 111, 111, 111, 111, 111, 111, 111, 111, 113, 113, 113, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 118, 118, 118, 118, 118, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 122, 122, 122, 122, 122, 123, 123, 123, 123, 123, 123, 123, 123, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 125, 127, 127, 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, 129, 129, 129, 131, 131, 133, 134, 134, 134, 134, 134, 137, 137, 139, 139, 141, 141, 141, 141, 141, 141, 141, 142, 142, 142, 142, 146, 146, 146, 146, 149, 149, 151, 151, 157, 157, 158, 158, 158, 158, 163, 163, 166, 166, 166, 166, 167, 167, 173, 178, 178, 178, 179, 181, 191, 193, 194, 194, 194, 197, 199, 202, 202, 202, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337]} +RLMATH_EOF diff --git a/tasks/construct-ae-p38-factorial-factors-l3-s6/tests/check.py b/tasks/construct-ae-p38-factorial-factors-l3-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..93ec67a19039afa8b4ce6e39811691b802132562 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l3-s6/tests/check.py @@ -0,0 +1,12 @@ +"""Factor N! into N factors, each >= t (AlphaEvolve problem 38 / OEIS A034258). Exact big-integer check.""" +import math + +from run import Invalid, int_list + + +def check(inst, ans): + n, t = inst["N"], inst["t"] + f = int_list(ans.get("factors"), n, t, None, "factors") + if math.prod(f) != math.factorial(n): + raise Invalid(f"the product of the factors is not {n}!") + return None, {"min_factor": min(f)} diff --git a/tasks/construct-ae-p38-factorial-factors-l3-s6/tests/instance.json b/tasks/construct-ae-p38-factorial-factors-l3-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a245b9cea90693cfdc8cffbff4487e52d38586b7 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l3-s6/tests/instance.json @@ -0,0 +1 @@ +{"N": 339, "t": 103, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l3-s6/tests/run.py b/tasks/construct-ae-p38-factorial-factors-l3-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l3-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-ae-p38-factorial-factors-l3-s6/tests/test.sh b/tasks/construct-ae-p38-factorial-factors-l3-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l3-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-ae-p38-factorial-factors-l3-s8/environment/Dockerfile b/tasks/construct-ae-p38-factorial-factors-l3-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l3-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-ae-p38-factorial-factors-l3-s8/environment/instance.json b/tasks/construct-ae-p38-factorial-factors-l3-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cdd7a3209c6b62fc72f57e0e0982fcf27338ca2e --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l3-s8/environment/instance.json @@ -0,0 +1 @@ +{"N": 384, "t": 117, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l3-s8/solution/solve.sh b/tasks/construct-ae-p38-factorial-factors-l3-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1e4d6115b47e7c596442365601ae36da005be88e --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l3-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"factors": [117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 118, 118, 118, 118, 118, 118, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 122, 122, 122, 122, 122, 122, 123, 123, 123, 123, 123, 123, 123, 123, 123, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 125, 125, 125, 125, 125, 125, 125, 125, 125, 125, 125, 125, 125, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 127, 127, 127, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, 129, 129, 129, 129, 131, 131, 132, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 134, 134, 134, 134, 134, 137, 137, 138, 138, 138, 138, 138, 138, 138, 138, 138, 138, 138, 138, 138, 138, 138, 138, 139, 139, 141, 141, 141, 141, 141, 141, 141, 141, 142, 142, 142, 142, 142, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 146, 146, 146, 146, 146, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 149, 149, 151, 151, 157, 157, 158, 158, 158, 158, 159, 159, 159, 159, 159, 159, 159, 163, 163, 166, 166, 166, 166, 167, 167, 173, 173, 178, 178, 178, 178, 179, 179, 181, 181, 191, 191, 193, 194, 194, 194, 197, 199, 202, 202, 202, 206, 206, 206, 211, 214, 214, 214, 218, 218, 218, 223, 226, 226, 226, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383]} +RLMATH_EOF diff --git a/tasks/construct-ae-p38-factorial-factors-l3-s8/tests/check.py b/tasks/construct-ae-p38-factorial-factors-l3-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..93ec67a19039afa8b4ce6e39811691b802132562 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l3-s8/tests/check.py @@ -0,0 +1,12 @@ +"""Factor N! into N factors, each >= t (AlphaEvolve problem 38 / OEIS A034258). Exact big-integer check.""" +import math + +from run import Invalid, int_list + + +def check(inst, ans): + n, t = inst["N"], inst["t"] + f = int_list(ans.get("factors"), n, t, None, "factors") + if math.prod(f) != math.factorial(n): + raise Invalid(f"the product of the factors is not {n}!") + return None, {"min_factor": min(f)} diff --git a/tasks/construct-ae-p38-factorial-factors-l3-s8/tests/instance.json b/tasks/construct-ae-p38-factorial-factors-l3-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cdd7a3209c6b62fc72f57e0e0982fcf27338ca2e --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l3-s8/tests/instance.json @@ -0,0 +1 @@ +{"N": 384, "t": 117, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l3-s8/tests/run.py b/tasks/construct-ae-p38-factorial-factors-l3-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l3-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-ae-p38-factorial-factors-l3-s8/tests/test.sh b/tasks/construct-ae-p38-factorial-factors-l3-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l3-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-ae-p52-erdos-squarefree-l3-s3/environment/Dockerfile b/tasks/construct-ae-p52-erdos-squarefree-l3-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l3-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-ae-p52-erdos-squarefree-l3-s3/environment/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l3-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3957d950b1e197d4cf5e332563450428e8175b73 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l3-s3/environment/instance.json @@ -0,0 +1 @@ +{"N": 686, "t": 28, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l3-s3/solution/solve.sh b/tasks/construct-ae-p52-erdos-squarefree-l3-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d9271085014943e866413aedc362aa487f661c0d --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l3-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"A": [7, 32, 57, 82, 107, 132, 157, 182, 207, 232, 257, 282, 307, 332, 357, 382, 407, 432, 457, 482, 507, 532, 557, 582, 607, 632, 657, 682]} +RLMATH_EOF diff --git a/tasks/construct-ae-p52-erdos-squarefree-l3-s3/tests/check.py b/tasks/construct-ae-p52-erdos-squarefree-l3-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..87e15b242f211059193ba122baecdee9add99130 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l3-s3/tests/check.py @@ -0,0 +1,38 @@ +"""Erdos squarefree problem (AlphaEvolve problem 52): A in [1, N], |A| >= t, ab+1 NOT squarefree for all a, b in A +(a = b included). The repo's problem page says "square-free"; the notebook and the Erdos problem ask for +"never squarefree", which is what we check. Exact: for every pair we find a prime p with p^2 | ab+1.""" +import numpy as np + +from run import Invalid, int_list + + +def _primes(n): + s = np.ones(n + 1, dtype=bool) + s[:2] = False + for i in range(2, int(n ** .5) + 1): + if s[i]: + s[i * i::i] = False + return np.nonzero(s)[0] + + +def check(inst, ans): + n, t = inst["N"], inst["t"] + a = ans.get("A") + if not isinstance(a, list) or not (t <= len(a) <= 2 * t + 20): + raise Invalid(f"A must be a list of {t}..{2 * t + 20} integers") + int_list(a, None, 1, n, "A") + if len(set(a)) != len(a): + raise Invalid("A must consist of distinct integers") + x = np.array(sorted(a), dtype=np.int64) + iu, ju = np.triu_indices(len(x)) + va, vb = x[iu], x[ju] + left = np.ones(len(iu), dtype=bool) # pairs without a square divisor found yet + for p in _primes(int((n * n + 1) ** .5) + 1): + q = int(p) * int(p) + idx = np.nonzero(left)[0] + hit = ((va[idx] % q) * (vb[idx] % q) + 1) % q == 0 + left[idx[hit]] = False + if not left.any(): + return None, {"size": len(a)} + k = int(np.nonzero(left)[0][0]) + raise Invalid(f"{int(va[k])}*{int(vb[k])}+1 = {int(va[k]) * int(vb[k]) + 1} is squarefree") diff --git a/tasks/construct-ae-p52-erdos-squarefree-l3-s3/tests/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l3-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3957d950b1e197d4cf5e332563450428e8175b73 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l3-s3/tests/instance.json @@ -0,0 +1 @@ +{"N": 686, "t": 28, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l3-s3/tests/run.py b/tasks/construct-ae-p52-erdos-squarefree-l3-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l3-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-ae-p52-erdos-squarefree-l3-s3/tests/test.sh b/tasks/construct-ae-p52-erdos-squarefree-l3-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l3-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-ae-p52-erdos-squarefree-l3-s4/environment/Dockerfile b/tasks/construct-ae-p52-erdos-squarefree-l3-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l3-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-ae-p52-erdos-squarefree-l3-s4/environment/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l3-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..162aab3a4b71c755eb4d52a2a6d751b8d489971e --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l3-s4/environment/instance.json @@ -0,0 +1 @@ +{"N": 1214, "t": 49, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l3-s4/solution/solve.sh b/tasks/construct-ae-p52-erdos-squarefree-l3-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..08dd662b27f2e463f866ae8102d9d7773351d82d --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l3-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"A": [7, 32, 57, 82, 107, 132, 157, 182, 207, 232, 257, 282, 307, 332, 357, 382, 407, 432, 457, 482, 507, 532, 557, 582, 607, 632, 657, 682, 707, 732, 757, 782, 807, 832, 857, 882, 907, 932, 957, 982, 1007, 1032, 1057, 1082, 1107, 1132, 1157, 1182, 1207]} +RLMATH_EOF diff --git a/tasks/construct-ae-p52-erdos-squarefree-l3-s4/tests/check.py b/tasks/construct-ae-p52-erdos-squarefree-l3-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..87e15b242f211059193ba122baecdee9add99130 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l3-s4/tests/check.py @@ -0,0 +1,38 @@ +"""Erdos squarefree problem (AlphaEvolve problem 52): A in [1, N], |A| >= t, ab+1 NOT squarefree for all a, b in A +(a = b included). The repo's problem page says "square-free"; the notebook and the Erdos problem ask for +"never squarefree", which is what we check. Exact: for every pair we find a prime p with p^2 | ab+1.""" +import numpy as np + +from run import Invalid, int_list + + +def _primes(n): + s = np.ones(n + 1, dtype=bool) + s[:2] = False + for i in range(2, int(n ** .5) + 1): + if s[i]: + s[i * i::i] = False + return np.nonzero(s)[0] + + +def check(inst, ans): + n, t = inst["N"], inst["t"] + a = ans.get("A") + if not isinstance(a, list) or not (t <= len(a) <= 2 * t + 20): + raise Invalid(f"A must be a list of {t}..{2 * t + 20} integers") + int_list(a, None, 1, n, "A") + if len(set(a)) != len(a): + raise Invalid("A must consist of distinct integers") + x = np.array(sorted(a), dtype=np.int64) + iu, ju = np.triu_indices(len(x)) + va, vb = x[iu], x[ju] + left = np.ones(len(iu), dtype=bool) # pairs without a square divisor found yet + for p in _primes(int((n * n + 1) ** .5) + 1): + q = int(p) * int(p) + idx = np.nonzero(left)[0] + hit = ((va[idx] % q) * (vb[idx] % q) + 1) % q == 0 + left[idx[hit]] = False + if not left.any(): + return None, {"size": len(a)} + k = int(np.nonzero(left)[0][0]) + raise Invalid(f"{int(va[k])}*{int(vb[k])}+1 = {int(va[k]) * int(vb[k]) + 1} is squarefree") diff --git a/tasks/construct-ae-p52-erdos-squarefree-l3-s4/tests/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l3-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..162aab3a4b71c755eb4d52a2a6d751b8d489971e --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l3-s4/tests/instance.json @@ -0,0 +1 @@ +{"N": 1214, "t": 49, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l3-s4/tests/run.py b/tasks/construct-ae-p52-erdos-squarefree-l3-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l3-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-ae-p52-erdos-squarefree-l3-s4/tests/test.sh b/tasks/construct-ae-p52-erdos-squarefree-l3-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l3-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-all-interval-l3-s1/environment/Dockerfile b/tasks/construct-mc-all-interval-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-all-interval-l3-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-all-interval-l3-s1/environment/instance.json b/tasks/construct-mc-all-interval-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ed5c9dd8df4be9b6009f1bf52a52e50d7edc3bc9 --- /dev/null +++ b/tasks/construct-mc-all-interval-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 13, "fixed": [], "family": "mc_all_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-all-interval-l3-s1/solution/solve.sh b/tasks/construct-mc-all-interval-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b560c3f5beff72ca3a906d50d227bea559fb40bc --- /dev/null +++ b/tasks/construct-mc-all-interval-l3-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [0, 12, 1, 11, 2, 10, 3, 9, 4, 8, 5, 7, 6]} +RLMATH_EOF diff --git a/tasks/construct-mc-all-interval-l3-s1/tests/check.py b/tasks/construct-mc-all-interval-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2e39eec264b6422a47e35921b8cdbe1fa1748307 --- /dev/null +++ b/tasks/construct-mc-all-interval-l3-s1/tests/check.py @@ -0,0 +1,17 @@ +"""All-interval series of size n (MathConstraint all_interval, CC-BY-4.0). Accepts any valid series.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("x"), n, 0, n - 1, "x") + if sorted(x) != list(range(n)): + raise Invalid("x is not a permutation of 0..n-1") + d = [abs(x[i + 1] - x[i]) for i in range(n - 1)] + if sorted(d) != list(range(1, n)): + raise Invalid("consecutive differences are not a permutation of 1..n-1") + seqs = {"x": x, "d": d} + for name, i, v in inst.get("fixed", []): + if seqs[name][i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + return None, {} diff --git a/tasks/construct-mc-all-interval-l3-s1/tests/instance.json b/tasks/construct-mc-all-interval-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ed5c9dd8df4be9b6009f1bf52a52e50d7edc3bc9 --- /dev/null +++ b/tasks/construct-mc-all-interval-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 13, "fixed": [], "family": "mc_all_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-all-interval-l3-s1/tests/run.py b/tasks/construct-mc-all-interval-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-all-interval-l3-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-all-interval-l3-s1/tests/test.sh b/tasks/construct-mc-all-interval-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-all-interval-l3-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-bibd-l4-s3/environment/Dockerfile b/tasks/construct-mc-bibd-l4-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-bibd-l4-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-bibd-l4-s3/environment/instance.json b/tasks/construct-mc-bibd-l4-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..24a546c4d255cfd1bc33a98cbf37d14ab172c23d --- /dev/null +++ b/tasks/construct-mc-bibd-l4-s3/environment/instance.json @@ -0,0 +1 @@ +{"v": 21, "k": 5, "lambda": 1, "b": 21, "family": "mc_bibd", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-bibd-l4-s3/solution/solve.sh b/tasks/construct-mc-bibd-l4-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..666b52194a038a1f774d7bdf5d40ebc2db98c1e9 --- /dev/null +++ b/tasks/construct-mc-bibd-l4-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"blocks": [[0, 1, 4, 14, 16], [1, 2, 5, 15, 17], [2, 3, 6, 16, 18], [3, 4, 7, 17, 19], [4, 5, 8, 18, 20], [0, 5, 6, 9, 19], [1, 6, 7, 10, 20], [0, 2, 7, 8, 11], [1, 3, 8, 9, 12], [2, 4, 9, 10, 13], [3, 5, 10, 11, 14], [4, 6, 11, 12, 15], [5, 7, 12, 13, 16], [6, 8, 13, 14, 17], [7, 9, 14, 15, 18], [8, 10, 15, 16, 19], [9, 11, 16, 17, 20], [0, 10, 12, 17, 18], [1, 11, 13, 18, 19], [2, 12, 14, 19, 20], [0, 3, 13, 15, 20]]} +RLMATH_EOF diff --git a/tasks/construct-mc-bibd-l4-s3/tests/check.py b/tasks/construct-mc-bibd-l4-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c4b5da62477026f27ff9869fe33602fcc41e2ea9 --- /dev/null +++ b/tasks/construct-mc-bibd-l4-s3/tests/check.py @@ -0,0 +1,25 @@ +"""Balanced incomplete block design BIBD(v, k, lambda) (MathConstraint bibd, CC-BY-4.0). +Answer = list of b blocks; every block is a k-subset of {0..v-1}, every pair of points lies in exactly +lambda blocks (which forces every point to lie in r blocks). Repeated blocks are allowed, as upstream +(its 0/1 incidence-matrix model does not forbid equal columns).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + v, k, lam, b = inst["v"], inst["k"], inst["lambda"], inst["b"] + blocks = ans.get("blocks") + if not isinstance(blocks, list) or len(blocks) != b: + raise Invalid(f"blocks must be a list of exactly {b} blocks") + pair = {} + for B in blocks: + B = int_list(B, k, 0, v - 1, "block") + if len(set(B)) != k: + raise Invalid("a block contains a repeated point") + for p in itertools.combinations(sorted(B), 2): + pair[p] = pair.get(p, 0) + 1 + for p in itertools.combinations(range(v), 2): + if pair.get(p, 0) != lam: + raise Invalid(f"points {p} lie together in {pair.get(p, 0)} blocks, need {lam}") + return None, {} diff --git a/tasks/construct-mc-bibd-l4-s3/tests/instance.json b/tasks/construct-mc-bibd-l4-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..24a546c4d255cfd1bc33a98cbf37d14ab172c23d --- /dev/null +++ b/tasks/construct-mc-bibd-l4-s3/tests/instance.json @@ -0,0 +1 @@ +{"v": 21, "k": 5, "lambda": 1, "b": 21, "family": "mc_bibd", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-bibd-l4-s3/tests/run.py b/tasks/construct-mc-bibd-l4-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-bibd-l4-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-bibd-l4-s3/tests/test.sh b/tasks/construct-mc-bibd-l4-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-bibd-l4-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-costas-array-l1-s1/environment/Dockerfile b/tasks/construct-mc-costas-array-l1-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-costas-array-l1-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-costas-array-l1-s1/environment/instance.json b/tasks/construct-mc-costas-array-l1-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..064e9d1f005c4000861f2894fa7b367cbebc0468 --- /dev/null +++ b/tasks/construct-mc-costas-array-l1-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 5, "fixed": [["x", 2, 3]], "family": "mc_costas_array", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-costas-array-l1-s1/solution/solve.sh b/tasks/construct-mc-costas-array-l1-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ee9b9e28e7e460cb3427cad46d3aa70c31e645b1 --- /dev/null +++ b/tasks/construct-mc-costas-array-l1-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [0, 2, 3, 1, 4]} +RLMATH_EOF diff --git a/tasks/construct-mc-costas-array-l1-s1/tests/check.py b/tasks/construct-mc-costas-array-l1-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c86323a5b639b23787ecd4d5f358b986bbd91b6c --- /dev/null +++ b/tasks/construct-mc-costas-array-l1-s1/tests/check.py @@ -0,0 +1,22 @@ +"""Costas array of order n (MathConstraint costas_array, CC-BY-4.0). Accepts any valid array. +Adapted from pilot/grader.py check_costas; adds the optional fixed entries (upstream partial assignment).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("x"), n, 0, n - 1, "x") + if sorted(x) != list(range(n)): + raise Invalid("x is not a permutation of 0..n-1") + for name, i, v in inst.get("fixed", []): + if x[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + vecs = set() + for i, j in itertools.combinations(range(n), 2): + d = (j - i, x[j] - x[i]) + if d in vecs: + raise Invalid(f"repeated displacement vector {d}") + vecs.add(d) + return None, {} diff --git a/tasks/construct-mc-costas-array-l1-s1/tests/instance.json b/tasks/construct-mc-costas-array-l1-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..064e9d1f005c4000861f2894fa7b367cbebc0468 --- /dev/null +++ b/tasks/construct-mc-costas-array-l1-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 5, "fixed": [["x", 2, 3]], "family": "mc_costas_array", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-costas-array-l1-s1/tests/run.py b/tasks/construct-mc-costas-array-l1-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-costas-array-l1-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-costas-array-l1-s1/tests/test.sh b/tasks/construct-mc-costas-array-l1-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-costas-array-l1-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-costas-array-l5-s0/environment/Dockerfile b/tasks/construct-mc-costas-array-l5-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-costas-array-l5-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-costas-array-l5-s0/environment/instance.json b/tasks/construct-mc-costas-array-l5-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..60ac081b614907ec4787659d62223b1a8fb0d3f4 --- /dev/null +++ b/tasks/construct-mc-costas-array-l5-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 21, "fixed": [], "family": "mc_costas_array", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-costas-array-l5-s0/solution/solve.sh b/tasks/construct-mc-costas-array-l5-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d600cde8ea445aa566953499fc95f292e4de3099 --- /dev/null +++ b/tasks/construct-mc-costas-array-l5-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [12, 10, 5, 4, 13, 1, 17, 11, 19, 16, 20, 7, 9, 14, 15, 6, 18, 2, 8, 0, 3]} +RLMATH_EOF diff --git a/tasks/construct-mc-costas-array-l5-s0/tests/check.py b/tasks/construct-mc-costas-array-l5-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c86323a5b639b23787ecd4d5f358b986bbd91b6c --- /dev/null +++ b/tasks/construct-mc-costas-array-l5-s0/tests/check.py @@ -0,0 +1,22 @@ +"""Costas array of order n (MathConstraint costas_array, CC-BY-4.0). Accepts any valid array. +Adapted from pilot/grader.py check_costas; adds the optional fixed entries (upstream partial assignment).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("x"), n, 0, n - 1, "x") + if sorted(x) != list(range(n)): + raise Invalid("x is not a permutation of 0..n-1") + for name, i, v in inst.get("fixed", []): + if x[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + vecs = set() + for i, j in itertools.combinations(range(n), 2): + d = (j - i, x[j] - x[i]) + if d in vecs: + raise Invalid(f"repeated displacement vector {d}") + vecs.add(d) + return None, {} diff --git a/tasks/construct-mc-costas-array-l5-s0/tests/instance.json b/tasks/construct-mc-costas-array-l5-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..60ac081b614907ec4787659d62223b1a8fb0d3f4 --- /dev/null +++ b/tasks/construct-mc-costas-array-l5-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 21, "fixed": [], "family": "mc_costas_array", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-costas-array-l5-s0/tests/run.py b/tasks/construct-mc-costas-array-l5-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-costas-array-l5-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-costas-array-l5-s0/tests/test.sh b/tasks/construct-mc-costas-array-l5-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-costas-array-l5-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-golomb-l2-s2/tests/check.py b/tasks/construct-mc-golomb-l2-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..84aedd6e33fee7271543bfa49ab05128e23c31ee --- /dev/null +++ b/tasks/construct-mc-golomb-l2-s2/tests/check.py @@ -0,0 +1,27 @@ +"""Golomb ruler with n marks and length <= L (MathConstraint golomb, CC-BY-4.0, reframed as a decision +problem with the target length stated). Accepts any valid ruler. +Upstream note: the upstream prompt states no length bound and its verifier re-solves the optimisation +model with the marks fixed, which returns OPTIMUM for any Golomb ruler, so any ruler (e.g. 0,1,3,7,15,..) +was accepted. Here the length bound is part of the instance and enforced.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, L = inst["n"], inst["max_length"] + a = int_list(ans.get("marks"), n, 0, L, "marks") + if a[0] != 0: + raise Invalid("first mark must be 0") + if any(a[i] >= a[i + 1] for i in range(n - 1)): + raise Invalid("marks must be strictly increasing") + for name, i, v in inst.get("fixed", []): + if a[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + seen = set() + for i, j in itertools.combinations(range(n), 2): + d = a[j] - a[i] + if d in seen: + raise Invalid(f"difference {d} occurs twice") + seen.add(d) + return None, {"length": a[-1]} diff --git a/tasks/construct-mc-golomb-l2-s2/tests/run.py b/tasks/construct-mc-golomb-l2-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-golomb-l2-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-graceful-graph-l4-s1/environment/Dockerfile b/tasks/construct-mc-graceful-graph-l4-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-graceful-graph-l4-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-graceful-graph-l4-s1/environment/instance.json b/tasks/construct-mc-graceful-graph-l4-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f2ef723935a63c10cc8c204e7e8b7623ffb77586 --- /dev/null +++ b/tasks/construct-mc-graceful-graph-l4-s1/environment/instance.json @@ -0,0 +1 @@ +{"k": 3, "p": 9, "num_vertices": 27, "edges": [[0, 1], [0, 2], [1, 2], [3, 4], [3, 5], [4, 5], [6, 7], [6, 8], [7, 8], [9, 10], [9, 11], [10, 11], [12, 13], [12, 14], [13, 14], [15, 16], [15, 17], [16, 17], [18, 19], [18, 20], [19, 20], [21, 22], [21, 23], [22, 23], [24, 25], [24, 26], [25, 26], [0, 3], [1, 4], [2, 5], [3, 6], [4, 7], [5, 8], [6, 9], [7, 10], [8, 11], [9, 12], [10, 13], [11, 14], [12, 15], [13, 16], [14, 17], [15, 18], [16, 19], [17, 20], [18, 21], [19, 22], [20, 23], [21, 24], [22, 25], [23, 26]], "fixed": [], "family": "mc_graceful_graph", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graceful-graph-l4-s1/solution/solve.sh b/tasks/construct-mc-graceful-graph-l4-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..11c72faa7d69d5c48cdc857900a9b8721301ef64 --- /dev/null +++ b/tasks/construct-mc-graceful-graph-l4-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"labels": [17, 29, 40, 42, 5, 20, 12, 31, 47, 46, 18, 8, 1, 4, 37, 2, 48, 6, 7, 16, 24, 50, 9, 3, 0, 49, 51]} +RLMATH_EOF diff --git a/tasks/construct-mc-graceful-graph-l4-s1/tests/check.py b/tasks/construct-mc-graceful-graph-l4-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f4d33af1d63c0495c3b32d34db6ae10f0fb45923 --- /dev/null +++ b/tasks/construct-mc-graceful-graph-l4-s1/tests/check.py @@ -0,0 +1,19 @@ +"""Graceful labelling of K_k x P_p (MathConstraint graceful_graph, CC-BY-4.0): distinct vertex labels in +0..m (m = number of edges) whose edge differences |l(u) - l(v)| are all distinct.""" +from run import Invalid, int_list + + +def check(inst, ans): + nv, edges = inst["num_vertices"], inst["edges"] + m = len(edges) + x = int_list(ans.get("labels"), nv, 0, m, "labels") + if len(set(x)) != nv: + raise Invalid("vertex labels must be distinct") + d = [abs(x[u] - x[v]) for u, v in edges] + if len(set(d)) != m: + raise Invalid("edge labels are not distinct") + seqs = {"labels": x, "d": d} + for name, i, v in inst.get("fixed", []): + if seqs[name][i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + return None, {} diff --git a/tasks/construct-mc-graceful-graph-l4-s1/tests/instance.json b/tasks/construct-mc-graceful-graph-l4-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f2ef723935a63c10cc8c204e7e8b7623ffb77586 --- /dev/null +++ b/tasks/construct-mc-graceful-graph-l4-s1/tests/instance.json @@ -0,0 +1 @@ +{"k": 3, "p": 9, "num_vertices": 27, "edges": [[0, 1], [0, 2], [1, 2], [3, 4], [3, 5], [4, 5], [6, 7], [6, 8], [7, 8], [9, 10], [9, 11], [10, 11], [12, 13], [12, 14], [13, 14], [15, 16], [15, 17], [16, 17], [18, 19], [18, 20], [19, 20], [21, 22], [21, 23], [22, 23], [24, 25], [24, 26], [25, 26], [0, 3], [1, 4], [2, 5], [3, 6], [4, 7], [5, 8], [6, 9], [7, 10], [8, 11], [9, 12], [10, 13], [11, 14], [12, 15], [13, 16], [14, 17], [15, 18], [16, 19], [17, 20], [18, 21], [19, 22], [20, 23], [21, 24], [22, 25], [23, 26]], "fixed": [], "family": "mc_graceful_graph", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graceful-graph-l4-s1/tests/run.py b/tasks/construct-mc-graceful-graph-l4-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-graceful-graph-l4-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-graceful-graph-l4-s1/tests/test.sh b/tasks/construct-mc-graceful-graph-l4-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-graceful-graph-l4-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-graph-k-coloring-l4-s0/environment/Dockerfile b/tasks/construct-mc-graph-k-coloring-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l4-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-graph-k-coloring-l4-s0/environment/instance.json b/tasks/construct-mc-graph-k-coloring-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0704ab6404cf8692a7bd5632cf22a2dfbc7c8fa0 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 60, "k": 4, "edges": [[0, 27], [0, 36], [0, 41], [0, 45], [1, 3], [1, 8], [1, 13], [1, 15], [1, 22], [1, 28], [1, 29], [1, 30], [1, 32], [1, 43], [1, 50], [1, 52], [1, 55], [2, 10], [2, 11], [2, 15], [2, 21], [2, 28], [2, 30], [2, 43], [2, 45], [3, 21], [3, 32], [3, 44], [3, 51], [4, 17], [4, 22], [4, 24], [4, 34], [4, 41], [4, 46], [4, 56], [5, 18], [5, 27], [5, 37], [5, 41], [5, 45], [5, 50], [6, 16], [6, 17], [6, 21], [6, 34], [6, 35], [6, 38], [6, 43], [6, 53], [7, 18], [7, 28], [7, 36], [7, 55], [7, 58], [8, 34], [8, 38], [8, 44], [8, 45], [8, 55], [8, 58], [9, 15], [9, 17], [9, 18], [9, 50], [9, 54], [10, 16], [10, 27], [10, 34], [10, 40], [11, 15], [11, 23], [11, 29], [11, 43], [11, 44], [11, 47], [11, 59], [12, 27], [12, 29], [12, 42], [12, 44], [12, 54], [12, 55], [13, 32], [13, 43], [13, 55], [13, 57], [14, 24], [14, 40], [14, 45], [14, 49], [15, 17], [15, 25], [15, 32], [15, 37], [16, 32], [16, 49], [16, 53], [17, 47], [17, 50], [17, 52], [17, 53], [18, 32], [18, 34], [18, 43], [19, 28], [19, 36], [19, 39], [19, 40], [19, 48], [19, 49], [19, 50], [20, 29], [20, 51], [20, 57], [20, 58], [21, 49], [21, 56], [22, 25], [22, 28], [22, 35], [22, 37], [22, 50], [23, 31], [23, 39], [24, 39], [24, 45], [24, 47], [24, 49], [24, 53], [24, 55], [25, 30], [25, 36], [26, 37], [26, 41], [26, 42], [26, 48], [26, 50], [26, 57], [26, 58], [27, 29], [27, 35], [27, 41], [27, 43], [28, 32], [28, 35], [28, 40], [28, 57], [29, 50], [29, 52], [29, 56], [30, 31], [30, 35], [30, 58], [31, 55], [31, 56], [32, 35], [33, 36], [33, 37], [33, 38], [33, 49], [33, 52], [34, 39], [34, 50], [34, 51], [34, 53], [35, 56], [36, 41], [36, 43], [37, 47], [37, 50], [37, 53], [37, 58], [39, 42], [39, 46], [40, 47], [40, 52], [41, 46], [41, 54], [41, 59], [42, 43], [42, 44], [42, 53], [42, 56], [44, 59], [45, 48], [45, 50], [45, 54], [46, 47], [46, 49], [46, 53], [46, 59], [47, 50], [47, 52], [48, 57], [49, 56], [49, 58], [51, 53], [51, 56], [51, 58]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l4-s0/solution/solve.sh b/tasks/construct-mc-graph-k-coloring-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b1f9118a3ec743ea6d0978b3d77538528cf31914 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l4-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [0, 2, 0, 0, 1, 0, 1, 0, 1, 0, 1, 2, 1, 0, 2, 1, 0, 2, 1, 2, 1, 2, 3, 0, 0, 0, 0, 2, 1, 0, 1, 2, 3, 0, 0, 0, 1, 2, 2, 1, 0, 3, 2, 3, 3, 3, 0, 3, 1, 1, 1, 2, 1, 3, 2, 3, 3, 2, 3, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-graph-k-coloring-l4-s0/tests/check.py b/tasks/construct-mc-graph-k-coloring-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2b5f38cd0c22ac1b4ba37c0d3ff0a34635f08854 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l4-s0/tests/check.py @@ -0,0 +1,11 @@ +"""Proper k-colouring of a given graph (MathConstraint graph_k_coloring, CC-BY-4.0). Any valid colouring.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + return None, {} diff --git a/tasks/construct-mc-graph-k-coloring-l4-s0/tests/instance.json b/tasks/construct-mc-graph-k-coloring-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0704ab6404cf8692a7bd5632cf22a2dfbc7c8fa0 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 60, "k": 4, "edges": [[0, 27], [0, 36], [0, 41], [0, 45], [1, 3], [1, 8], [1, 13], [1, 15], [1, 22], [1, 28], [1, 29], [1, 30], [1, 32], [1, 43], [1, 50], [1, 52], [1, 55], [2, 10], [2, 11], [2, 15], [2, 21], [2, 28], [2, 30], [2, 43], [2, 45], [3, 21], [3, 32], [3, 44], [3, 51], [4, 17], [4, 22], [4, 24], [4, 34], [4, 41], [4, 46], [4, 56], [5, 18], [5, 27], [5, 37], [5, 41], [5, 45], [5, 50], [6, 16], [6, 17], [6, 21], [6, 34], [6, 35], [6, 38], [6, 43], [6, 53], [7, 18], [7, 28], [7, 36], [7, 55], [7, 58], [8, 34], [8, 38], [8, 44], [8, 45], [8, 55], [8, 58], [9, 15], [9, 17], [9, 18], [9, 50], [9, 54], [10, 16], [10, 27], [10, 34], [10, 40], [11, 15], [11, 23], [11, 29], [11, 43], [11, 44], [11, 47], [11, 59], [12, 27], [12, 29], [12, 42], [12, 44], [12, 54], [12, 55], [13, 32], [13, 43], [13, 55], [13, 57], [14, 24], [14, 40], [14, 45], [14, 49], [15, 17], [15, 25], [15, 32], [15, 37], [16, 32], [16, 49], [16, 53], [17, 47], [17, 50], [17, 52], [17, 53], [18, 32], [18, 34], [18, 43], [19, 28], [19, 36], [19, 39], [19, 40], [19, 48], [19, 49], [19, 50], [20, 29], [20, 51], [20, 57], [20, 58], [21, 49], [21, 56], [22, 25], [22, 28], [22, 35], [22, 37], [22, 50], [23, 31], [23, 39], [24, 39], [24, 45], [24, 47], [24, 49], [24, 53], [24, 55], [25, 30], [25, 36], [26, 37], [26, 41], [26, 42], [26, 48], [26, 50], [26, 57], [26, 58], [27, 29], [27, 35], [27, 41], [27, 43], [28, 32], [28, 35], [28, 40], [28, 57], [29, 50], [29, 52], [29, 56], [30, 31], [30, 35], [30, 58], [31, 55], [31, 56], [32, 35], [33, 36], [33, 37], [33, 38], [33, 49], [33, 52], [34, 39], [34, 50], [34, 51], [34, 53], [35, 56], [36, 41], [36, 43], [37, 47], [37, 50], [37, 53], [37, 58], [39, 42], [39, 46], [40, 47], [40, 52], [41, 46], [41, 54], [41, 59], [42, 43], [42, 44], [42, 53], [42, 56], [44, 59], [45, 48], [45, 50], [45, 54], [46, 47], [46, 49], [46, 53], [46, 59], [47, 50], [47, 52], [48, 57], [49, 56], [49, 58], [51, 53], [51, 56], [51, 58]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l4-s0/tests/run.py b/tasks/construct-mc-graph-k-coloring-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l4-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-graph-k-coloring-l4-s0/tests/test.sh b/tasks/construct-mc-graph-k-coloring-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l4-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-hadamard-l4-s1/environment/Dockerfile b/tasks/construct-mc-hadamard-l4-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-hadamard-l4-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-hadamard-l4-s1/environment/instance.json b/tasks/construct-mc-hadamard-l4-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d507466f9c4089e53b3d88fbd39f03d9de39e035 --- /dev/null +++ b/tasks/construct-mc-hadamard-l4-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 35, "family": "mc_hadamard", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-hadamard-l4-s1/solution/solve.sh b/tasks/construct-mc-hadamard-l4-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..36e6d691b1ab11bb49d53c58075608c5ca745027 --- /dev/null +++ b/tasks/construct-mc-hadamard-l4-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [-1, -1, 1, -1, -1, 1, 1, -1, 1, -1, 1, -1, -1, -1, -1, 1, -1, -1, 1, 1, 1, -1, 1, 1, 1, 1, 1, -1, -1, -1, 1, 1, 1, -1, 1], "y": [-1, -1, 1, -1, -1, 1, 1, -1, 1, -1, 1, -1, -1, -1, -1, 1, -1, -1, 1, 1, 1, -1, 1, 1, 1, 1, 1, -1, -1, -1, 1, 1, 1, -1, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-hadamard-l4-s1/tests/check.py b/tasks/construct-mc-hadamard-l4-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..fc4b93160fd7473dd14935db9d712e52abdd00c2 --- /dev/null +++ b/tasks/construct-mc-hadamard-l4-s1/tests/check.py @@ -0,0 +1,18 @@ +"""Legendre pair of odd length n (MathConstraint hadamard, CC-BY-4.0): x, y in {-1,+1}^n with +sum(x) = sum(y) = 1 and PAF_x(k) + PAF_y(k) = -2 for k = 1..(n-1)/2 (periodic autocorrelation).""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("x"), n, -1, 1, "x") + y = int_list(ans.get("y"), n, -1, 1, "y") + if 0 in x or 0 in y: + raise Invalid("entries must be -1 or +1") + if sum(x) != 1 or sum(y) != 1: + raise Invalid("sum(x) and sum(y) must both equal 1") + for k in range(1, (n - 1) // 2 + 1): + p = sum(x[i] * x[(i + k) % n] for i in range(n)) + sum(y[i] * y[(i + k) % n] for i in range(n)) + if p != -2: + raise Invalid(f"PAF_x({k}) + PAF_y({k}) = {p}, need -2") + return None, {} diff --git a/tasks/construct-mc-hadamard-l4-s1/tests/instance.json b/tasks/construct-mc-hadamard-l4-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d507466f9c4089e53b3d88fbd39f03d9de39e035 --- /dev/null +++ b/tasks/construct-mc-hadamard-l4-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 35, "family": "mc_hadamard", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-hadamard-l4-s1/tests/run.py b/tasks/construct-mc-hadamard-l4-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-hadamard-l4-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-hadamard-l4-s1/tests/test.sh b/tasks/construct-mc-hadamard-l4-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-hadamard-l4-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-langford-l4-s0/environment/Dockerfile b/tasks/construct-mc-langford-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-langford-l4-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-langford-l4-s0/environment/instance.json b/tasks/construct-mc-langford-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ae970df95e999f02a342518de43c55d2aa24ae8e --- /dev/null +++ b/tasks/construct-mc-langford-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 24, "fixed": [], "family": "mc_langford", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-langford-l4-s0/solution/solve.sh b/tasks/construct-mc-langford-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b07ff4853e3e7bed98a87e7af1239e56826db660 --- /dev/null +++ b/tasks/construct-mc-langford-l4-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"seq": [20, 21, 13, 24, 12, 14, 8, 10, 17, 19, 22, 2, 18, 11, 2, 8, 13, 12, 10, 16, 14, 20, 23, 21, 9, 11, 17, 15, 24, 19, 7, 18, 6, 22, 9, 5, 16, 4, 7, 6, 3, 5, 4, 15, 3, 1, 23, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-langford-l4-s0/tests/check.py b/tasks/construct-mc-langford-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4672d7eacf321991933cb280d6c940f1c4a67935 --- /dev/null +++ b/tasks/construct-mc-langford-l4-s0/tests/check.py @@ -0,0 +1,17 @@ +"""Langford sequence L(2, n) (MathConstraint langford, CC-BY-4.0). Accepts any valid sequence.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + seq = int_list(ans.get("seq"), 2 * n, 1, n, "seq") + for v in range(1, n + 1): + pos = [i for i, s in enumerate(seq) if s == v] + if len(pos) != 2: + raise Invalid(f"value {v} occurs {len(pos)} times (need exactly 2)") + if pos[1] - pos[0] != v + 1: + raise Invalid(f"the two copies of {v} are {pos[1] - pos[0]} positions apart (need {v + 1})") + for name, i, v in inst.get("fixed", []): + if seq[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + return None, {} diff --git a/tasks/construct-mc-langford-l4-s0/tests/instance.json b/tasks/construct-mc-langford-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ae970df95e999f02a342518de43c55d2aa24ae8e --- /dev/null +++ b/tasks/construct-mc-langford-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 24, "fixed": [], "family": "mc_langford", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-langford-l4-s0/tests/run.py b/tasks/construct-mc-langford-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-langford-l4-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-langford-l4-s0/tests/test.sh b/tasks/construct-mc-langford-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-langford-l4-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-low-autocorrelation-l6-s5/environment/Dockerfile b/tasks/construct-mc-low-autocorrelation-l6-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l6-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-low-autocorrelation-l6-s5/environment/instance.json b/tasks/construct-mc-low-autocorrelation-l6-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a2c4bc16da78efb2a5fe6a6518d4e1a5bdcc7ea3 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l6-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 64, "bound": 328, "fixed": [], "family": "mc_low_autocorrelation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-low-autocorrelation-l6-s5/solution/solve.sh b/tasks/construct-mc-low-autocorrelation-l6-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c25430c35760456664b64a7e5e570443bcbe6d11 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l6-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"seq": [-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, -1, -1, -1, -1, 1, 1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1, 1, 1, -1, -1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, 1, 1, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-low-autocorrelation-l6-s5/tests/check.py b/tasks/construct-mc-low-autocorrelation-l6-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8456f7b1c0ff0c9fb4bc9ae5a49074c8afa7d1aa --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l6-s5/tests/check.py @@ -0,0 +1,20 @@ +"""+-1 sequence of length n with aperiodic autocorrelation energy sum_k C_k^2 <= bound +(MathConstraint low_autocorrelation, CC-BY-4.0). Exact integer arithmetic.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, bound = inst["n"], inst["bound"] + s = int_list(ans.get("seq"), n, -1, 1, "seq") + if any(v == 0 for v in s): + raise Invalid("entries must be -1 or +1") + c = [sum(s[i] * s[i + k] for i in range(n - k)) for k in range(1, n)] + e = sum(v * v for v in c) + # fixed values: seq[i] or c[k] (c[k] is the autocorrelation at shift k+1, as upstream) + seqs = {"seq": s, "c": c} + for name, i, v in inst.get("fixed", []): + if seqs[name][i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + if e > bound: + raise Invalid(f"energy {e} exceeds the bound {bound}") + return None, {"energy": e} diff --git a/tasks/construct-mc-low-autocorrelation-l6-s5/tests/instance.json b/tasks/construct-mc-low-autocorrelation-l6-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a2c4bc16da78efb2a5fe6a6518d4e1a5bdcc7ea3 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l6-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 64, "bound": 328, "fixed": [], "family": "mc_low_autocorrelation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-low-autocorrelation-l6-s5/tests/run.py b/tasks/construct-mc-low-autocorrelation-l6-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l6-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-low-autocorrelation-l6-s5/tests/test.sh b/tasks/construct-mc-low-autocorrelation-l6-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l6-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-magic-sequence-l1-s3/environment/Dockerfile b/tasks/construct-mc-magic-sequence-l1-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l1-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-magic-sequence-l1-s3/environment/instance.json b/tasks/construct-mc-magic-sequence-l1-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..91b5048648aae261692940d01b0c1f77d1d2aaed --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l1-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 5, "fixed": [], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l1-s3/solution/solve.sh b/tasks/construct-mc-magic-sequence-l1-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..09d927b408510c23053153ebab733352d4d59f28 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l1-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [2, 1, 2, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-magic-sequence-l1-s3/tests/check.py b/tasks/construct-mc-magic-sequence-l1-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..27f636ddd6cfe523924ae01c6b9f37ee392f0332 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l1-s3/tests/check.py @@ -0,0 +1,18 @@ +"""Magic sequence of length n: x[i] = number of occurrences of i in x (MathConstraint magic_sequence, +CC-BY-4.0). The property itself is checked (no stored answer).""" +from collections import Counter + +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("x"), n, 0, n, "x") + cnt = Counter(x) + for i in range(n): + if x[i] != cnt.get(i, 0): + raise Invalid(f"x[{i}] = {x[i]} but {i} occurs {cnt.get(i, 0)} times") + for name, i, v in inst.get("fixed", []): + if x[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + return None, {} diff --git a/tasks/construct-mc-magic-sequence-l1-s3/tests/instance.json b/tasks/construct-mc-magic-sequence-l1-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..91b5048648aae261692940d01b0c1f77d1d2aaed --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l1-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 5, "fixed": [], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l1-s3/tests/run.py b/tasks/construct-mc-magic-sequence-l1-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l1-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-magic-sequence-l1-s3/tests/test.sh b/tasks/construct-mc-magic-sequence-l1-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l1-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-magic-sequence-l5-s2/environment/Dockerfile b/tasks/construct-mc-magic-sequence-l5-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l5-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-magic-sequence-l5-s2/environment/instance.json b/tasks/construct-mc-magic-sequence-l5-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b12075440cc13449e11971092a90401a67329bbd --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l5-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 64, "fixed": [], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l5-s2/solution/solve.sh b/tasks/construct-mc-magic-sequence-l5-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..56db69cd7a4656952b2917ef0c59a052a425b724 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l5-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [60, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-magic-sequence-l5-s2/tests/check.py b/tasks/construct-mc-magic-sequence-l5-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..27f636ddd6cfe523924ae01c6b9f37ee392f0332 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l5-s2/tests/check.py @@ -0,0 +1,18 @@ +"""Magic sequence of length n: x[i] = number of occurrences of i in x (MathConstraint magic_sequence, +CC-BY-4.0). The property itself is checked (no stored answer).""" +from collections import Counter + +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("x"), n, 0, n, "x") + cnt = Counter(x) + for i in range(n): + if x[i] != cnt.get(i, 0): + raise Invalid(f"x[{i}] = {x[i]} but {i} occurs {cnt.get(i, 0)} times") + for name, i, v in inst.get("fixed", []): + if x[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + return None, {} diff --git a/tasks/construct-mc-magic-sequence-l5-s2/tests/instance.json b/tasks/construct-mc-magic-sequence-l5-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b12075440cc13449e11971092a90401a67329bbd --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l5-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 64, "fixed": [], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l5-s2/tests/run.py b/tasks/construct-mc-magic-sequence-l5-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l5-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-magic-sequence-l5-s2/tests/test.sh b/tasks/construct-mc-magic-sequence-l5-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l5-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-magic-sequence-l5-s5/environment/Dockerfile b/tasks/construct-mc-magic-sequence-l5-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l5-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-magic-sequence-l5-s5/environment/instance.json b/tasks/construct-mc-magic-sequence-l5-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7b698f1f262c8d99b834da015ef294e066c31336 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l5-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 100, "fixed": [], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l5-s5/solution/solve.sh b/tasks/construct-mc-magic-sequence-l5-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..26371d10da5046042f06e910a9712450c4dcb5aa --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l5-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [96, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-magic-sequence-l5-s5/tests/check.py b/tasks/construct-mc-magic-sequence-l5-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..27f636ddd6cfe523924ae01c6b9f37ee392f0332 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l5-s5/tests/check.py @@ -0,0 +1,18 @@ +"""Magic sequence of length n: x[i] = number of occurrences of i in x (MathConstraint magic_sequence, +CC-BY-4.0). The property itself is checked (no stored answer).""" +from collections import Counter + +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("x"), n, 0, n, "x") + cnt = Counter(x) + for i in range(n): + if x[i] != cnt.get(i, 0): + raise Invalid(f"x[{i}] = {x[i]} but {i} occurs {cnt.get(i, 0)} times") + for name, i, v in inst.get("fixed", []): + if x[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + return None, {} diff --git a/tasks/construct-mc-magic-sequence-l5-s5/tests/instance.json b/tasks/construct-mc-magic-sequence-l5-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7b698f1f262c8d99b834da015ef294e066c31336 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l5-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 100, "fixed": [], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l5-s5/tests/run.py b/tasks/construct-mc-magic-sequence-l5-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l5-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-magic-sequence-l5-s5/tests/test.sh b/tasks/construct-mc-magic-sequence-l5-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l5-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-clique-l2-s3/environment/Dockerfile b/tasks/construct-mc-max-clique-l2-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-clique-l2-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-clique-l2-s3/environment/instance.json b/tasks/construct-mc-max-clique-l2-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..568eb0065587e066c64fe6708510a15e96ab115d --- /dev/null +++ b/tasks/construct-mc-max-clique-l2-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 40, "k": 8, "edges": [[0, 3], [0, 6], [0, 7], [0, 8], [0, 14], [0, 16], [0, 21], [0, 22], [0, 24], [0, 31], [0, 32], [0, 33], [0, 35], [0, 36], [0, 37], [1, 2], [1, 5], [1, 8], [1, 16], [1, 21], [1, 22], [1, 23], [1, 29], [1, 30], [1, 33], [1, 34], [1, 36], [1, 37], [1, 39], [2, 3], [2, 4], [2, 5], [2, 7], [2, 11], [2, 12], [2, 13], [2, 17], [2, 22], [2, 28], [2, 36], [2, 38], [2, 39], [3, 4], [3, 6], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 14], [3, 17], [3, 18], [3, 21], [3, 22], [3, 25], [3, 27], [3, 34], [3, 37], [3, 38], [4, 6], [4, 7], [4, 9], [4, 13], [4, 15], [4, 17], [4, 18], [4, 20], [4, 21], [4, 22], [4, 23], [4, 26], [4, 27], [4, 32], [4, 33], [4, 34], [4, 35], [4, 38], [5, 6], [5, 7], [5, 8], [5, 10], [5, 12], [5, 15], [5, 16], [5, 17], [5, 18], [5, 21], [5, 22], [5, 23], [5, 24], [5, 25], [5, 26], [5, 27], [5, 28], [5, 30], [5, 32], [5, 33], [5, 34], [5, 35], [5, 36], [5, 37], [6, 7], [6, 8], [6, 11], [6, 12], [6, 14], [6, 16], [6, 17], [6, 18], [6, 19], [6, 21], [6, 22], [6, 23], [6, 25], [6, 26], [6, 27], [6, 28], [6, 31], [6, 32], [6, 33], [6, 34], [6, 35], [6, 36], [6, 37], [6, 38], [7, 10], [7, 13], [7, 14], [7, 15], [7, 17], [7, 19], [7, 23], [7, 26], [7, 27], [7, 29], [7, 33], [7, 34], [7, 36], [7, 37], [8, 9], [8, 11], [8, 14], [8, 15], [8, 18], [8, 19], [8, 20], [8, 21], [8, 22], [8, 23], [8, 24], [8, 26], [8, 29], [8, 32], [8, 35], [8, 38], [8, 39], [9, 10], [9, 11], [9, 12], [9, 14], [9, 16], [9, 17], [9, 19], [9, 21], [9, 29], [9, 33], [10, 11], [10, 12], [10, 13], [10, 15], [10, 16], [10, 17], [10, 19], [10, 22], [10, 24], [10, 25], [10, 26], [10, 27], [10, 28], [10, 32], [10, 33], [10, 35], [10, 37], [11, 15], [11, 16], [11, 20], [11, 21], [11, 23], [11, 26], [11, 27], [11, 28], [11, 30], [11, 31], [11, 32], [11, 35], [11, 39], [12, 14], [12, 16], [12, 20], [12, 24], [12, 26], [12, 27], [12, 28], [12, 31], [12, 32], [12, 34], [12, 35], [12, 36], [12, 38], [13, 16], [13, 19], [13, 20], [13, 22], [13, 23], [13, 29], [13, 31], [13, 33], [13, 35], [13, 37], [13, 38], [14, 15], [14, 17], [14, 20], [14, 21], [14, 22], [14, 23], [14, 24], [14, 28], [14, 30], [14, 31], [14, 34], [14, 35], [14, 36], [15, 16], [15, 18], [15, 24], [15, 26], [15, 27], [15, 28], [15, 29], [15, 30], [15, 31], [15, 35], [15, 36], [15, 37], [15, 38], [15, 39], [16, 17], [16, 21], [16, 23], [16, 28], [16, 29], [16, 35], [17, 21], [17, 23], [17, 26], [17, 27], [17, 32], [17, 34], [17, 36], [17, 37], [17, 38], [18, 19], [18, 20], [18, 21], [18, 22], [18, 23], [18, 25], [18, 26], [18, 27], [18, 29], [18, 30], [18, 33], [18, 34], [18, 36], [18, 37], [18, 38], [18, 39], [19, 20], [19, 22], [19, 23], [19, 25], [19, 29], [19, 31], [19, 35], [19, 37], [19, 38], [20, 21], [20, 23], [20, 26], [20, 28], [20, 30], [20, 32], [20, 33], [20, 35], [20, 36], [20, 37], [21, 22], [21, 24], [21, 25], [21, 26], [21, 27], [21, 29], [21, 33], [21, 34], [21, 36], [21, 38], [22, 24], [22, 26], [22, 27], [22, 28], [22, 32], [22, 33], [22, 37], [22, 38], [22, 39], [23, 24], [23, 25], [23, 26], [23, 27], [23, 29], [23, 31], [23, 32], [23, 33], [23, 35], [23, 36], [23, 37], [23, 39], [24, 27], [24, 30], [24, 31], [24, 32], [24, 33], [24, 34], [24, 35], [24, 36], [24, 37], [24, 38], [25, 30], [25, 31], [25, 34], [25, 35], [25, 36], [25, 38], [25, 39], [26, 28], [26, 29], [26, 30], [26, 31], [26, 32], [26, 36], [26, 38], [27, 31], [27, 33], [27, 35], [27, 36], [27, 38], [27, 39], [28, 30], [28, 31], [28, 32], [28, 33], [28, 34], [28, 35], [28, 36], [28, 37], [29, 35], [29, 36], [29, 37], [29, 39], [30, 31], [30, 32], [30, 34], [30, 38], [31, 32], [31, 33], [31, 36], [31, 37], [32, 34], [32, 36], [33, 34], [33, 38], [33, 39], [34, 36], [34, 38], [34, 39], [35, 37], [35, 39], [36, 38], [37, 39], [38, 39]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l2-s3/solution/solve.sh b/tasks/construct-mc-max-clique-l2-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..42c7d3a551cdeb08f98c23574d824d6bc21ab4f5 --- /dev/null +++ b/tasks/construct-mc-max-clique-l2-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [3, 4, 6, 18, 21, 22, 27, 38]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-clique-l2-s3/tests/check.py b/tasks/construct-mc-max-clique-l2-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3f70dbd5b155a3514c2102aa4ad460201495210 --- /dev/null +++ b/tasks/construct-mc-max-clique-l2-s3/tests/check.py @@ -0,0 +1,18 @@ +"""Clique of size >= k in a given graph (MathConstraint max_clique decision version, CC-BY-4.0).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("clique"), None, 0, n - 1, "clique") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) < k: + raise Invalid(f"clique has {len(S)} vertices, need at least {k}") + E = {(u, v) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(S), 2): + if (u, v) not in E: + raise Invalid(f"vertices {u} and {v} are not adjacent") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-max-clique-l2-s3/tests/instance.json b/tasks/construct-mc-max-clique-l2-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..568eb0065587e066c64fe6708510a15e96ab115d --- /dev/null +++ b/tasks/construct-mc-max-clique-l2-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 40, "k": 8, "edges": [[0, 3], [0, 6], [0, 7], [0, 8], [0, 14], [0, 16], [0, 21], [0, 22], [0, 24], [0, 31], [0, 32], [0, 33], [0, 35], [0, 36], [0, 37], [1, 2], [1, 5], [1, 8], [1, 16], [1, 21], [1, 22], [1, 23], [1, 29], [1, 30], [1, 33], [1, 34], [1, 36], [1, 37], [1, 39], [2, 3], [2, 4], [2, 5], [2, 7], [2, 11], [2, 12], [2, 13], [2, 17], [2, 22], [2, 28], [2, 36], [2, 38], [2, 39], [3, 4], [3, 6], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 14], [3, 17], [3, 18], [3, 21], [3, 22], [3, 25], [3, 27], [3, 34], [3, 37], [3, 38], [4, 6], [4, 7], [4, 9], [4, 13], [4, 15], [4, 17], [4, 18], [4, 20], [4, 21], [4, 22], [4, 23], [4, 26], [4, 27], [4, 32], [4, 33], [4, 34], [4, 35], [4, 38], [5, 6], [5, 7], [5, 8], [5, 10], [5, 12], [5, 15], [5, 16], [5, 17], [5, 18], [5, 21], [5, 22], [5, 23], [5, 24], [5, 25], [5, 26], [5, 27], [5, 28], [5, 30], [5, 32], [5, 33], [5, 34], [5, 35], [5, 36], [5, 37], [6, 7], [6, 8], [6, 11], [6, 12], [6, 14], [6, 16], [6, 17], [6, 18], [6, 19], [6, 21], [6, 22], [6, 23], [6, 25], [6, 26], [6, 27], [6, 28], [6, 31], [6, 32], [6, 33], [6, 34], [6, 35], [6, 36], [6, 37], [6, 38], [7, 10], [7, 13], [7, 14], [7, 15], [7, 17], [7, 19], [7, 23], [7, 26], [7, 27], [7, 29], [7, 33], [7, 34], [7, 36], [7, 37], [8, 9], [8, 11], [8, 14], [8, 15], [8, 18], [8, 19], [8, 20], [8, 21], [8, 22], [8, 23], [8, 24], [8, 26], [8, 29], [8, 32], [8, 35], [8, 38], [8, 39], [9, 10], [9, 11], [9, 12], [9, 14], [9, 16], [9, 17], [9, 19], [9, 21], [9, 29], [9, 33], [10, 11], [10, 12], [10, 13], [10, 15], [10, 16], [10, 17], [10, 19], [10, 22], [10, 24], [10, 25], [10, 26], [10, 27], [10, 28], [10, 32], [10, 33], [10, 35], [10, 37], [11, 15], [11, 16], [11, 20], [11, 21], [11, 23], [11, 26], [11, 27], [11, 28], [11, 30], [11, 31], [11, 32], [11, 35], [11, 39], [12, 14], [12, 16], [12, 20], [12, 24], [12, 26], [12, 27], [12, 28], [12, 31], [12, 32], [12, 34], [12, 35], [12, 36], [12, 38], [13, 16], [13, 19], [13, 20], [13, 22], [13, 23], [13, 29], [13, 31], [13, 33], [13, 35], [13, 37], [13, 38], [14, 15], [14, 17], [14, 20], [14, 21], [14, 22], [14, 23], [14, 24], [14, 28], [14, 30], [14, 31], [14, 34], [14, 35], [14, 36], [15, 16], [15, 18], [15, 24], [15, 26], [15, 27], [15, 28], [15, 29], [15, 30], [15, 31], [15, 35], [15, 36], [15, 37], [15, 38], [15, 39], [16, 17], [16, 21], [16, 23], [16, 28], [16, 29], [16, 35], [17, 21], [17, 23], [17, 26], [17, 27], [17, 32], [17, 34], [17, 36], [17, 37], [17, 38], [18, 19], [18, 20], [18, 21], [18, 22], [18, 23], [18, 25], [18, 26], [18, 27], [18, 29], [18, 30], [18, 33], [18, 34], [18, 36], [18, 37], [18, 38], [18, 39], [19, 20], [19, 22], [19, 23], [19, 25], [19, 29], [19, 31], [19, 35], [19, 37], [19, 38], [20, 21], [20, 23], [20, 26], [20, 28], [20, 30], [20, 32], [20, 33], [20, 35], [20, 36], [20, 37], [21, 22], [21, 24], [21, 25], [21, 26], [21, 27], [21, 29], [21, 33], [21, 34], [21, 36], [21, 38], [22, 24], [22, 26], [22, 27], [22, 28], [22, 32], [22, 33], [22, 37], [22, 38], [22, 39], [23, 24], [23, 25], [23, 26], [23, 27], [23, 29], [23, 31], [23, 32], [23, 33], [23, 35], [23, 36], [23, 37], [23, 39], [24, 27], [24, 30], [24, 31], [24, 32], [24, 33], [24, 34], [24, 35], [24, 36], [24, 37], [24, 38], [25, 30], [25, 31], [25, 34], [25, 35], [25, 36], [25, 38], [25, 39], [26, 28], [26, 29], [26, 30], [26, 31], [26, 32], [26, 36], [26, 38], [27, 31], [27, 33], [27, 35], [27, 36], [27, 38], [27, 39], [28, 30], [28, 31], [28, 32], [28, 33], [28, 34], [28, 35], [28, 36], [28, 37], [29, 35], [29, 36], [29, 37], [29, 39], [30, 31], [30, 32], [30, 34], [30, 38], [31, 32], [31, 33], [31, 36], [31, 37], [32, 34], [32, 36], [33, 34], [33, 38], [33, 39], [34, 36], [34, 38], [34, 39], [35, 37], [35, 39], [36, 38], [37, 39], [38, 39]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l2-s3/tests/run.py b/tasks/construct-mc-max-clique-l2-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-clique-l2-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-clique-l2-s3/tests/test.sh b/tasks/construct-mc-max-clique-l2-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-clique-l2-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-clique-l2-s4/environment/Dockerfile b/tasks/construct-mc-max-clique-l2-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-clique-l2-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-clique-l2-s4/environment/instance.json b/tasks/construct-mc-max-clique-l2-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..91bb68e55ba395aadf5ecce52952b5941d5eb9f2 --- /dev/null +++ b/tasks/construct-mc-max-clique-l2-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 40, "k": 8, "edges": [[0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 11], [0, 12], [0, 13], [0, 15], [0, 16], [0, 19], [0, 27], [0, 28], [0, 30], [0, 35], [0, 37], [0, 38], [1, 2], [1, 3], [1, 4], [1, 7], [1, 9], [1, 10], [1, 14], [1, 20], [1, 23], [1, 26], [1, 29], [1, 30], [1, 31], [1, 32], [1, 34], [1, 35], [1, 36], [1, 37], [1, 39], [2, 3], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 12], [2, 13], [2, 16], [2, 17], [2, 18], [2, 20], [2, 27], [2, 28], [2, 31], [2, 33], [2, 34], [2, 39], [3, 5], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 18], [3, 19], [3, 20], [3, 21], [3, 25], [3, 28], [3, 29], [3, 31], [3, 34], [3, 35], [3, 37], [3, 39], [4, 5], [4, 6], [4, 10], [4, 11], [4, 12], [4, 14], [4, 15], [4, 16], [4, 17], [4, 19], [4, 20], [4, 22], [4, 28], [4, 29], [4, 31], [4, 34], [4, 35], [4, 36], [4, 37], [4, 38], [4, 39], [5, 6], [5, 8], [5, 14], [5, 20], [5, 21], [5, 24], [5, 27], [5, 28], [5, 29], [5, 32], [5, 35], [5, 36], [5, 37], [5, 39], [6, 8], [6, 10], [6, 11], [6, 12], [6, 13], [6, 14], [6, 15], [6, 17], [6, 18], [6, 19], [6, 21], [6, 22], [6, 23], [6, 24], [6, 26], [6, 27], [6, 29], [6, 30], [6, 31], [6, 34], [6, 35], [6, 38], [6, 39], [7, 9], [7, 11], [7, 20], [7, 23], [7, 24], [7, 26], [7, 27], [7, 29], [7, 31], [7, 33], [7, 34], [7, 35], [7, 36], [7, 38], [7, 39], [8, 14], [8, 16], [8, 17], [8, 19], [8, 21], [8, 22], [8, 23], [8, 27], [8, 28], [8, 33], [8, 38], [9, 10], [9, 11], [9, 12], [9, 13], [9, 15], [9, 16], [9, 18], [9, 19], [9, 20], [9, 21], [9, 22], [9, 23], [9, 24], [9, 28], [9, 29], [9, 30], [9, 33], [9, 35], [9, 36], [10, 11], [10, 14], [10, 15], [10, 16], [10, 17], [10, 18], [10, 23], [10, 27], [10, 32], [10, 33], [10, 34], [10, 36], [10, 37], [10, 38], [10, 39], [11, 12], [11, 13], [11, 15], [11, 17], [11, 18], [11, 20], [11, 22], [11, 24], [11, 25], [11, 28], [11, 29], [11, 30], [11, 33], [11, 35], [11, 36], [12, 13], [12, 14], [12, 15], [12, 16], [12, 17], [12, 18], [12, 19], [12, 20], [12, 22], [12, 24], [12, 26], [12, 27], [12, 28], [12, 29], [12, 30], [12, 31], [12, 32], [12, 33], [12, 34], [12, 36], [12, 37], [12, 38], [13, 14], [13, 16], [13, 17], [13, 18], [13, 19], [13, 20], [13, 22], [13, 23], [13, 24], [13, 25], [13, 27], [13, 31], [13, 33], [13, 36], [13, 38], [14, 15], [14, 18], [14, 20], [14, 24], [14, 25], [14, 26], [14, 29], [14, 30], [14, 31], [14, 34], [14, 36], [14, 39], [15, 18], [15, 19], [15, 20], [15, 23], [15, 27], [15, 28], [15, 30], [15, 31], [15, 33], [15, 34], [15, 38], [16, 18], [16, 20], [16, 22], [16, 24], [16, 25], [16, 26], [16, 27], [16, 29], [16, 32], [16, 33], [16, 36], [16, 39], [17, 18], [17, 21], [17, 22], [17, 23], [17, 25], [17, 26], [17, 29], [17, 32], [17, 35], [17, 38], [17, 39], [18, 19], [18, 21], [18, 22], [18, 23], [18, 24], [18, 29], [18, 34], [18, 35], [18, 36], [18, 37], [19, 20], [19, 22], [19, 24], [19, 27], [19, 28], [19, 30], [19, 33], [19, 36], [19, 37], [20, 24], [20, 26], [20, 27], [20, 28], [20, 29], [20, 31], [20, 32], [20, 33], [20, 35], [20, 36], [20, 37], [21, 23], [21, 24], [21, 25], [21, 27], [21, 28], [21, 29], [21, 31], [21, 33], [21, 34], [21, 37], [21, 38], [21, 39], [22, 24], [22, 28], [22, 29], [22, 33], [22, 34], [22, 36], [23, 24], [23, 26], [23, 27], [23, 31], [23, 32], [23, 33], [23, 35], [23, 39], [24, 25], [24, 28], [24, 30], [24, 33], [24, 35], [24, 36], [24, 38], [25, 29], [25, 30], [25, 32], [25, 33], [25, 36], [26, 29], [26, 30], [26, 32], [26, 33], [26, 37], [27, 29], [27, 31], [27, 32], [27, 33], [27, 34], [27, 36], [27, 39], [28, 29], [28, 30], [28, 31], [28, 33], [28, 35], [28, 36], [28, 39], [29, 31], [29, 32], [29, 33], [29, 36], [29, 37], [29, 38], [30, 31], [30, 32], [30, 33], [30, 34], [30, 36], [30, 38], [31, 32], [31, 34], [31, 36], [31, 38], [31, 39], [32, 34], [32, 36], [32, 37], [32, 38], [33, 35], [33, 38], [33, 39], [34, 35], [34, 38], [35, 37], [35, 38], [35, 39], [36, 37], [36, 38], [36, 39], [37, 39], [38, 39]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l2-s4/solution/solve.sh b/tasks/construct-mc-max-clique-l2-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b161f2048f59d7fcbdb1b74823fcd8aa5cbeb262 --- /dev/null +++ b/tasks/construct-mc-max-clique-l2-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [9, 12, 13, 16, 18, 22, 24, 36]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-clique-l2-s4/tests/check.py b/tasks/construct-mc-max-clique-l2-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3f70dbd5b155a3514c2102aa4ad460201495210 --- /dev/null +++ b/tasks/construct-mc-max-clique-l2-s4/tests/check.py @@ -0,0 +1,18 @@ +"""Clique of size >= k in a given graph (MathConstraint max_clique decision version, CC-BY-4.0).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("clique"), None, 0, n - 1, "clique") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) < k: + raise Invalid(f"clique has {len(S)} vertices, need at least {k}") + E = {(u, v) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(S), 2): + if (u, v) not in E: + raise Invalid(f"vertices {u} and {v} are not adjacent") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-max-clique-l2-s4/tests/instance.json b/tasks/construct-mc-max-clique-l2-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..91bb68e55ba395aadf5ecce52952b5941d5eb9f2 --- /dev/null +++ b/tasks/construct-mc-max-clique-l2-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 40, "k": 8, "edges": [[0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 11], [0, 12], [0, 13], [0, 15], [0, 16], [0, 19], [0, 27], [0, 28], [0, 30], [0, 35], [0, 37], [0, 38], [1, 2], [1, 3], [1, 4], [1, 7], [1, 9], [1, 10], [1, 14], [1, 20], [1, 23], [1, 26], [1, 29], [1, 30], [1, 31], [1, 32], [1, 34], [1, 35], [1, 36], [1, 37], [1, 39], [2, 3], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 12], [2, 13], [2, 16], [2, 17], [2, 18], [2, 20], [2, 27], [2, 28], [2, 31], [2, 33], [2, 34], [2, 39], [3, 5], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 18], [3, 19], [3, 20], [3, 21], [3, 25], [3, 28], [3, 29], [3, 31], [3, 34], [3, 35], [3, 37], [3, 39], [4, 5], [4, 6], [4, 10], [4, 11], [4, 12], [4, 14], [4, 15], [4, 16], [4, 17], [4, 19], [4, 20], [4, 22], [4, 28], [4, 29], [4, 31], [4, 34], [4, 35], [4, 36], [4, 37], [4, 38], [4, 39], [5, 6], [5, 8], [5, 14], [5, 20], [5, 21], [5, 24], [5, 27], [5, 28], [5, 29], [5, 32], [5, 35], [5, 36], [5, 37], [5, 39], [6, 8], [6, 10], [6, 11], [6, 12], [6, 13], [6, 14], [6, 15], [6, 17], [6, 18], [6, 19], [6, 21], [6, 22], [6, 23], [6, 24], [6, 26], [6, 27], [6, 29], [6, 30], [6, 31], [6, 34], [6, 35], [6, 38], [6, 39], [7, 9], [7, 11], [7, 20], [7, 23], [7, 24], [7, 26], [7, 27], [7, 29], [7, 31], [7, 33], [7, 34], [7, 35], [7, 36], [7, 38], [7, 39], [8, 14], [8, 16], [8, 17], [8, 19], [8, 21], [8, 22], [8, 23], [8, 27], [8, 28], [8, 33], [8, 38], [9, 10], [9, 11], [9, 12], [9, 13], [9, 15], [9, 16], [9, 18], [9, 19], [9, 20], [9, 21], [9, 22], [9, 23], [9, 24], [9, 28], [9, 29], [9, 30], [9, 33], [9, 35], [9, 36], [10, 11], [10, 14], [10, 15], [10, 16], [10, 17], [10, 18], [10, 23], [10, 27], [10, 32], [10, 33], [10, 34], [10, 36], [10, 37], [10, 38], [10, 39], [11, 12], [11, 13], [11, 15], [11, 17], [11, 18], [11, 20], [11, 22], [11, 24], [11, 25], [11, 28], [11, 29], [11, 30], [11, 33], [11, 35], [11, 36], [12, 13], [12, 14], [12, 15], [12, 16], [12, 17], [12, 18], [12, 19], [12, 20], [12, 22], [12, 24], [12, 26], [12, 27], [12, 28], [12, 29], [12, 30], [12, 31], [12, 32], [12, 33], [12, 34], [12, 36], [12, 37], [12, 38], [13, 14], [13, 16], [13, 17], [13, 18], [13, 19], [13, 20], [13, 22], [13, 23], [13, 24], [13, 25], [13, 27], [13, 31], [13, 33], [13, 36], [13, 38], [14, 15], [14, 18], [14, 20], [14, 24], [14, 25], [14, 26], [14, 29], [14, 30], [14, 31], [14, 34], [14, 36], [14, 39], [15, 18], [15, 19], [15, 20], [15, 23], [15, 27], [15, 28], [15, 30], [15, 31], [15, 33], [15, 34], [15, 38], [16, 18], [16, 20], [16, 22], [16, 24], [16, 25], [16, 26], [16, 27], [16, 29], [16, 32], [16, 33], [16, 36], [16, 39], [17, 18], [17, 21], [17, 22], [17, 23], [17, 25], [17, 26], [17, 29], [17, 32], [17, 35], [17, 38], [17, 39], [18, 19], [18, 21], [18, 22], [18, 23], [18, 24], [18, 29], [18, 34], [18, 35], [18, 36], [18, 37], [19, 20], [19, 22], [19, 24], [19, 27], [19, 28], [19, 30], [19, 33], [19, 36], [19, 37], [20, 24], [20, 26], [20, 27], [20, 28], [20, 29], [20, 31], [20, 32], [20, 33], [20, 35], [20, 36], [20, 37], [21, 23], [21, 24], [21, 25], [21, 27], [21, 28], [21, 29], [21, 31], [21, 33], [21, 34], [21, 37], [21, 38], [21, 39], [22, 24], [22, 28], [22, 29], [22, 33], [22, 34], [22, 36], [23, 24], [23, 26], [23, 27], [23, 31], [23, 32], [23, 33], [23, 35], [23, 39], [24, 25], [24, 28], [24, 30], [24, 33], [24, 35], [24, 36], [24, 38], [25, 29], [25, 30], [25, 32], [25, 33], [25, 36], [26, 29], [26, 30], [26, 32], [26, 33], [26, 37], [27, 29], [27, 31], [27, 32], [27, 33], [27, 34], [27, 36], [27, 39], [28, 29], [28, 30], [28, 31], [28, 33], [28, 35], [28, 36], [28, 39], [29, 31], [29, 32], [29, 33], [29, 36], [29, 37], [29, 38], [30, 31], [30, 32], [30, 33], [30, 34], [30, 36], [30, 38], [31, 32], [31, 34], [31, 36], [31, 38], [31, 39], [32, 34], [32, 36], [32, 37], [32, 38], [33, 35], [33, 38], [33, 39], [34, 35], [34, 38], [35, 37], [35, 38], [35, 39], [36, 37], [36, 38], [36, 39], [37, 39], [38, 39]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l2-s4/tests/run.py b/tasks/construct-mc-max-clique-l2-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-clique-l2-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-clique-l2-s4/tests/test.sh b/tasks/construct-mc-max-clique-l2-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-clique-l2-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-clique-l6-s2/environment/Dockerfile b/tasks/construct-mc-max-clique-l6-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-clique-l6-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-clique-l6-s2/environment/instance.json b/tasks/construct-mc-max-clique-l6-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b3fe36937e31ecfb06b7cd510f5d51ae993c6db1 --- /dev/null +++ b/tasks/construct-mc-max-clique-l6-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 120, "k": 13, "edges": [[0, 2], [0, 3], [0, 4], [0, 7], [0, 8], [0, 11], [0, 12], [0, 15], [0, 16], [0, 20], [0, 26], [0, 29], [0, 30], [0, 34], [0, 36], [0, 37], [0, 38], [0, 39], [0, 40], [0, 41], [0, 43], [0, 45], [0, 47], [0, 49], [0, 51], [0, 52], [0, 54], [0, 57], [0, 59], [0, 61], [0, 62], [0, 65], [0, 68], [0, 70], [0, 71], [0, 73], [0, 75], [0, 76], [0, 78], [0, 82], [0, 86], [0, 92], [0, 95], [0, 96], [0, 97], [0, 98], [0, 102], [0, 105], [0, 107], [0, 109], [0, 110], [0, 111], [0, 113], [0, 116], [0, 118], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 13], [1, 14], [1, 15], [1, 19], [1, 20], [1, 21], [1, 22], [1, 24], [1, 25], [1, 27], [1, 28], [1, 29], [1, 35], [1, 38], [1, 42], [1, 43], [1, 44], [1, 45], [1, 48], [1, 49], [1, 51], [1, 54], [1, 55], [1, 56], [1, 58], [1, 60], [1, 62], [1, 65], [1, 70], [1, 72], [1, 76], [1, 83], [1, 84], [1, 85], [1, 88], [1, 90], [1, 92], [1, 94], [1, 95], [1, 99], [1, 101], [1, 102], [1, 106], [1, 113], [1, 116], [1, 119], [2, 4], [2, 12], [2, 15], [2, 23], [2, 26], [2, 27], [2, 29], [2, 30], [2, 31], [2, 33], [2, 34], [2, 35], [2, 37], [2, 39], [2, 40], [2, 43], [2, 44], [2, 47], [2, 50], [2, 52], [2, 53], [2, 56], [2, 57], [2, 59], [2, 64], [2, 69], [2, 70], [2, 71], [2, 72], [2, 73], [2, 74], [2, 75], [2, 77], [2, 81], [2, 83], [2, 91], [2, 97], [2, 98], [2, 99], [2, 100], [2, 101], [2, 102], [2, 104], [2, 105], [2, 107], [2, 109], [2, 110], [2, 111], [2, 112], [2, 113], [2, 115], [3, 5], [3, 6], [3, 11], [3, 12], [3, 13], [3, 14], [3, 16], [3, 18], [3, 20], [3, 21], [3, 22], [3, 23], [3, 24], [3, 26], [3, 28], [3, 30], [3, 32], [3, 33], [3, 35], [3, 38], [3, 39], [3, 40], [3, 41], [3, 43], [3, 44], [3, 45], [3, 47], [3, 51], [3, 52], [3, 54], [3, 55], [3, 57], [3, 58], [3, 61], [3, 66], [3, 68], [3, 70], [3, 76], [3, 77], [3, 80], [3, 81], [3, 82], [3, 84], [3, 85], [3, 87], [3, 89], [3, 90], [3, 91], [3, 97], [3, 99], [3, 101], [3, 102], [3, 104], [3, 111], [3, 112], [3, 115], [3, 119], [4, 7], [4, 9], [4, 13], [4, 14], [4, 22], [4, 23], [4, 26], [4, 29], [4, 32], [4, 33], [4, 35], [4, 36], [4, 37], [4, 38], [4, 39], [4, 40], [4, 41], [4, 42], [4, 43], [4, 44], [4, 46], [4, 47], [4, 48], [4, 50], [4, 51], [4, 52], [4, 53], [4, 54], [4, 55], [4, 57], [4, 62], [4, 66], [4, 69], [4, 71], [4, 72], [4, 73], [4, 76], [4, 77], [4, 78], [4, 79], [4, 80], [4, 81], [4, 84], [4, 86], [4, 87], [4, 90], [4, 92], [4, 95], [4, 101], [4, 102], [4, 103], [4, 105], [4, 106], [4, 109], [4, 111], [4, 112], [4, 113], [4, 114], [4, 115], [4, 117], [4, 118], [4, 119], [5, 10], [5, 11], [5, 13], [5, 15], [5, 16], [5, 18], [5, 19], [5, 21], [5, 22], [5, 24], [5, 25], [5, 30], [5, 31], [5, 32], [5, 33], [5, 34], [5, 37], [5, 41], [5, 42], [5, 43], [5, 44], [5, 47], [5, 48], [5, 50], [5, 55], [5, 57], [5, 61], [5, 63], [5, 64], [5, 65], [5, 66], [5, 69], [5, 70], [5, 72], [5, 73], [5, 74], [5, 77], [5, 78], [5, 84], [5, 85], [5, 87], [5, 88], [5, 90], [5, 94], [5, 95], [5, 96], [5, 97], [5, 98], [5, 100], [5, 101], [5, 102], [5, 103], [5, 107], [5, 108], [5, 109], [5, 110], [5, 113], [5, 114], [5, 116], [5, 117], [5, 118], [5, 119], [6, 9], [6, 12], [6, 13], [6, 15], [6, 16], [6, 18], [6, 19], [6, 21], [6, 23], [6, 24], [6, 27], [6, 28], [6, 30], [6, 31], [6, 34], [6, 35], [6, 36], [6, 38], [6, 39], [6, 40], [6, 42], [6, 45], [6, 46], [6, 47], [6, 49], [6, 52], [6, 56], [6, 57], [6, 58], [6, 59], [6, 60], [6, 61], [6, 67], [6, 71], [6, 72], [6, 73], [6, 75], [6, 76], [6, 78], [6, 81], [6, 82], [6, 91], [6, 93], [6, 95], [6, 97], [6, 98], [6, 99], [6, 103], [6, 104], [6, 105], [6, 106], [6, 108], [6, 111], [6, 112], [6, 116], [6, 117], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [7, 14], [7, 15], [7, 17], [7, 18], [7, 22], [7, 26], [7, 27], [7, 28], [7, 33], [7, 35], [7, 37], [7, 39], [7, 40], [7, 44], [7, 49], [7, 51], [7, 54], [7, 55], [7, 56], [7, 58], [7, 59], [7, 61], [7, 62], [7, 63], [7, 65], [7, 66], [7, 68], [7, 70], [7, 76], [7, 77], [7, 78], [7, 80], [7, 82], [7, 84], [7, 85], [7, 86], [7, 87], [7, 89], [7, 91], [7, 92], [7, 94], [7, 96], [7, 97], [7, 99], [7, 100], [7, 104], [7, 107], [7, 108], [7, 111], [7, 112], [7, 113], [7, 116], [7, 117], [8, 10], [8, 13], [8, 15], [8, 16], [8, 17], [8, 18], [8, 19], [8, 21], [8, 22], [8, 33], [8, 34], [8, 35], [8, 37], [8, 38], [8, 39], [8, 40], [8, 43], [8, 44], [8, 45], [8, 48], [8, 49], [8, 51], [8, 58], [8, 59], [8, 61], [8, 64], [8, 65], [8, 66], [8, 69], [8, 72], [8, 73], [8, 74], [8, 76], [8, 77], [8, 80], [8, 85], [8, 86], [8, 91], [8, 92], [8, 94], [8, 95], [8, 99], [8, 100], [8, 101], [8, 106], [8, 110], [8, 112], [8, 113], [8, 117], [8, 118], [9, 11], [9, 12], [9, 13], [9, 16], [9, 20], [9, 21], [9, 24], [9, 26], [9, 27], [9, 29], [9, 30], [9, 32], [9, 33], [9, 35], [9, 40], [9, 45], [9, 46], [9, 47], [9, 48], [9, 49], [9, 51], [9, 52], [9, 54], [9, 55], [9, 56], [9, 58], [9, 59], [9, 62], [9, 63], [9, 66], [9, 70], [9, 73], [9, 76], [9, 80], [9, 86], [9, 87], [9, 90], [9, 92], [9, 98], [9, 101], [9, 104], [9, 112], [9, 113], [9, 116], [9, 117], [9, 119], [10, 11], [10, 12], [10, 15], [10, 17], [10, 19], [10, 21], [10, 22], [10, 23], [10, 25], [10, 29], [10, 30], [10, 31], [10, 32], [10, 34], [10, 37], [10, 38], [10, 39], [10, 41], [10, 42], [10, 44], [10, 47], [10, 48], [10, 50], [10, 52], [10, 53], [10, 55], [10, 56], [10, 57], [10, 59], [10, 60], [10, 63], [10, 67], [10, 71], [10, 73], [10, 75], [10, 78], [10, 80], [10, 84], [10, 85], [10, 87], [10, 89], [10, 94], [10, 95], [10, 98], [10, 100], [10, 101], [10, 102], [10, 103], [10, 105], [10, 108], [10, 113], [10, 115], [10, 116], [10, 119], [11, 12], [11, 14], [11, 15], [11, 20], [11, 21], [11, 25], [11, 26], [11, 28], [11, 29], [11, 33], [11, 35], [11, 36], [11, 39], [11, 41], [11, 43], [11, 45], [11, 47], [11, 50], [11, 53], [11, 55], [11, 60], [11, 63], [11, 65], [11, 66], [11, 69], [11, 71], [11, 75], [11, 76], [11, 78], [11, 81], [11, 82], [11, 84], [11, 86], [11, 88], [11, 91], [11, 92], [11, 94], [11, 97], [11, 98], [11, 100], [11, 102], [11, 103], [11, 105], [11, 106], [11, 107], [11, 109], [11, 113], [11, 118], [11, 119], [12, 13], [12, 14], [12, 16], [12, 18], [12, 20], [12, 22], [12, 23], [12, 24], [12, 25], [12, 27], [12, 29], [12, 30], [12, 33], [12, 34], [12, 35], [12, 36], [12, 43], [12, 45], [12, 47], [12, 49], [12, 51], [12, 53], [12, 56], [12, 58], [12, 59], [12, 60], [12, 62], [12, 66], [12, 67], [12, 72], [12, 73], [12, 77], [12, 80], [12, 84], [12, 86], [12, 89], [12, 91], [12, 92], [12, 95], [12, 96], [12, 98], [12, 100], [12, 102], [12, 103], [12, 104], [12, 108], [12, 112], [12, 113], [12, 115], [12, 116], [12, 118], [12, 119], [13, 14], [13, 22], [13, 24], [13, 26], [13, 28], [13, 32], [13, 33], [13, 36], [13, 37], [13, 38], [13, 41], [13, 43], [13, 44], [13, 45], [13, 47], [13, 48], [13, 50], [13, 51], [13, 52], [13, 55], [13, 56], [13, 57], [13, 61], [13, 64], [13, 67], [13, 68], [13, 69], [13, 70], [13, 71], [13, 72], [13, 74], [13, 75], [13, 76], [13, 79], [13, 88], [13, 90], [13, 92], [13, 97], [13, 98], [13, 99], [13, 103], [13, 104], [13, 105], [13, 106], [13, 107], [13, 112], [13, 113], [13, 115], [13, 117], [14, 16], [14, 19], [14, 21], [14, 22], [14, 24], [14, 25], [14, 28], [14, 29], [14, 36], [14, 39], [14, 41], [14, 43], [14, 47], [14, 50], [14, 52], [14, 53], [14, 55], [14, 56], [14, 57], [14, 60], [14, 64], [14, 65], [14, 66], [14, 68], [14, 69], [14, 70], [14, 71], [14, 75], [14, 76], [14, 78], [14, 80], [14, 81], [14, 82], [14, 83], [14, 84], [14, 85], [14, 87], [14, 89], [14, 90], [14, 91], [14, 92], [14, 98], [14, 100], [14, 101], [14, 106], [14, 108], [14, 114], [14, 115], [14, 116], [14, 119], [15, 17], [15, 19], [15, 21], [15, 22], [15, 24], [15, 25], [15, 27], [15, 28], [15, 29], [15, 31], [15, 36], [15, 38], [15, 40], [15, 42], [15, 45], [15, 46], [15, 47], [15, 48], [15, 49], [15, 51], [15, 52], [15, 55], [15, 56], [15, 57], [15, 58], [15, 59], [15, 61], [15, 63], [15, 64], [15, 65], [15, 66], [15, 68], [15, 71], [15, 72], [15, 74], [15, 75], [15, 77], [15, 78], [15, 79], [15, 82], [15, 83], [15, 84], [15, 86], [15, 87], [15, 90], [15, 91], [15, 92], [15, 94], [15, 98], [15, 99], [15, 100], [15, 102], [15, 103], [15, 104], [15, 106], [15, 107], [15, 109], [15, 112], [15, 115], [15, 116], [15, 119], [16, 19], [16, 21], [16, 22], [16, 23], [16, 24], [16, 26], [16, 27], [16, 28], [16, 31], [16, 34], [16, 37], [16, 38], [16, 40], [16, 41], [16, 42], [16, 47], [16, 49], [16, 50], [16, 54], [16, 57], [16, 59], [16, 60], [16, 62], [16, 64], [16, 68], [16, 71], [16, 73], [16, 76], [16, 78], [16, 82], [16, 84], [16, 88], [16, 89], [16, 91], [16, 95], [16, 97], [16, 100], [16, 102], [16, 103], [16, 104], [16, 108], [16, 109], [16, 110], [16, 112], [16, 114], [16, 116], [16, 117], [16, 118], [17, 18], [17, 20], [17, 21], [17, 22], [17, 23], [17, 26], [17, 27], [17, 28], [17, 29], [17, 33], [17, 34], [17, 37], [17, 38], [17, 41], [17, 42], [17, 44], [17, 45], [17, 46], [17, 47], [17, 50], [17, 53], [17, 55], [17, 58], [17, 62], [17, 64], [17, 65], [17, 68], [17, 69], [17, 70], [17, 75], [17, 77], [17, 78], [17, 80], [17, 81], [17, 82], [17, 85], [17, 92], [17, 93], [17, 95], [17, 100], [17, 103], [17, 104], [17, 105], [17, 106], [17, 107], [17, 112], [17, 114], [17, 115], [17, 116], [17, 119], [18, 21], [18, 28], [18, 33], [18, 34], [18, 35], [18, 36], [18, 38], [18, 39], [18, 42], [18, 43], [18, 44], [18, 45], [18, 47], [18, 48], [18, 51], [18, 54], [18, 55], [18, 58], [18, 60], [18, 62], [18, 63], [18, 66], [18, 69], [18, 72], [18, 73], [18, 76], [18, 78], [18, 80], [18, 81], [18, 83], [18, 87], [18, 88], [18, 89], [18, 91], [18, 93], [18, 94], [18, 96], [18, 97], [18, 98], [18, 99], [18, 100], [18, 101], [18, 104], [18, 106], [18, 108], [18, 110], [18, 111], [18, 114], [19, 20], [19, 22], [19, 23], [19, 28], [19, 33], [19, 34], [19, 35], [19, 36], [19, 37], [19, 38], [19, 39], [19, 40], [19, 41], [19, 42], [19, 43], [19, 45], [19, 46], [19, 49], [19, 51], [19, 52], [19, 54], [19, 57], [19, 59], [19, 63], [19, 67], [19, 69], [19, 70], [19, 71], [19, 72], [19, 74], [19, 75], [19, 76], [19, 77], [19, 82], [19, 83], [19, 84], [19, 85], [19, 86], [19, 87], [19, 88], [19, 90], [19, 91], [19, 92], [19, 93], [19, 96], [19, 97], [19, 98], [19, 100], [19, 101], [19, 103], [19, 104], [19, 105], [19, 107], [19, 111], [19, 112], [19, 113], [19, 118], [19, 119], [20, 21], [20, 25], [20, 28], [20, 29], [20, 30], [20, 31], [20, 35], [20, 36], [20, 38], [20, 39], [20, 41], [20, 42], [20, 43], [20, 44], [20, 48], [20, 49], [20, 53], [20, 55], [20, 56], [20, 57], [20, 59], [20, 62], [20, 67], [20, 70], [20, 71], [20, 72], [20, 74], [20, 75], [20, 76], [20, 77], [20, 79], [20, 80], [20, 83], [20, 84], [20, 86], [20, 89], [20, 91], [20, 92], [20, 95], [20, 96], [20, 97], [20, 102], [20, 103], [20, 105], [20, 106], [20, 107], [20, 108], [20, 110], [20, 111], [20, 115], [20, 116], [20, 117], [20, 118], [20, 119], [21, 23], [21, 26], [21, 27], [21, 32], [21, 34], [21, 35], [21, 36], [21, 37], [21, 41], [21, 42], [21, 44], [21, 45], [21, 46], [21, 48], [21, 49], [21, 53], [21, 59], [21, 60], [21, 63], [21, 65], [21, 66], [21, 70], [21, 72], [21, 73], [21, 74], [21, 75], [21, 76], [21, 79], [21, 81], [21, 86], [21, 87], [21, 90], [21, 91], [21, 93], [21, 95], [21, 96], [21, 98], [21, 99], [21, 100], [21, 102], [21, 103], [21, 105], [21, 107], [21, 109], [21, 114], [21, 115], [21, 117], [21, 119], [22, 27], [22, 28], [22, 29], [22, 30], [22, 31], [22, 32], [22, 35], [22, 36], [22, 37], [22, 41], [22, 42], [22, 43], [22, 45], [22, 46], [22, 47], [22, 49], [22, 50], [22, 51], [22, 52], [22, 53], [22, 54], [22, 57], [22, 59], [22, 63], [22, 65], [22, 66], [22, 67], [22, 71], [22, 72], [22, 74], [22, 75], [22, 76], [22, 81], [22, 83], [22, 85], [22, 87], [22, 91], [22, 94], [22, 98], [22, 99], [22, 101], [22, 102], [22, 103], [22, 104], [22, 105], [22, 106], [22, 107], [22, 109], [22, 110], [22, 115], [22, 117], [22, 119], [23, 24], [23, 26], [23, 27], [23, 28], [23, 31], [23, 32], [23, 39], [23, 41], [23, 44], [23, 45], [23, 46], [23, 47], [23, 52], [23, 53], [23, 55], [23, 58], [23, 59], [23, 60], [23, 62], [23, 63], [23, 65], [23, 68], [23, 69], [23, 70], [23, 72], [23, 74], [23, 80], [23, 82], [23, 84], [23, 86], [23, 88], [23, 90], [23, 91], [23, 93], [23, 94], [23, 95], [23, 98], [23, 99], [23, 100], [23, 102], [23, 106], [23, 110], [23, 111], [23, 113], [23, 114], [23, 116], [23, 117], [23, 118], [23, 119], [24, 25], [24, 27], [24, 28], [24, 29], [24, 31], [24, 32], [24, 35], [24, 40], [24, 42], [24, 44], [24, 46], [24, 49], [24, 50], [24, 51], [24, 53], [24, 55], [24, 57], [24, 58], [24, 62], [24, 64], [24, 66], [24, 68], [24, 71], [24, 74], [24, 76], [24, 77], [24, 78], [24, 82], [24, 85], [24, 87], [24, 89], [24, 92], [24, 94], [24, 95], [24, 96], [24, 97], [24, 99], [24, 102], [24, 103], [24, 105], [24, 109], [24, 110], [24, 111], [24, 112], [24, 115], [24, 119], [25, 26], [25, 32], [25, 33], [25, 35], [25, 39], [25, 40], [25, 41], [25, 42], [25, 43], [25, 46], [25, 47], [25, 50], [25, 52], [25, 53], [25, 58], [25, 60], [25, 64], [25, 65], [25, 67], [25, 69], [25, 70], [25, 71], [25, 72], [25, 73], [25, 74], [25, 76], [25, 78], [25, 79], [25, 80], [25, 81], [25, 84], [25, 85], [25, 86], [25, 88], [25, 93], [25, 94], [25, 95], [25, 96], [25, 97], [25, 101], [25, 103], [25, 105], [25, 107], [25, 108], [25, 109], [25, 113], [25, 115], [25, 116], [25, 118], [26, 27], [26, 29], [26, 30], [26, 31], [26, 32], [26, 33], [26, 34], [26, 35], [26, 36], [26, 38], [26, 39], [26, 41], [26, 42], [26, 43], [26, 44], [26, 46], [26, 47], [26, 48], [26, 50], [26, 58], [26, 60], [26, 61], [26, 62], [26, 63], [26, 64], [26, 66], [26, 67], [26, 68], [26, 69], [26, 72], [26, 73], [26, 75], [26, 77], [26, 78], [26, 80], [26, 84], [26, 85], [26, 86], [26, 87], [26, 89], [26, 91], [26, 93], [26, 94], [26, 95], [26, 96], [26, 97], [26, 98], [26, 99], [26, 102], [26, 104], [26, 105], [26, 106], [26, 107], [26, 110], [26, 111], [26, 113], [26, 114], [26, 115], [26, 116], [26, 117], [27, 28], [27, 29], [27, 31], [27, 35], [27, 40], [27, 41], [27, 44], [27, 45], [27, 46], [27, 47], [27, 48], [27, 50], [27, 52], [27, 55], [27, 56], [27, 58], [27, 60], [27, 61], [27, 62], [27, 65], [27, 66], [27, 70], [27, 71], [27, 72], [27, 73], [27, 75], [27, 78], [27, 84], [27, 85], [27, 86], [27, 88], [27, 89], [27, 90], [27, 91], [27, 92], [27, 95], [27, 99], [27, 101], [27, 102], [27, 105], [27, 107], [27, 110], [27, 111], [27, 112], [27, 114], [27, 116], [27, 118], [27, 119], [28, 29], [28, 30], [28, 31], [28, 33], [28, 34], [28, 40], [28, 43], [28, 44], [28, 46], [28, 50], [28, 51], [28, 53], [28, 54], [28, 55], [28, 56], [28, 58], [28, 61], [28, 62], [28, 63], [28, 65], [28, 67], [28, 68], [28, 73], [28, 75], [28, 76], [28, 77], [28, 78], [28, 81], [28, 83], [28, 85], [28, 86], [28, 87], [28, 88], [28, 89], [28, 91], [28, 93], [28, 96], [28, 100], [28, 101], [28, 102], [28, 103], [28, 104], [28, 106], [28, 107], [28, 109], [28, 110], [28, 113], [28, 116], [28, 117], [28, 118], [28, 119], [29, 31], [29, 32], [29, 33], [29, 34], [29, 36], [29, 37], [29, 39], [29, 43], [29, 44], [29, 47], [29, 49], [29, 50], [29, 52], [29, 53], [29, 56], [29, 57], [29, 58], [29, 60], [29, 61], [29, 62], [29, 66], [29, 68], [29, 70], [29, 71], [29, 72], [29, 73], [29, 74], [29, 75], [29, 76], [29, 77], [29, 81], [29, 83], [29, 87], [29, 89], [29, 92], [29, 93], [29, 94], [29, 96], [29, 97], [29, 100], [29, 102], [29, 105], [29, 106], [29, 108], [29, 110], [29, 113], [29, 114], [29, 116], [29, 117], [29, 118], [30, 31], [30, 33], [30, 34], [30, 35], [30, 37], [30, 38], [30, 40], [30, 41], [30, 42], [30, 45], [30, 46], [30, 47], [30, 50], [30, 56], [30, 57], [30, 59], [30, 61], [30, 64], [30, 65], [30, 66], [30, 67], [30, 69], [30, 70], [30, 71], [30, 74], [30, 75], [30, 81], [30, 87], [30, 91], [30, 92], [30, 95], [30, 96], [30, 99], [30, 105], [30, 106], [30, 109], [30, 111], [30, 112], [30, 113], [30, 114], [30, 115], [30, 116], [30, 118], [31, 32], [31, 33], [31, 34], [31, 36], [31, 37], [31, 38], [31, 39], [31, 46], [31, 47], [31, 48], [31, 50], [31, 51], [31, 52], [31, 53], [31, 54], [31, 57], [31, 58], [31, 60], [31, 61], [31, 62], [31, 63], [31, 65], [31, 66], [31, 69], [31, 71], [31, 75], [31, 76], [31, 77], [31, 78], [31, 83], [31, 87], [31, 89], [31, 91], [31, 94], [31, 98], [31, 99], [31, 100], [31, 103], [31, 104], [31, 106], [31, 107], [31, 108], [31, 109], [31, 110], [31, 113], [31, 114], [31, 115], [31, 116], [31, 118], [32, 33], [32, 34], [32, 35], [32, 36], [32, 38], [32, 39], [32, 40], [32, 42], [32, 44], [32, 45], [32, 46], [32, 47], [32, 50], [32, 51], [32, 52], [32, 56], [32, 57], [32, 59], [32, 60], [32, 61], [32, 62], [32, 64], [32, 65], [32, 68], [32, 71], [32, 72], [32, 73], [32, 74], [32, 78], [32, 80], [32, 81], [32, 82], [32, 83], [32, 87], [32, 88], [32, 89], [32, 91], [32, 92], [32, 93], [32, 94], [32, 95], [32, 97], [32, 99], [32, 100], [32, 103], [32, 104], [32, 105], [32, 106], [32, 110], [32, 112], [32, 115], [32, 116], [32, 118], [32, 119], [33, 34], [33, 37], [33, 38], [33, 39], [33, 40], [33, 41], [33, 42], [33, 44], [33, 45], [33, 46], [33, 48], [33, 49], [33, 50], [33, 51], [33, 53], [33, 55], [33, 56], [33, 57], [33, 60], [33, 61], [33, 65], [33, 68], [33, 70], [33, 71], [33, 72], [33, 74], [33, 75], [33, 76], [33, 78], [33, 79], [33, 81], [33, 83], [33, 84], [33, 87], [33, 89], [33, 91], [33, 94], [33, 95], [33, 96], [33, 99], [33, 100], [33, 101], [33, 102], [33, 104], [33, 105], [33, 112], [33, 113], [33, 119], [34, 40], [34, 41], [34, 46], [34, 49], [34, 50], [34, 54], [34, 55], [34, 59], [34, 65], [34, 67], [34, 71], [34, 74], [34, 75], [34, 76], [34, 80], [34, 81], [34, 84], [34, 85], [34, 88], [34, 89], [34, 91], [34, 92], [34, 95], [34, 97], [34, 100], [34, 101], [34, 102], [34, 104], [34, 109], [34, 110], [34, 111], [34, 112], [34, 117], [34, 118], [34, 119], [35, 38], [35, 39], [35, 41], [35, 46], [35, 47], [35, 48], [35, 51], [35, 53], [35, 54], [35, 56], [35, 57], [35, 59], [35, 60], [35, 62], [35, 63], [35, 64], [35, 65], [35, 69], [35, 72], [35, 73], [35, 76], [35, 77], [35, 78], [35, 84], [35, 85], [35, 86], [35, 87], [35, 94], [35, 95], [35, 96], [35, 97], [35, 98], [35, 99], [35, 100], [35, 101], [35, 104], [35, 105], [35, 107], [35, 108], [35, 112], [35, 114], [35, 116], [35, 118], [36, 37], [36, 38], [36, 39], [36, 42], [36, 45], [36, 50], [36, 53], [36, 54], [36, 55], [36, 56], [36, 61], [36, 63], [36, 66], [36, 70], [36, 73], [36, 75], [36, 79], [36, 82], [36, 83], [36, 84], [36, 85], [36, 86], [36, 87], [36, 88], [36, 93], [36, 95], [36, 97], [36, 99], [36, 105], [36, 107], [36, 109], [36, 110], [36, 112], [36, 113], [36, 114], [36, 115], [36, 116], [36, 119], [37, 39], [37, 40], [37, 41], [37, 42], [37, 43], [37, 44], [37, 45], [37, 46], [37, 48], [37, 49], [37, 52], [37, 55], [37, 59], [37, 60], [37, 61], [37, 62], [37, 65], [37, 68], [37, 69], [37, 70], [37, 71], [37, 73], [37, 75], [37, 76], [37, 78], [37, 81], [37, 82], [37, 83], [37, 85], [37, 86], [37, 89], [37, 91], [37, 94], [37, 95], [37, 99], [37, 104], [37, 110], [37, 111], [37, 112], [37, 113], [37, 114], [37, 116], [37, 119], [38, 39], [38, 41], [38, 42], [38, 46], [38, 47], [38, 48], [38, 51], [38, 52], [38, 53], [38, 54], [38, 59], [38, 60], [38, 61], [38, 62], [38, 64], [38, 69], [38, 70], [38, 72], [38, 75], [38, 76], [38, 79], [38, 80], [38, 82], [38, 83], [38, 85], [38, 88], [38, 90], [38, 93], [38, 94], [38, 96], [38, 97], [38, 99], [38, 100], [38, 104], [38, 108], [38, 111], [38, 112], [38, 114], [38, 116], [38, 117], [38, 119], [39, 44], [39, 46], [39, 48], [39, 49], [39, 53], [39, 54], [39, 56], [39, 60], [39, 65], [39, 66], [39, 67], [39, 71], [39, 72], [39, 73], [39, 74], [39, 77], [39, 79], [39, 82], [39, 84], [39, 86], [39, 89], [39, 91], [39, 94], [39, 95], [39, 96], [39, 99], [39, 100], [39, 101], [39, 103], [39, 105], [39, 111], [39, 112], [39, 115], [39, 116], [40, 41], [40, 42], [40, 43], [40, 46], [40, 47], [40, 50], [40, 56], [40, 57], [40, 58], [40, 59], [40, 61], [40, 65], [40, 67], [40, 68], [40, 75], [40, 77], [40, 78], [40, 79], [40, 81], [40, 82], [40, 87], [40, 89], [40, 90], [40, 91], [40, 92], [40, 93], [40, 95], [40, 96], [40, 98], [40, 100], [40, 102], [40, 108], [40, 109], [40, 110], [40, 111], [40, 112], [40, 113], [40, 118], [40, 119], [41, 43], [41, 44], [41, 45], [41, 46], [41, 47], [41, 51], [41, 52], [41, 54], [41, 55], [41, 56], [41, 64], [41, 65], [41, 67], [41, 70], [41, 73], [41, 74], [41, 75], [41, 79], [41, 80], [41, 81], [41, 82], [41, 84], [41, 86], [41, 87], [41, 88], [41, 89], [41, 92], [41, 96], [41, 102], [41, 103], [41, 105], [41, 106], [41, 107], [41, 109], [41, 110], [41, 112], [41, 113], [41, 119], [42, 44], [42, 48], [42, 50], [42, 53], [42, 55], [42, 56], [42, 59], [42, 63], [42, 65], [42, 69], [42, 70], [42, 74], [42, 76], [42, 77], [42, 79], [42, 81], [42, 86], [42, 93], [42, 94], [42, 97], [42, 98], [42, 99], [42, 101], [42, 102], [42, 104], [42, 105], [42, 107], [42, 109], [42, 110], [42, 111], [42, 117], [42, 119], [43, 44], [43, 47], [43, 48], [43, 49], [43, 51], [43, 55], [43, 56], [43, 57], [43, 58], [43, 63], [43, 64], [43, 67], [43, 70], [43, 76], [43, 82], [43, 84], [43, 87], [43, 88], [43, 89], [43, 92], [43, 93], [43, 96], [43, 98], [43, 100], [43, 102], [43, 103], [43, 104], [43, 107], [43, 108], [43, 109], [43, 110], [43, 111], [43, 112], [43, 113], [43, 118], [43, 119], [44, 45], [44, 46], [44, 47], [44, 50], [44, 52], [44, 53], [44, 56], [44, 58], [44, 62], [44, 63], [44, 67], [44, 69], [44, 75], [44, 78], [44, 83], [44, 84], [44, 87], [44, 90], [44, 91], [44, 95], [44, 96], [44, 97], [44, 100], [44, 101], [44, 102], [44, 104], [44, 105], [44, 107], [44, 110], [44, 111], [44, 113], [44, 114], [44, 118], [45, 47], [45, 49], [45, 52], [45, 55], [45, 56], [45, 57], [45, 59], [45, 60], [45, 61], [45, 63], [45, 64], [45, 69], [45, 70], [45, 71], [45, 72], [45, 73], [45, 74], [45, 75], [45, 76], [45, 79], [45, 80], [45, 82], [45, 83], [45, 84], [45, 85], [45, 86], [45, 87], [45, 88], [45, 89], [45, 90], [45, 91], [45, 93], [45, 94], [45, 98], [45, 100], [45, 101], [45, 107], [45, 115], [45, 116], [45, 117], [46, 48], [46, 53], [46, 54], [46, 56], [46, 57], [46, 58], [46, 60], [46, 61], [46, 62], [46, 63], [46, 65], [46, 66], [46, 67], [46, 68], [46, 70], [46, 74], [46, 76], [46, 77], [46, 78], [46, 80], [46, 81], [46, 84], [46, 85], [46, 86], [46, 87], [46, 88], [46, 92], [46, 93], [46, 94], [46, 96], [46, 98], [46, 99], [46, 100], [46, 104], [46, 106], [46, 108], [46, 112], [46, 113], [46, 114], [46, 115], [46, 118], [46, 119], [47, 48], [47, 50], [47, 52], [47, 53], [47, 54], [47, 55], [47, 56], [47, 60], [47, 61], [47, 63], [47, 64], [47, 65], [47, 66], [47, 68], [47, 70], [47, 73], [47, 74], [47, 75], [47, 76], [47, 78], [47, 80], [47, 81], [47, 88], [47, 89], [47, 91], [47, 92], [47, 93], [47, 94], [47, 95], [47, 96], [47, 97], [47, 98], [47, 99], [47, 100], [47, 101], [47, 102], [47, 103], [47, 106], [47, 107], [47, 109], [47, 110], [47, 113], [47, 114], [47, 116], [47, 117], [47, 118], [48, 49], [48, 53], [48, 54], [48, 55], [48, 57], [48, 58], [48, 59], [48, 60], [48, 65], [48, 68], [48, 71], [48, 72], [48, 73], [48, 76], [48, 77], [48, 79], [48, 83], [48, 84], [48, 86], [48, 91], [48, 97], [48, 100], [48, 101], [48, 102], [48, 103], [48, 110], [48, 112], [48, 113], [48, 117], [48, 118], [48, 119], [49, 53], [49, 54], [49, 57], [49, 61], [49, 67], [49, 69], [49, 71], [49, 74], [49, 75], [49, 76], [49, 78], [49, 79], [49, 82], [49, 83], [49, 85], [49, 88], [49, 93], [49, 94], [49, 99], [49, 101], [49, 104], [49, 106], [49, 107], [49, 109], [49, 111], [49, 115], [50, 51], [50, 52], [50, 55], [50, 57], [50, 59], [50, 62], [50, 64], [50, 66], [50, 67], [50, 68], [50, 69], [50, 70], [50, 73], [50, 74], [50, 76], [50, 77], [50, 78], [50, 80], [50, 81], [50, 82], [50, 86], [50, 87], [50, 88], [50, 89], [50, 91], [50, 92], [50, 93], [50, 96], [50, 98], [50, 100], [50, 101], [50, 102], [50, 103], [50, 104], [50, 108], [50, 109], [50, 111], [50, 115], [50, 117], [51, 52], [51, 55], [51, 56], [51, 57], [51, 58], [51, 59], [51, 61], [51, 62], [51, 65], [51, 67], [51, 68], [51, 69], [51, 70], [51, 71], [51, 72], [51, 73], [51, 75], [51, 77], [51, 80], [51, 86], [51, 89], [51, 91], [51, 93], [51, 95], [51, 99], [51, 100], [51, 101], [51, 102], [51, 103], [51, 110], [51, 113], [51, 114], [51, 118], [52, 55], [52, 58], [52, 60], [52, 61], [52, 64], [52, 65], [52, 66], [52, 70], [52, 71], [52, 73], [52, 76], [52, 77], [52, 78], [52, 79], [52, 80], [52, 82], [52, 85], [52, 86], [52, 87], [52, 88], [52, 89], [52, 90], [52, 92], [52, 93], [52, 94], [52, 96], [52, 97], [52, 102], [52, 104], [52, 106], [52, 107], [52, 113], [52, 115], [52, 118], [53, 56], [53, 63], [53, 67], [53, 70], [53, 71], [53, 72], [53, 73], [53, 74], [53, 75], [53, 76], [53, 77], [53, 78], [53, 79], [53, 81], [53, 83], [53, 86], [53, 88], [53, 89], [53, 92], [53, 93], [53, 94], [53, 95], [53, 96], [53, 97], [53, 98], [53, 100], [53, 101], [53, 104], [53, 105], [53, 106], [53, 107], [53, 108], [53, 111], [53, 112], [53, 115], [53, 117], [54, 60], [54, 61], [54, 63], [54, 64], [54, 66], [54, 68], [54, 69], [54, 72], [54, 75], [54, 77], [54, 78], [54, 79], [54, 80], [54, 81], [54, 89], [54, 90], [54, 91], [54, 92], [54, 93], [54, 94], [54, 95], [54, 97], [54, 104], [54, 105], [54, 106], [54, 108], [54, 109], [54, 112], [54, 113], [54, 115], [54, 116], [54, 118], [55, 64], [55, 65], [55, 67], [55, 68], [55, 71], [55, 73], [55, 78], [55, 81], [55, 82], [55, 83], [55, 85], [55, 88], [55, 89], [55, 90], [55, 91], [55, 93], [55, 94], [55, 95], [55, 96], [55, 97], [55, 98], [55, 99], [55, 100], [55, 101], [55, 102], [55, 103], [55, 104], [55, 107], [55, 112], [56, 58], [56, 59], [56, 60], [56, 63], [56, 65], [56, 66], [56, 67], [56, 69], [56, 70], [56, 71], [56, 72], [56, 73], [56, 77], [56, 78], [56, 80], [56, 81], [56, 82], [56, 87], [56, 96], [56, 98], [56, 102], [56, 105], [56, 107], [56, 110], [56, 111], [56, 112], [56, 113], [56, 114], [56, 118], [56, 119], [57, 59], [57, 60], [57, 61], [57, 62], [57, 63], [57, 64], [57, 65], [57, 69], [57, 72], [57, 79], [57, 82], [57, 84], [57, 86], [57, 87], [57, 90], [57, 95], [57, 96], [57, 100], [57, 101], [57, 102], [57, 103], [57, 104], [57, 105], [57, 108], [57, 109], [57, 110], [57, 114], [57, 115], [57, 116], [57, 117], [57, 119], [58, 60], [58, 63], [58, 64], [58, 65], [58, 67], [58, 69], [58, 70], [58, 71], [58, 72], [58, 73], [58, 74], [58, 75], [58, 77], [58, 82], [58, 85], [58, 86], [58, 87], [58, 88], [58, 89], [58, 91], [58, 93], [58, 94], [58, 95], [58, 96], [58, 97], [58, 98], [58, 101], [58, 102], [58, 105], [58, 106], [58, 107], [58, 110], [58, 112], [58, 114], [58, 117], [59, 62], [59, 64], [59, 65], [59, 69], [59, 75], [59, 76], [59, 77], [59, 79], [59, 80], [59, 83], [59, 84], [59, 85], [59, 86], [59, 88], [59, 89], [59, 90], [59, 94], [59, 95], [59, 96], [59, 99], [59, 100], [59, 101], [59, 105], [59, 107], [59, 109], [59, 111], [59, 112], [59, 113], [59, 116], [59, 117], [59, 118], [59, 119], [60, 62], [60, 63], [60, 65], [60, 66], [60, 67], [60, 69], [60, 75], [60, 76], [60, 80], [60, 82], [60, 83], [60, 84], [60, 85], [60, 86], [60, 89], [60, 93], [60, 95], [60, 97], [60, 99], [60, 100], [60, 104], [60, 105], [60, 107], [60, 110], [60, 111], [60, 112], [60, 113], [60, 114], [60, 116], [60, 117], [60, 118], [61, 63], [61, 66], [61, 67], [61, 71], [61, 76], [61, 77], [61, 79], [61, 80], [61, 82], [61, 83], [61, 84], [61, 86], [61, 87], [61, 88], [61, 90], [61, 98], [61, 99], [61, 100], [61, 103], [61, 104], [61, 105], [61, 107], [61, 110], [61, 112], [61, 115], [61, 116], [61, 118], [61, 119], [62, 64], [62, 65], [62, 66], [62, 68], [62, 69], [62, 74], [62, 75], [62, 77], [62, 78], [62, 80], [62, 83], [62, 84], [62, 85], [62, 87], [62, 88], [62, 89], [62, 90], [62, 92], [62, 94], [62, 98], [62, 99], [62, 101], [62, 102], [62, 104], [62, 105], [62, 106], [62, 107], [62, 108], [62, 110], [62, 111], [62, 113], [62, 116], [62, 117], [62, 119], [63, 66], [63, 67], [63, 68], [63, 71], [63, 72], [63, 73], [63, 74], [63, 75], [63, 76], [63, 80], [63, 81], [63, 82], [63, 84], [63, 85], [63, 87], [63, 94], [63, 95], [63, 96], [63, 102], [63, 104], [63, 108], [63, 111], [63, 113], [63, 114], [63, 115], [63, 116], [64, 66], [64, 70], [64, 77], [64, 79], [64, 80], [64, 81], [64, 82], [64, 87], [64, 88], [64, 90], [64, 91], [64, 94], [64, 96], [64, 98], [64, 101], [64, 103], [64, 105], [64, 109], [64, 110], [64, 113], [64, 115], [64, 116], [64, 118], [64, 119], [65, 66], [65, 68], [65, 71], [65, 74], [65, 76], [65, 77], [65, 79], [65, 80], [65, 81], [65, 82], [65, 83], [65, 84], [65, 85], [65, 88], [65, 89], [65, 100], [65, 101], [65, 102], [65, 104], [65, 109], [65, 110], [65, 116], [66, 67], [66, 70], [66, 73], [66, 75], [66, 76], [66, 77], [66, 79], [66, 82], [66, 83], [66, 84], [66, 85], [66, 86], [66, 89], [66, 90], [66, 92], [66, 93], [66, 94], [66, 95], [66, 96], [66, 100], [66, 101], [66, 103], [66, 104], [66, 105], [66, 107], [66, 109], [66, 110], [66, 111], [66, 113], [66, 114], [66, 115], [66, 116], [66, 117], [66, 118], [66, 119], [67, 68], [67, 71], [67, 72], [67, 73], [67, 74], [67, 78], [67, 79], [67, 83], [67, 85], [67, 86], [67, 90], [67, 92], [67, 94], [67, 95], [67, 96], [67, 98], [67, 99], [67, 100], [67, 101], [67, 104], [67, 107], [67, 110], [67, 111], [67, 113], [67, 114], [67, 116], [68, 71], [68, 72], [68, 73], [68, 75], [68, 76], [68, 82], [68, 84], [68, 92], [68, 93], [68, 97], [68, 99], [68, 100], [68, 102], [68, 105], [68, 107], [68, 111], [68, 114], [68, 117], [68, 118], [69, 71], [69, 74], [69, 77], [69, 78], [69, 80], [69, 81], [69, 83], [69, 84], [69, 92], [69, 93], [69, 94], [69, 95], [69, 96], [69, 97], [69, 100], [69, 102], [69, 103], [69, 104], [69, 106], [69, 108], [69, 109], [69, 110], [69, 113], [69, 115], [69, 117], [69, 119], [70, 72], [70, 74], [70, 75], [70, 77], [70, 78], [70, 79], [70, 80], [70, 81], [70, 86], [70, 88], [70, 91], [70, 97], [70, 99], [70, 100], [70, 103], [70, 108], [70, 109], [70, 110], [70, 111], [70, 113], [70, 115], [70, 116], [70, 117], [71, 72], [71, 74], [71, 76], [71, 77], [71, 79], [71, 83], [71, 85], [71, 88], [71, 89], [71, 90], [71, 93], [71, 94], [71, 95], [71, 99], [71, 100], [71, 103], [71, 104], [71, 107], [71, 108], [71, 109], [71, 110], [71, 111], [71, 116], [72, 73], [72, 75], [72, 76], [72, 78], [72, 79], [72, 80], [72, 83], [72, 85], [72, 86], [72, 87], [72, 90], [72, 93], [72, 95], [72, 97], [72, 104], [72, 106], [72, 111], [72, 113], [72, 114], [72, 117], [72, 118], [73, 78], [73, 79], [73, 81], [73, 83], [73, 88], [73, 90], [73, 93], [73, 96], [73, 102], [73, 104], [73, 105], [73, 109], [73, 111], [73, 112], [73, 115], [73, 116], [74, 76], [74, 77], [74, 78], [74, 80], [74, 81], [74, 83], [74, 84], [74, 85], [74, 88], [74, 89], [74, 90], [74, 92], [74, 95], [74, 96], [74, 98], [74, 99], [74, 100], [74, 102], [74, 104], [74, 105], [74, 111], [74, 112], [74, 115], [74, 116], [74, 117], [75, 76], [75, 77], [75, 82], [75, 87], [75, 88], [75, 89], [75, 90], [75, 93], [75, 95], [75, 96], [75, 97], [75, 98], [75, 99], [75, 100], [75, 101], [75, 104], [75, 107], [75, 110], [75, 112], [75, 114], [75, 116], [75, 117], [75, 118], [76, 79], [76, 80], [76, 82], [76, 85], [76, 89], [76, 90], [76, 91], [76, 93], [76, 95], [76, 99], [76, 100], [76, 101], [76, 102], [76, 103], [76, 107], [76, 108], [76, 109], [76, 110], [76, 111], [76, 112], [76, 114], [76, 115], [76, 116], [76, 118], [77, 79], [77, 81], [77, 82], [77, 88], [77, 90], [77, 91], [77, 92], [77, 96], [77, 99], [77, 103], [77, 108], [77, 109], [77, 110], [77, 113], [77, 114], [77, 115], [77, 116], [77, 117], [77, 118], [77, 119], [78, 81], [78, 83], [78, 89], [78, 91], [78, 93], [78, 94], [78, 96], [78, 98], [78, 99], [78, 100], [78, 101], [78, 102], [78, 104], [78, 106], [78, 107], [78, 109], [78, 110], [78, 112], [78, 116], [78, 119], [79, 80], [79, 82], [79, 84], [79, 85], [79, 88], [79, 90], [79, 91], [79, 92], [79, 94], [79, 95], [79, 98], [79, 99], [79, 100], [79, 103], [79, 104], [79, 105], [79, 113], [79, 114], [79, 115], [80, 82], [80, 89], [80, 90], [80, 91], [80, 96], [80, 97], [80, 100], [80, 101], [80, 105], [80, 106], [80, 107], [80, 108], [80, 109], [80, 111], [80, 115], [80, 117], [80, 119], [81, 84], [81, 86], [81, 87], [81, 88], [81, 89], [81, 91], [81, 95], [81, 97], [81, 99], [81, 100], [81, 105], [81, 107], [81, 108], [81, 109], [81, 110], [81, 112], [81, 114], [81, 115], [81, 116], [81, 118], [81, 119], [82, 84], [82, 85], [82, 86], [82, 88], [82, 89], [82, 92], [82, 93], [82, 95], [82, 96], [82, 99], [82, 100], [82, 104], [82, 105], [82, 108], [82, 110], [82, 114], [82, 115], [82, 116], [82, 117], [82, 119], [83, 86], [83, 88], [83, 89], [83, 93], [83, 95], [83, 96], [83, 98], [83, 101], [83, 102], [83, 104], [83, 106], [83, 113], [83, 115], [83, 118], [83, 119], [84, 85], [84, 86], [84, 91], [84, 97], [84, 98], [84, 99], [84, 100], [84, 101], [84, 102], [84, 103], [84, 104], [84, 108], [84, 109], [84, 110], [84, 112], [84, 113], [84, 114], [84, 116], [84, 117], [84, 119], [85, 88], [85, 90], [85, 91], [85, 93], [85, 94], [85, 95], [85, 97], [85, 98], [85, 99], [85, 100], [85, 103], [85, 105], [85, 107], [85, 108], [85, 109], [85, 116], [85, 117], [86, 87], [86, 90], [86, 94], [86, 95], [86, 96], [86, 100], [86, 101], [86, 102], [86, 107], [86, 108], [86, 109], [86, 111], [86, 113], [86, 115], [86, 116], [86, 119], [87, 89], [87, 90], [87, 91], [87, 92], [87, 93], [87, 94], [87, 96], [87, 97], [87, 99], [87, 101], [87, 103], [87, 105], [87, 106], [87, 107], [87, 110], [87, 111], [87, 113], [87, 114], [87, 115], [87, 118], [88, 89], [88, 91], [88, 92], [88, 93], [88, 98], [88, 101], [88, 102], [88, 103], [88, 104], [88, 109], [88, 112], [88, 115], [88, 117], [88, 118], [88, 119], [89, 90], [89, 91], [89, 93], [89, 95], [89, 96], [89, 97], [89, 99], [89, 100], [89, 106], [89, 107], [89, 108], [89, 110], [89, 111], [89, 112], [89, 113], [89, 114], [89, 116], [89, 118], [89, 119], [90, 91], [90, 92], [90, 93], [90, 94], [90, 96], [90, 97], [90, 98], [90, 100], [90, 101], [90, 104], [90, 107], [90, 109], [90, 110], [90, 114], [90, 116], [90, 117], [90, 118], [90, 119], [91, 92], [91, 95], [91, 97], [91, 99], [91, 101], [91, 106], [91, 108], [91, 109], [91, 112], [91, 113], [91, 116], [91, 117], [91, 119], [92, 93], [92, 94], [92, 96], [92, 97], [92, 98], [92, 104], [92, 105], [92, 108], [92, 109], [92, 113], [92, 116], [92, 117], [93, 94], [93, 95], [93, 98], [93, 99], [93, 100], [93, 101], [93, 105], [93, 107], [93, 111], [93, 117], [93, 118], [94, 95], [94, 96], [94, 97], [94, 98], [94, 100], [94, 102], [94, 104], [94, 107], [94, 108], [94, 110], [94, 113], [94, 114], [94, 115], [94, 116], [94, 117], [94, 119], [95, 97], [95, 99], [95, 100], [95, 105], [95, 108], [95, 111], [95, 114], [95, 115], [95, 118], [96, 97], [96, 100], [96, 101], [96, 102], [96, 104], [96, 105], [96, 107], [96, 109], [96, 110], [96, 117], [96, 119], [97, 100], [97, 102], [97, 105], [97, 106], [97, 108], [97, 112], [97, 113], [97, 115], [97, 116], [97, 117], [97, 119], [98, 100], [98, 101], [98, 104], [98, 105], [98, 107], [98, 108], [98, 110], [98, 111], [98, 113], [98, 115], [98, 116], [98, 119], [99, 102], [99, 104], [99, 105], [99, 106], [99, 109], [99, 110], [99, 111], [99, 112], [99, 113], [99, 115], [100, 103], [100, 105], [100, 106], [100, 107], [100, 108], [100, 109], [100, 110], [100, 112], [100, 114], [100, 115], [100, 116], [100, 117], [100, 118], [101, 104], [101, 106], [101, 112], [101, 116], [101, 119], [102, 103], [102, 105], [102, 107], [102, 108], [102, 109], [102, 112], [102, 116], [102, 117], [103, 105], [103, 106], [103, 108], [103, 109], [103, 113], [103, 114], [103, 117], [104, 106], [104, 108], [104, 109], [104, 111], [104, 112], [104, 118], [105, 106], [105, 108], [105, 111], [105, 117], [105, 119], [106, 107], [106, 108], [106, 109], [106, 111], [106, 112], [106, 116], [106, 118], [107, 110], [107, 111], [107, 113], [107, 116], [108, 113], [108, 115], [108, 119], [109, 110], [109, 115], [109, 117], [109, 119], [110, 113], [110, 114], [110, 115], [110, 116], [110, 117], [110, 118], [111, 113], [111, 119], [112, 114], [113, 114], [113, 116], [113, 117], [113, 119], [114, 115], [114, 116], [114, 118], [114, 119], [115, 116], [115, 119], [116, 117], [116, 118], [117, 118], [117, 119], [118, 119]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l6-s2/solution/solve.sh b/tasks/construct-mc-max-clique-l6-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b1146f211209377cab60434d8e3189edc09b1635 --- /dev/null +++ b/tasks/construct-mc-max-clique-l6-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [29, 31, 47, 60, 66, 75, 76, 89, 100, 110, 114, 116, 118]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-clique-l6-s2/tests/check.py b/tasks/construct-mc-max-clique-l6-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3f70dbd5b155a3514c2102aa4ad460201495210 --- /dev/null +++ b/tasks/construct-mc-max-clique-l6-s2/tests/check.py @@ -0,0 +1,18 @@ +"""Clique of size >= k in a given graph (MathConstraint max_clique decision version, CC-BY-4.0).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("clique"), None, 0, n - 1, "clique") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) < k: + raise Invalid(f"clique has {len(S)} vertices, need at least {k}") + E = {(u, v) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(S), 2): + if (u, v) not in E: + raise Invalid(f"vertices {u} and {v} are not adjacent") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-max-clique-l6-s2/tests/instance.json b/tasks/construct-mc-max-clique-l6-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b3fe36937e31ecfb06b7cd510f5d51ae993c6db1 --- /dev/null +++ b/tasks/construct-mc-max-clique-l6-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 120, "k": 13, "edges": [[0, 2], [0, 3], [0, 4], [0, 7], [0, 8], [0, 11], [0, 12], [0, 15], [0, 16], [0, 20], [0, 26], [0, 29], [0, 30], [0, 34], [0, 36], [0, 37], [0, 38], [0, 39], [0, 40], [0, 41], [0, 43], [0, 45], [0, 47], [0, 49], [0, 51], [0, 52], [0, 54], [0, 57], [0, 59], [0, 61], [0, 62], [0, 65], [0, 68], [0, 70], [0, 71], [0, 73], [0, 75], [0, 76], [0, 78], [0, 82], [0, 86], [0, 92], [0, 95], [0, 96], [0, 97], [0, 98], [0, 102], [0, 105], [0, 107], [0, 109], [0, 110], [0, 111], [0, 113], [0, 116], [0, 118], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 13], [1, 14], [1, 15], [1, 19], [1, 20], [1, 21], [1, 22], [1, 24], [1, 25], [1, 27], [1, 28], [1, 29], [1, 35], [1, 38], [1, 42], [1, 43], [1, 44], [1, 45], [1, 48], [1, 49], [1, 51], [1, 54], [1, 55], [1, 56], [1, 58], [1, 60], [1, 62], [1, 65], [1, 70], [1, 72], [1, 76], [1, 83], [1, 84], [1, 85], [1, 88], [1, 90], [1, 92], [1, 94], [1, 95], [1, 99], [1, 101], [1, 102], [1, 106], [1, 113], [1, 116], [1, 119], [2, 4], [2, 12], [2, 15], [2, 23], [2, 26], [2, 27], [2, 29], [2, 30], [2, 31], [2, 33], [2, 34], [2, 35], [2, 37], [2, 39], [2, 40], [2, 43], [2, 44], [2, 47], [2, 50], [2, 52], [2, 53], [2, 56], [2, 57], [2, 59], [2, 64], [2, 69], [2, 70], [2, 71], [2, 72], [2, 73], [2, 74], [2, 75], [2, 77], [2, 81], [2, 83], [2, 91], [2, 97], [2, 98], [2, 99], [2, 100], [2, 101], [2, 102], [2, 104], [2, 105], [2, 107], [2, 109], [2, 110], [2, 111], [2, 112], [2, 113], [2, 115], [3, 5], [3, 6], [3, 11], [3, 12], [3, 13], [3, 14], [3, 16], [3, 18], [3, 20], [3, 21], [3, 22], [3, 23], [3, 24], [3, 26], [3, 28], [3, 30], [3, 32], [3, 33], [3, 35], [3, 38], [3, 39], [3, 40], [3, 41], [3, 43], [3, 44], [3, 45], [3, 47], [3, 51], [3, 52], [3, 54], [3, 55], [3, 57], [3, 58], [3, 61], [3, 66], [3, 68], [3, 70], [3, 76], [3, 77], [3, 80], [3, 81], [3, 82], [3, 84], [3, 85], [3, 87], [3, 89], [3, 90], [3, 91], [3, 97], [3, 99], [3, 101], [3, 102], [3, 104], [3, 111], [3, 112], [3, 115], [3, 119], [4, 7], [4, 9], [4, 13], [4, 14], [4, 22], [4, 23], [4, 26], [4, 29], [4, 32], [4, 33], [4, 35], [4, 36], [4, 37], [4, 38], [4, 39], [4, 40], [4, 41], [4, 42], [4, 43], [4, 44], [4, 46], [4, 47], [4, 48], [4, 50], [4, 51], [4, 52], [4, 53], [4, 54], [4, 55], [4, 57], [4, 62], [4, 66], [4, 69], [4, 71], [4, 72], [4, 73], [4, 76], [4, 77], [4, 78], [4, 79], [4, 80], [4, 81], [4, 84], [4, 86], [4, 87], [4, 90], [4, 92], [4, 95], [4, 101], [4, 102], [4, 103], [4, 105], [4, 106], [4, 109], [4, 111], [4, 112], [4, 113], [4, 114], [4, 115], [4, 117], [4, 118], [4, 119], [5, 10], [5, 11], [5, 13], [5, 15], [5, 16], [5, 18], [5, 19], [5, 21], [5, 22], [5, 24], [5, 25], [5, 30], [5, 31], [5, 32], [5, 33], [5, 34], [5, 37], [5, 41], [5, 42], [5, 43], [5, 44], [5, 47], [5, 48], [5, 50], [5, 55], [5, 57], [5, 61], [5, 63], [5, 64], [5, 65], [5, 66], [5, 69], [5, 70], [5, 72], [5, 73], [5, 74], [5, 77], [5, 78], [5, 84], [5, 85], [5, 87], [5, 88], [5, 90], [5, 94], [5, 95], [5, 96], [5, 97], [5, 98], [5, 100], [5, 101], [5, 102], [5, 103], [5, 107], [5, 108], [5, 109], [5, 110], [5, 113], [5, 114], [5, 116], [5, 117], [5, 118], [5, 119], [6, 9], [6, 12], [6, 13], [6, 15], [6, 16], [6, 18], [6, 19], [6, 21], [6, 23], [6, 24], [6, 27], [6, 28], [6, 30], [6, 31], [6, 34], [6, 35], [6, 36], [6, 38], [6, 39], [6, 40], [6, 42], [6, 45], [6, 46], [6, 47], [6, 49], [6, 52], [6, 56], [6, 57], [6, 58], [6, 59], [6, 60], [6, 61], [6, 67], [6, 71], [6, 72], [6, 73], [6, 75], [6, 76], [6, 78], [6, 81], [6, 82], [6, 91], [6, 93], [6, 95], [6, 97], [6, 98], [6, 99], [6, 103], [6, 104], [6, 105], [6, 106], [6, 108], [6, 111], [6, 112], [6, 116], [6, 117], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [7, 14], [7, 15], [7, 17], [7, 18], [7, 22], [7, 26], [7, 27], [7, 28], [7, 33], [7, 35], [7, 37], [7, 39], [7, 40], [7, 44], [7, 49], [7, 51], [7, 54], [7, 55], [7, 56], [7, 58], [7, 59], [7, 61], [7, 62], [7, 63], [7, 65], [7, 66], [7, 68], [7, 70], [7, 76], [7, 77], [7, 78], [7, 80], [7, 82], [7, 84], [7, 85], [7, 86], [7, 87], [7, 89], [7, 91], [7, 92], [7, 94], [7, 96], [7, 97], [7, 99], [7, 100], [7, 104], [7, 107], [7, 108], [7, 111], [7, 112], [7, 113], [7, 116], [7, 117], [8, 10], [8, 13], [8, 15], [8, 16], [8, 17], [8, 18], [8, 19], [8, 21], [8, 22], [8, 33], [8, 34], [8, 35], [8, 37], [8, 38], [8, 39], [8, 40], [8, 43], [8, 44], [8, 45], [8, 48], [8, 49], [8, 51], [8, 58], [8, 59], [8, 61], [8, 64], [8, 65], [8, 66], [8, 69], [8, 72], [8, 73], [8, 74], [8, 76], [8, 77], [8, 80], [8, 85], [8, 86], [8, 91], [8, 92], [8, 94], [8, 95], [8, 99], [8, 100], [8, 101], [8, 106], [8, 110], [8, 112], [8, 113], [8, 117], [8, 118], [9, 11], [9, 12], [9, 13], [9, 16], [9, 20], [9, 21], [9, 24], [9, 26], [9, 27], [9, 29], [9, 30], [9, 32], [9, 33], [9, 35], [9, 40], [9, 45], [9, 46], [9, 47], [9, 48], [9, 49], [9, 51], [9, 52], [9, 54], [9, 55], [9, 56], [9, 58], [9, 59], [9, 62], [9, 63], [9, 66], [9, 70], [9, 73], [9, 76], [9, 80], [9, 86], [9, 87], [9, 90], [9, 92], [9, 98], [9, 101], [9, 104], [9, 112], [9, 113], [9, 116], [9, 117], [9, 119], [10, 11], [10, 12], [10, 15], [10, 17], [10, 19], [10, 21], [10, 22], [10, 23], [10, 25], [10, 29], [10, 30], [10, 31], [10, 32], [10, 34], [10, 37], [10, 38], [10, 39], [10, 41], [10, 42], [10, 44], [10, 47], [10, 48], [10, 50], [10, 52], [10, 53], [10, 55], [10, 56], [10, 57], [10, 59], [10, 60], [10, 63], [10, 67], [10, 71], [10, 73], [10, 75], [10, 78], [10, 80], [10, 84], [10, 85], [10, 87], [10, 89], [10, 94], [10, 95], [10, 98], [10, 100], [10, 101], [10, 102], [10, 103], [10, 105], [10, 108], [10, 113], [10, 115], [10, 116], [10, 119], [11, 12], [11, 14], [11, 15], [11, 20], [11, 21], [11, 25], [11, 26], [11, 28], [11, 29], [11, 33], [11, 35], [11, 36], [11, 39], [11, 41], [11, 43], [11, 45], [11, 47], [11, 50], [11, 53], [11, 55], [11, 60], [11, 63], [11, 65], [11, 66], [11, 69], [11, 71], [11, 75], [11, 76], [11, 78], [11, 81], [11, 82], [11, 84], [11, 86], [11, 88], [11, 91], [11, 92], [11, 94], [11, 97], [11, 98], [11, 100], [11, 102], [11, 103], [11, 105], [11, 106], [11, 107], [11, 109], [11, 113], [11, 118], [11, 119], [12, 13], [12, 14], [12, 16], [12, 18], [12, 20], [12, 22], [12, 23], [12, 24], [12, 25], [12, 27], [12, 29], [12, 30], [12, 33], [12, 34], [12, 35], [12, 36], [12, 43], [12, 45], [12, 47], [12, 49], [12, 51], [12, 53], [12, 56], [12, 58], [12, 59], [12, 60], [12, 62], [12, 66], [12, 67], [12, 72], [12, 73], [12, 77], [12, 80], [12, 84], [12, 86], [12, 89], [12, 91], [12, 92], [12, 95], [12, 96], [12, 98], [12, 100], [12, 102], [12, 103], [12, 104], [12, 108], [12, 112], [12, 113], [12, 115], [12, 116], [12, 118], [12, 119], [13, 14], [13, 22], [13, 24], [13, 26], [13, 28], [13, 32], [13, 33], [13, 36], [13, 37], [13, 38], [13, 41], [13, 43], [13, 44], [13, 45], [13, 47], [13, 48], [13, 50], [13, 51], [13, 52], [13, 55], [13, 56], [13, 57], [13, 61], [13, 64], [13, 67], [13, 68], [13, 69], [13, 70], [13, 71], [13, 72], [13, 74], [13, 75], [13, 76], [13, 79], [13, 88], [13, 90], [13, 92], [13, 97], [13, 98], [13, 99], [13, 103], [13, 104], [13, 105], [13, 106], [13, 107], [13, 112], [13, 113], [13, 115], [13, 117], [14, 16], [14, 19], [14, 21], [14, 22], [14, 24], [14, 25], [14, 28], [14, 29], [14, 36], [14, 39], [14, 41], [14, 43], [14, 47], [14, 50], [14, 52], [14, 53], [14, 55], [14, 56], [14, 57], [14, 60], [14, 64], [14, 65], [14, 66], [14, 68], [14, 69], [14, 70], [14, 71], [14, 75], [14, 76], [14, 78], [14, 80], [14, 81], [14, 82], [14, 83], [14, 84], [14, 85], [14, 87], [14, 89], [14, 90], [14, 91], [14, 92], [14, 98], [14, 100], [14, 101], [14, 106], [14, 108], [14, 114], [14, 115], [14, 116], [14, 119], [15, 17], [15, 19], [15, 21], [15, 22], [15, 24], [15, 25], [15, 27], [15, 28], [15, 29], [15, 31], [15, 36], [15, 38], [15, 40], [15, 42], [15, 45], [15, 46], [15, 47], [15, 48], [15, 49], [15, 51], [15, 52], [15, 55], [15, 56], [15, 57], [15, 58], [15, 59], [15, 61], [15, 63], [15, 64], [15, 65], [15, 66], [15, 68], [15, 71], [15, 72], [15, 74], [15, 75], [15, 77], [15, 78], [15, 79], [15, 82], [15, 83], [15, 84], [15, 86], [15, 87], [15, 90], [15, 91], [15, 92], [15, 94], [15, 98], [15, 99], [15, 100], [15, 102], [15, 103], [15, 104], [15, 106], [15, 107], [15, 109], [15, 112], [15, 115], [15, 116], [15, 119], [16, 19], [16, 21], [16, 22], [16, 23], [16, 24], [16, 26], [16, 27], [16, 28], [16, 31], [16, 34], [16, 37], [16, 38], [16, 40], [16, 41], [16, 42], [16, 47], [16, 49], [16, 50], [16, 54], [16, 57], [16, 59], [16, 60], [16, 62], [16, 64], [16, 68], [16, 71], [16, 73], [16, 76], [16, 78], [16, 82], [16, 84], [16, 88], [16, 89], [16, 91], [16, 95], [16, 97], [16, 100], [16, 102], [16, 103], [16, 104], [16, 108], [16, 109], [16, 110], [16, 112], [16, 114], [16, 116], [16, 117], [16, 118], [17, 18], [17, 20], [17, 21], [17, 22], [17, 23], [17, 26], [17, 27], [17, 28], [17, 29], [17, 33], [17, 34], [17, 37], [17, 38], [17, 41], [17, 42], [17, 44], [17, 45], [17, 46], [17, 47], [17, 50], [17, 53], [17, 55], [17, 58], [17, 62], [17, 64], [17, 65], [17, 68], [17, 69], [17, 70], [17, 75], [17, 77], [17, 78], [17, 80], [17, 81], [17, 82], [17, 85], [17, 92], [17, 93], [17, 95], [17, 100], [17, 103], [17, 104], [17, 105], [17, 106], [17, 107], [17, 112], [17, 114], [17, 115], [17, 116], [17, 119], [18, 21], [18, 28], [18, 33], [18, 34], [18, 35], [18, 36], [18, 38], [18, 39], [18, 42], [18, 43], [18, 44], [18, 45], [18, 47], [18, 48], [18, 51], [18, 54], [18, 55], [18, 58], [18, 60], [18, 62], [18, 63], [18, 66], [18, 69], [18, 72], [18, 73], [18, 76], [18, 78], [18, 80], [18, 81], [18, 83], [18, 87], [18, 88], [18, 89], [18, 91], [18, 93], [18, 94], [18, 96], [18, 97], [18, 98], [18, 99], [18, 100], [18, 101], [18, 104], [18, 106], [18, 108], [18, 110], [18, 111], [18, 114], [19, 20], [19, 22], [19, 23], [19, 28], [19, 33], [19, 34], [19, 35], [19, 36], [19, 37], [19, 38], [19, 39], [19, 40], [19, 41], [19, 42], [19, 43], [19, 45], [19, 46], [19, 49], [19, 51], [19, 52], [19, 54], [19, 57], [19, 59], [19, 63], [19, 67], [19, 69], [19, 70], [19, 71], [19, 72], [19, 74], [19, 75], [19, 76], [19, 77], [19, 82], [19, 83], [19, 84], [19, 85], [19, 86], [19, 87], [19, 88], [19, 90], [19, 91], [19, 92], [19, 93], [19, 96], [19, 97], [19, 98], [19, 100], [19, 101], [19, 103], [19, 104], [19, 105], [19, 107], [19, 111], [19, 112], [19, 113], [19, 118], [19, 119], [20, 21], [20, 25], [20, 28], [20, 29], [20, 30], [20, 31], [20, 35], [20, 36], [20, 38], [20, 39], [20, 41], [20, 42], [20, 43], [20, 44], [20, 48], [20, 49], [20, 53], [20, 55], [20, 56], [20, 57], [20, 59], [20, 62], [20, 67], [20, 70], [20, 71], [20, 72], [20, 74], [20, 75], [20, 76], [20, 77], [20, 79], [20, 80], [20, 83], [20, 84], [20, 86], [20, 89], [20, 91], [20, 92], [20, 95], [20, 96], [20, 97], [20, 102], [20, 103], [20, 105], [20, 106], [20, 107], [20, 108], [20, 110], [20, 111], [20, 115], [20, 116], [20, 117], [20, 118], [20, 119], [21, 23], [21, 26], [21, 27], [21, 32], [21, 34], [21, 35], [21, 36], [21, 37], [21, 41], [21, 42], [21, 44], [21, 45], [21, 46], [21, 48], [21, 49], [21, 53], [21, 59], [21, 60], [21, 63], [21, 65], [21, 66], [21, 70], [21, 72], [21, 73], [21, 74], [21, 75], [21, 76], [21, 79], [21, 81], [21, 86], [21, 87], [21, 90], [21, 91], [21, 93], [21, 95], [21, 96], [21, 98], [21, 99], [21, 100], [21, 102], [21, 103], [21, 105], [21, 107], [21, 109], [21, 114], [21, 115], [21, 117], [21, 119], [22, 27], [22, 28], [22, 29], [22, 30], [22, 31], [22, 32], [22, 35], [22, 36], [22, 37], [22, 41], [22, 42], [22, 43], [22, 45], [22, 46], [22, 47], [22, 49], [22, 50], [22, 51], [22, 52], [22, 53], [22, 54], [22, 57], [22, 59], [22, 63], [22, 65], [22, 66], [22, 67], [22, 71], [22, 72], [22, 74], [22, 75], [22, 76], [22, 81], [22, 83], [22, 85], [22, 87], [22, 91], [22, 94], [22, 98], [22, 99], [22, 101], [22, 102], [22, 103], [22, 104], [22, 105], [22, 106], [22, 107], [22, 109], [22, 110], [22, 115], [22, 117], [22, 119], [23, 24], [23, 26], [23, 27], [23, 28], [23, 31], [23, 32], [23, 39], [23, 41], [23, 44], [23, 45], [23, 46], [23, 47], [23, 52], [23, 53], [23, 55], [23, 58], [23, 59], [23, 60], [23, 62], [23, 63], [23, 65], [23, 68], [23, 69], [23, 70], [23, 72], [23, 74], [23, 80], [23, 82], [23, 84], [23, 86], [23, 88], [23, 90], [23, 91], [23, 93], [23, 94], [23, 95], [23, 98], [23, 99], [23, 100], [23, 102], [23, 106], [23, 110], [23, 111], [23, 113], [23, 114], [23, 116], [23, 117], [23, 118], [23, 119], [24, 25], [24, 27], [24, 28], [24, 29], [24, 31], [24, 32], [24, 35], [24, 40], [24, 42], [24, 44], [24, 46], [24, 49], [24, 50], [24, 51], [24, 53], [24, 55], [24, 57], [24, 58], [24, 62], [24, 64], [24, 66], [24, 68], [24, 71], [24, 74], [24, 76], [24, 77], [24, 78], [24, 82], [24, 85], [24, 87], [24, 89], [24, 92], [24, 94], [24, 95], [24, 96], [24, 97], [24, 99], [24, 102], [24, 103], [24, 105], [24, 109], [24, 110], [24, 111], [24, 112], [24, 115], [24, 119], [25, 26], [25, 32], [25, 33], [25, 35], [25, 39], [25, 40], [25, 41], [25, 42], [25, 43], [25, 46], [25, 47], [25, 50], [25, 52], [25, 53], [25, 58], [25, 60], [25, 64], [25, 65], [25, 67], [25, 69], [25, 70], [25, 71], [25, 72], [25, 73], [25, 74], [25, 76], [25, 78], [25, 79], [25, 80], [25, 81], [25, 84], [25, 85], [25, 86], [25, 88], [25, 93], [25, 94], [25, 95], [25, 96], [25, 97], [25, 101], [25, 103], [25, 105], [25, 107], [25, 108], [25, 109], [25, 113], [25, 115], [25, 116], [25, 118], [26, 27], [26, 29], [26, 30], [26, 31], [26, 32], [26, 33], [26, 34], [26, 35], [26, 36], [26, 38], [26, 39], [26, 41], [26, 42], [26, 43], [26, 44], [26, 46], [26, 47], [26, 48], [26, 50], [26, 58], [26, 60], [26, 61], [26, 62], [26, 63], [26, 64], [26, 66], [26, 67], [26, 68], [26, 69], [26, 72], [26, 73], [26, 75], [26, 77], [26, 78], [26, 80], [26, 84], [26, 85], [26, 86], [26, 87], [26, 89], [26, 91], [26, 93], [26, 94], [26, 95], [26, 96], [26, 97], [26, 98], [26, 99], [26, 102], [26, 104], [26, 105], [26, 106], [26, 107], [26, 110], [26, 111], [26, 113], [26, 114], [26, 115], [26, 116], [26, 117], [27, 28], [27, 29], [27, 31], [27, 35], [27, 40], [27, 41], [27, 44], [27, 45], [27, 46], [27, 47], [27, 48], [27, 50], [27, 52], [27, 55], [27, 56], [27, 58], [27, 60], [27, 61], [27, 62], [27, 65], [27, 66], [27, 70], [27, 71], [27, 72], [27, 73], [27, 75], [27, 78], [27, 84], [27, 85], [27, 86], [27, 88], [27, 89], [27, 90], [27, 91], [27, 92], [27, 95], [27, 99], [27, 101], [27, 102], [27, 105], [27, 107], [27, 110], [27, 111], [27, 112], [27, 114], [27, 116], [27, 118], [27, 119], [28, 29], [28, 30], [28, 31], [28, 33], [28, 34], [28, 40], [28, 43], [28, 44], [28, 46], [28, 50], [28, 51], [28, 53], [28, 54], [28, 55], [28, 56], [28, 58], [28, 61], [28, 62], [28, 63], [28, 65], [28, 67], [28, 68], [28, 73], [28, 75], [28, 76], [28, 77], [28, 78], [28, 81], [28, 83], [28, 85], [28, 86], [28, 87], [28, 88], [28, 89], [28, 91], [28, 93], [28, 96], [28, 100], [28, 101], [28, 102], [28, 103], [28, 104], [28, 106], [28, 107], [28, 109], [28, 110], [28, 113], [28, 116], [28, 117], [28, 118], [28, 119], [29, 31], [29, 32], [29, 33], [29, 34], [29, 36], [29, 37], [29, 39], [29, 43], [29, 44], [29, 47], [29, 49], [29, 50], [29, 52], [29, 53], [29, 56], [29, 57], [29, 58], [29, 60], [29, 61], [29, 62], [29, 66], [29, 68], [29, 70], [29, 71], [29, 72], [29, 73], [29, 74], [29, 75], [29, 76], [29, 77], [29, 81], [29, 83], [29, 87], [29, 89], [29, 92], [29, 93], [29, 94], [29, 96], [29, 97], [29, 100], [29, 102], [29, 105], [29, 106], [29, 108], [29, 110], [29, 113], [29, 114], [29, 116], [29, 117], [29, 118], [30, 31], [30, 33], [30, 34], [30, 35], [30, 37], [30, 38], [30, 40], [30, 41], [30, 42], [30, 45], [30, 46], [30, 47], [30, 50], [30, 56], [30, 57], [30, 59], [30, 61], [30, 64], [30, 65], [30, 66], [30, 67], [30, 69], [30, 70], [30, 71], [30, 74], [30, 75], [30, 81], [30, 87], [30, 91], [30, 92], [30, 95], [30, 96], [30, 99], [30, 105], [30, 106], [30, 109], [30, 111], [30, 112], [30, 113], [30, 114], [30, 115], [30, 116], [30, 118], [31, 32], [31, 33], [31, 34], [31, 36], [31, 37], [31, 38], [31, 39], [31, 46], [31, 47], [31, 48], [31, 50], [31, 51], [31, 52], [31, 53], [31, 54], [31, 57], [31, 58], [31, 60], [31, 61], [31, 62], [31, 63], [31, 65], [31, 66], [31, 69], [31, 71], [31, 75], [31, 76], [31, 77], [31, 78], [31, 83], [31, 87], [31, 89], [31, 91], [31, 94], [31, 98], [31, 99], [31, 100], [31, 103], [31, 104], [31, 106], [31, 107], [31, 108], [31, 109], [31, 110], [31, 113], [31, 114], [31, 115], [31, 116], [31, 118], [32, 33], [32, 34], [32, 35], [32, 36], [32, 38], [32, 39], [32, 40], [32, 42], [32, 44], [32, 45], [32, 46], [32, 47], [32, 50], [32, 51], [32, 52], [32, 56], [32, 57], [32, 59], [32, 60], [32, 61], [32, 62], [32, 64], [32, 65], [32, 68], [32, 71], [32, 72], [32, 73], [32, 74], [32, 78], [32, 80], [32, 81], [32, 82], [32, 83], [32, 87], [32, 88], [32, 89], [32, 91], [32, 92], [32, 93], [32, 94], [32, 95], [32, 97], [32, 99], [32, 100], [32, 103], [32, 104], [32, 105], [32, 106], [32, 110], [32, 112], [32, 115], [32, 116], [32, 118], [32, 119], [33, 34], [33, 37], [33, 38], [33, 39], [33, 40], [33, 41], [33, 42], [33, 44], [33, 45], [33, 46], [33, 48], [33, 49], [33, 50], [33, 51], [33, 53], [33, 55], [33, 56], [33, 57], [33, 60], [33, 61], [33, 65], [33, 68], [33, 70], [33, 71], [33, 72], [33, 74], [33, 75], [33, 76], [33, 78], [33, 79], [33, 81], [33, 83], [33, 84], [33, 87], [33, 89], [33, 91], [33, 94], [33, 95], [33, 96], [33, 99], [33, 100], [33, 101], [33, 102], [33, 104], [33, 105], [33, 112], [33, 113], [33, 119], [34, 40], [34, 41], [34, 46], [34, 49], [34, 50], [34, 54], [34, 55], [34, 59], [34, 65], [34, 67], [34, 71], [34, 74], [34, 75], [34, 76], [34, 80], [34, 81], [34, 84], [34, 85], [34, 88], [34, 89], [34, 91], [34, 92], [34, 95], [34, 97], [34, 100], [34, 101], [34, 102], [34, 104], [34, 109], [34, 110], [34, 111], [34, 112], [34, 117], [34, 118], [34, 119], [35, 38], [35, 39], [35, 41], [35, 46], [35, 47], [35, 48], [35, 51], [35, 53], [35, 54], [35, 56], [35, 57], [35, 59], [35, 60], [35, 62], [35, 63], [35, 64], [35, 65], [35, 69], [35, 72], [35, 73], [35, 76], [35, 77], [35, 78], [35, 84], [35, 85], [35, 86], [35, 87], [35, 94], [35, 95], [35, 96], [35, 97], [35, 98], [35, 99], [35, 100], [35, 101], [35, 104], [35, 105], [35, 107], [35, 108], [35, 112], [35, 114], [35, 116], [35, 118], [36, 37], [36, 38], [36, 39], [36, 42], [36, 45], [36, 50], [36, 53], [36, 54], [36, 55], [36, 56], [36, 61], [36, 63], [36, 66], [36, 70], [36, 73], [36, 75], [36, 79], [36, 82], [36, 83], [36, 84], [36, 85], [36, 86], [36, 87], [36, 88], [36, 93], [36, 95], [36, 97], [36, 99], [36, 105], [36, 107], [36, 109], [36, 110], [36, 112], [36, 113], [36, 114], [36, 115], [36, 116], [36, 119], [37, 39], [37, 40], [37, 41], [37, 42], [37, 43], [37, 44], [37, 45], [37, 46], [37, 48], [37, 49], [37, 52], [37, 55], [37, 59], [37, 60], [37, 61], [37, 62], [37, 65], [37, 68], [37, 69], [37, 70], [37, 71], [37, 73], [37, 75], [37, 76], [37, 78], [37, 81], [37, 82], [37, 83], [37, 85], [37, 86], [37, 89], [37, 91], [37, 94], [37, 95], [37, 99], [37, 104], [37, 110], [37, 111], [37, 112], [37, 113], [37, 114], [37, 116], [37, 119], [38, 39], [38, 41], [38, 42], [38, 46], [38, 47], [38, 48], [38, 51], [38, 52], [38, 53], [38, 54], [38, 59], [38, 60], [38, 61], [38, 62], [38, 64], [38, 69], [38, 70], [38, 72], [38, 75], [38, 76], [38, 79], [38, 80], [38, 82], [38, 83], [38, 85], [38, 88], [38, 90], [38, 93], [38, 94], [38, 96], [38, 97], [38, 99], [38, 100], [38, 104], [38, 108], [38, 111], [38, 112], [38, 114], [38, 116], [38, 117], [38, 119], [39, 44], [39, 46], [39, 48], [39, 49], [39, 53], [39, 54], [39, 56], [39, 60], [39, 65], [39, 66], [39, 67], [39, 71], [39, 72], [39, 73], [39, 74], [39, 77], [39, 79], [39, 82], [39, 84], [39, 86], [39, 89], [39, 91], [39, 94], [39, 95], [39, 96], [39, 99], [39, 100], [39, 101], [39, 103], [39, 105], [39, 111], [39, 112], [39, 115], [39, 116], [40, 41], [40, 42], [40, 43], [40, 46], [40, 47], [40, 50], [40, 56], [40, 57], [40, 58], [40, 59], [40, 61], [40, 65], [40, 67], [40, 68], [40, 75], [40, 77], [40, 78], [40, 79], [40, 81], [40, 82], [40, 87], [40, 89], [40, 90], [40, 91], [40, 92], [40, 93], [40, 95], [40, 96], [40, 98], [40, 100], [40, 102], [40, 108], [40, 109], [40, 110], [40, 111], [40, 112], [40, 113], [40, 118], [40, 119], [41, 43], [41, 44], [41, 45], [41, 46], [41, 47], [41, 51], [41, 52], [41, 54], [41, 55], [41, 56], [41, 64], [41, 65], [41, 67], [41, 70], [41, 73], [41, 74], [41, 75], [41, 79], [41, 80], [41, 81], [41, 82], [41, 84], [41, 86], [41, 87], [41, 88], [41, 89], [41, 92], [41, 96], [41, 102], [41, 103], [41, 105], [41, 106], [41, 107], [41, 109], [41, 110], [41, 112], [41, 113], [41, 119], [42, 44], [42, 48], [42, 50], [42, 53], [42, 55], [42, 56], [42, 59], [42, 63], [42, 65], [42, 69], [42, 70], [42, 74], [42, 76], [42, 77], [42, 79], [42, 81], [42, 86], [42, 93], [42, 94], [42, 97], [42, 98], [42, 99], [42, 101], [42, 102], [42, 104], [42, 105], [42, 107], [42, 109], [42, 110], [42, 111], [42, 117], [42, 119], [43, 44], [43, 47], [43, 48], [43, 49], [43, 51], [43, 55], [43, 56], [43, 57], [43, 58], [43, 63], [43, 64], [43, 67], [43, 70], [43, 76], [43, 82], [43, 84], [43, 87], [43, 88], [43, 89], [43, 92], [43, 93], [43, 96], [43, 98], [43, 100], [43, 102], [43, 103], [43, 104], [43, 107], [43, 108], [43, 109], [43, 110], [43, 111], [43, 112], [43, 113], [43, 118], [43, 119], [44, 45], [44, 46], [44, 47], [44, 50], [44, 52], [44, 53], [44, 56], [44, 58], [44, 62], [44, 63], [44, 67], [44, 69], [44, 75], [44, 78], [44, 83], [44, 84], [44, 87], [44, 90], [44, 91], [44, 95], [44, 96], [44, 97], [44, 100], [44, 101], [44, 102], [44, 104], [44, 105], [44, 107], [44, 110], [44, 111], [44, 113], [44, 114], [44, 118], [45, 47], [45, 49], [45, 52], [45, 55], [45, 56], [45, 57], [45, 59], [45, 60], [45, 61], [45, 63], [45, 64], [45, 69], [45, 70], [45, 71], [45, 72], [45, 73], [45, 74], [45, 75], [45, 76], [45, 79], [45, 80], [45, 82], [45, 83], [45, 84], [45, 85], [45, 86], [45, 87], [45, 88], [45, 89], [45, 90], [45, 91], [45, 93], [45, 94], [45, 98], [45, 100], [45, 101], [45, 107], [45, 115], [45, 116], [45, 117], [46, 48], [46, 53], [46, 54], [46, 56], [46, 57], [46, 58], [46, 60], [46, 61], [46, 62], [46, 63], [46, 65], [46, 66], [46, 67], [46, 68], [46, 70], [46, 74], [46, 76], [46, 77], [46, 78], [46, 80], [46, 81], [46, 84], [46, 85], [46, 86], [46, 87], [46, 88], [46, 92], [46, 93], [46, 94], [46, 96], [46, 98], [46, 99], [46, 100], [46, 104], [46, 106], [46, 108], [46, 112], [46, 113], [46, 114], [46, 115], [46, 118], [46, 119], [47, 48], [47, 50], [47, 52], [47, 53], [47, 54], [47, 55], [47, 56], [47, 60], [47, 61], [47, 63], [47, 64], [47, 65], [47, 66], [47, 68], [47, 70], [47, 73], [47, 74], [47, 75], [47, 76], [47, 78], [47, 80], [47, 81], [47, 88], [47, 89], [47, 91], [47, 92], [47, 93], [47, 94], [47, 95], [47, 96], [47, 97], [47, 98], [47, 99], [47, 100], [47, 101], [47, 102], [47, 103], [47, 106], [47, 107], [47, 109], [47, 110], [47, 113], [47, 114], [47, 116], [47, 117], [47, 118], [48, 49], [48, 53], [48, 54], [48, 55], [48, 57], [48, 58], [48, 59], [48, 60], [48, 65], [48, 68], [48, 71], [48, 72], [48, 73], [48, 76], [48, 77], [48, 79], [48, 83], [48, 84], [48, 86], [48, 91], [48, 97], [48, 100], [48, 101], [48, 102], [48, 103], [48, 110], [48, 112], [48, 113], [48, 117], [48, 118], [48, 119], [49, 53], [49, 54], [49, 57], [49, 61], [49, 67], [49, 69], [49, 71], [49, 74], [49, 75], [49, 76], [49, 78], [49, 79], [49, 82], [49, 83], [49, 85], [49, 88], [49, 93], [49, 94], [49, 99], [49, 101], [49, 104], [49, 106], [49, 107], [49, 109], [49, 111], [49, 115], [50, 51], [50, 52], [50, 55], [50, 57], [50, 59], [50, 62], [50, 64], [50, 66], [50, 67], [50, 68], [50, 69], [50, 70], [50, 73], [50, 74], [50, 76], [50, 77], [50, 78], [50, 80], [50, 81], [50, 82], [50, 86], [50, 87], [50, 88], [50, 89], [50, 91], [50, 92], [50, 93], [50, 96], [50, 98], [50, 100], [50, 101], [50, 102], [50, 103], [50, 104], [50, 108], [50, 109], [50, 111], [50, 115], [50, 117], [51, 52], [51, 55], [51, 56], [51, 57], [51, 58], [51, 59], [51, 61], [51, 62], [51, 65], [51, 67], [51, 68], [51, 69], [51, 70], [51, 71], [51, 72], [51, 73], [51, 75], [51, 77], [51, 80], [51, 86], [51, 89], [51, 91], [51, 93], [51, 95], [51, 99], [51, 100], [51, 101], [51, 102], [51, 103], [51, 110], [51, 113], [51, 114], [51, 118], [52, 55], [52, 58], [52, 60], [52, 61], [52, 64], [52, 65], [52, 66], [52, 70], [52, 71], [52, 73], [52, 76], [52, 77], [52, 78], [52, 79], [52, 80], [52, 82], [52, 85], [52, 86], [52, 87], [52, 88], [52, 89], [52, 90], [52, 92], [52, 93], [52, 94], [52, 96], [52, 97], [52, 102], [52, 104], [52, 106], [52, 107], [52, 113], [52, 115], [52, 118], [53, 56], [53, 63], [53, 67], [53, 70], [53, 71], [53, 72], [53, 73], [53, 74], [53, 75], [53, 76], [53, 77], [53, 78], [53, 79], [53, 81], [53, 83], [53, 86], [53, 88], [53, 89], [53, 92], [53, 93], [53, 94], [53, 95], [53, 96], [53, 97], [53, 98], [53, 100], [53, 101], [53, 104], [53, 105], [53, 106], [53, 107], [53, 108], [53, 111], [53, 112], [53, 115], [53, 117], [54, 60], [54, 61], [54, 63], [54, 64], [54, 66], [54, 68], [54, 69], [54, 72], [54, 75], [54, 77], [54, 78], [54, 79], [54, 80], [54, 81], [54, 89], [54, 90], [54, 91], [54, 92], [54, 93], [54, 94], [54, 95], [54, 97], [54, 104], [54, 105], [54, 106], [54, 108], [54, 109], [54, 112], [54, 113], [54, 115], [54, 116], [54, 118], [55, 64], [55, 65], [55, 67], [55, 68], [55, 71], [55, 73], [55, 78], [55, 81], [55, 82], [55, 83], [55, 85], [55, 88], [55, 89], [55, 90], [55, 91], [55, 93], [55, 94], [55, 95], [55, 96], [55, 97], [55, 98], [55, 99], [55, 100], [55, 101], [55, 102], [55, 103], [55, 104], [55, 107], [55, 112], [56, 58], [56, 59], [56, 60], [56, 63], [56, 65], [56, 66], [56, 67], [56, 69], [56, 70], [56, 71], [56, 72], [56, 73], [56, 77], [56, 78], [56, 80], [56, 81], [56, 82], [56, 87], [56, 96], [56, 98], [56, 102], [56, 105], [56, 107], [56, 110], [56, 111], [56, 112], [56, 113], [56, 114], [56, 118], [56, 119], [57, 59], [57, 60], [57, 61], [57, 62], [57, 63], [57, 64], [57, 65], [57, 69], [57, 72], [57, 79], [57, 82], [57, 84], [57, 86], [57, 87], [57, 90], [57, 95], [57, 96], [57, 100], [57, 101], [57, 102], [57, 103], [57, 104], [57, 105], [57, 108], [57, 109], [57, 110], [57, 114], [57, 115], [57, 116], [57, 117], [57, 119], [58, 60], [58, 63], [58, 64], [58, 65], [58, 67], [58, 69], [58, 70], [58, 71], [58, 72], [58, 73], [58, 74], [58, 75], [58, 77], [58, 82], [58, 85], [58, 86], [58, 87], [58, 88], [58, 89], [58, 91], [58, 93], [58, 94], [58, 95], [58, 96], [58, 97], [58, 98], [58, 101], [58, 102], [58, 105], [58, 106], [58, 107], [58, 110], [58, 112], [58, 114], [58, 117], [59, 62], [59, 64], [59, 65], [59, 69], [59, 75], [59, 76], [59, 77], [59, 79], [59, 80], [59, 83], [59, 84], [59, 85], [59, 86], [59, 88], [59, 89], [59, 90], [59, 94], [59, 95], [59, 96], [59, 99], [59, 100], [59, 101], [59, 105], [59, 107], [59, 109], [59, 111], [59, 112], [59, 113], [59, 116], [59, 117], [59, 118], [59, 119], [60, 62], [60, 63], [60, 65], [60, 66], [60, 67], [60, 69], [60, 75], [60, 76], [60, 80], [60, 82], [60, 83], [60, 84], [60, 85], [60, 86], [60, 89], [60, 93], [60, 95], [60, 97], [60, 99], [60, 100], [60, 104], [60, 105], [60, 107], [60, 110], [60, 111], [60, 112], [60, 113], [60, 114], [60, 116], [60, 117], [60, 118], [61, 63], [61, 66], [61, 67], [61, 71], [61, 76], [61, 77], [61, 79], [61, 80], [61, 82], [61, 83], [61, 84], [61, 86], [61, 87], [61, 88], [61, 90], [61, 98], [61, 99], [61, 100], [61, 103], [61, 104], [61, 105], [61, 107], [61, 110], [61, 112], [61, 115], [61, 116], [61, 118], [61, 119], [62, 64], [62, 65], [62, 66], [62, 68], [62, 69], [62, 74], [62, 75], [62, 77], [62, 78], [62, 80], [62, 83], [62, 84], [62, 85], [62, 87], [62, 88], [62, 89], [62, 90], [62, 92], [62, 94], [62, 98], [62, 99], [62, 101], [62, 102], [62, 104], [62, 105], [62, 106], [62, 107], [62, 108], [62, 110], [62, 111], [62, 113], [62, 116], [62, 117], [62, 119], [63, 66], [63, 67], [63, 68], [63, 71], [63, 72], [63, 73], [63, 74], [63, 75], [63, 76], [63, 80], [63, 81], [63, 82], [63, 84], [63, 85], [63, 87], [63, 94], [63, 95], [63, 96], [63, 102], [63, 104], [63, 108], [63, 111], [63, 113], [63, 114], [63, 115], [63, 116], [64, 66], [64, 70], [64, 77], [64, 79], [64, 80], [64, 81], [64, 82], [64, 87], [64, 88], [64, 90], [64, 91], [64, 94], [64, 96], [64, 98], [64, 101], [64, 103], [64, 105], [64, 109], [64, 110], [64, 113], [64, 115], [64, 116], [64, 118], [64, 119], [65, 66], [65, 68], [65, 71], [65, 74], [65, 76], [65, 77], [65, 79], [65, 80], [65, 81], [65, 82], [65, 83], [65, 84], [65, 85], [65, 88], [65, 89], [65, 100], [65, 101], [65, 102], [65, 104], [65, 109], [65, 110], [65, 116], [66, 67], [66, 70], [66, 73], [66, 75], [66, 76], [66, 77], [66, 79], [66, 82], [66, 83], [66, 84], [66, 85], [66, 86], [66, 89], [66, 90], [66, 92], [66, 93], [66, 94], [66, 95], [66, 96], [66, 100], [66, 101], [66, 103], [66, 104], [66, 105], [66, 107], [66, 109], [66, 110], [66, 111], [66, 113], [66, 114], [66, 115], [66, 116], [66, 117], [66, 118], [66, 119], [67, 68], [67, 71], [67, 72], [67, 73], [67, 74], [67, 78], [67, 79], [67, 83], [67, 85], [67, 86], [67, 90], [67, 92], [67, 94], [67, 95], [67, 96], [67, 98], [67, 99], [67, 100], [67, 101], [67, 104], [67, 107], [67, 110], [67, 111], [67, 113], [67, 114], [67, 116], [68, 71], [68, 72], [68, 73], [68, 75], [68, 76], [68, 82], [68, 84], [68, 92], [68, 93], [68, 97], [68, 99], [68, 100], [68, 102], [68, 105], [68, 107], [68, 111], [68, 114], [68, 117], [68, 118], [69, 71], [69, 74], [69, 77], [69, 78], [69, 80], [69, 81], [69, 83], [69, 84], [69, 92], [69, 93], [69, 94], [69, 95], [69, 96], [69, 97], [69, 100], [69, 102], [69, 103], [69, 104], [69, 106], [69, 108], [69, 109], [69, 110], [69, 113], [69, 115], [69, 117], [69, 119], [70, 72], [70, 74], [70, 75], [70, 77], [70, 78], [70, 79], [70, 80], [70, 81], [70, 86], [70, 88], [70, 91], [70, 97], [70, 99], [70, 100], [70, 103], [70, 108], [70, 109], [70, 110], [70, 111], [70, 113], [70, 115], [70, 116], [70, 117], [71, 72], [71, 74], [71, 76], [71, 77], [71, 79], [71, 83], [71, 85], [71, 88], [71, 89], [71, 90], [71, 93], [71, 94], [71, 95], [71, 99], [71, 100], [71, 103], [71, 104], [71, 107], [71, 108], [71, 109], [71, 110], [71, 111], [71, 116], [72, 73], [72, 75], [72, 76], [72, 78], [72, 79], [72, 80], [72, 83], [72, 85], [72, 86], [72, 87], [72, 90], [72, 93], [72, 95], [72, 97], [72, 104], [72, 106], [72, 111], [72, 113], [72, 114], [72, 117], [72, 118], [73, 78], [73, 79], [73, 81], [73, 83], [73, 88], [73, 90], [73, 93], [73, 96], [73, 102], [73, 104], [73, 105], [73, 109], [73, 111], [73, 112], [73, 115], [73, 116], [74, 76], [74, 77], [74, 78], [74, 80], [74, 81], [74, 83], [74, 84], [74, 85], [74, 88], [74, 89], [74, 90], [74, 92], [74, 95], [74, 96], [74, 98], [74, 99], [74, 100], [74, 102], [74, 104], [74, 105], [74, 111], [74, 112], [74, 115], [74, 116], [74, 117], [75, 76], [75, 77], [75, 82], [75, 87], [75, 88], [75, 89], [75, 90], [75, 93], [75, 95], [75, 96], [75, 97], [75, 98], [75, 99], [75, 100], [75, 101], [75, 104], [75, 107], [75, 110], [75, 112], [75, 114], [75, 116], [75, 117], [75, 118], [76, 79], [76, 80], [76, 82], [76, 85], [76, 89], [76, 90], [76, 91], [76, 93], [76, 95], [76, 99], [76, 100], [76, 101], [76, 102], [76, 103], [76, 107], [76, 108], [76, 109], [76, 110], [76, 111], [76, 112], [76, 114], [76, 115], [76, 116], [76, 118], [77, 79], [77, 81], [77, 82], [77, 88], [77, 90], [77, 91], [77, 92], [77, 96], [77, 99], [77, 103], [77, 108], [77, 109], [77, 110], [77, 113], [77, 114], [77, 115], [77, 116], [77, 117], [77, 118], [77, 119], [78, 81], [78, 83], [78, 89], [78, 91], [78, 93], [78, 94], [78, 96], [78, 98], [78, 99], [78, 100], [78, 101], [78, 102], [78, 104], [78, 106], [78, 107], [78, 109], [78, 110], [78, 112], [78, 116], [78, 119], [79, 80], [79, 82], [79, 84], [79, 85], [79, 88], [79, 90], [79, 91], [79, 92], [79, 94], [79, 95], [79, 98], [79, 99], [79, 100], [79, 103], [79, 104], [79, 105], [79, 113], [79, 114], [79, 115], [80, 82], [80, 89], [80, 90], [80, 91], [80, 96], [80, 97], [80, 100], [80, 101], [80, 105], [80, 106], [80, 107], [80, 108], [80, 109], [80, 111], [80, 115], [80, 117], [80, 119], [81, 84], [81, 86], [81, 87], [81, 88], [81, 89], [81, 91], [81, 95], [81, 97], [81, 99], [81, 100], [81, 105], [81, 107], [81, 108], [81, 109], [81, 110], [81, 112], [81, 114], [81, 115], [81, 116], [81, 118], [81, 119], [82, 84], [82, 85], [82, 86], [82, 88], [82, 89], [82, 92], [82, 93], [82, 95], [82, 96], [82, 99], [82, 100], [82, 104], [82, 105], [82, 108], [82, 110], [82, 114], [82, 115], [82, 116], [82, 117], [82, 119], [83, 86], [83, 88], [83, 89], [83, 93], [83, 95], [83, 96], [83, 98], [83, 101], [83, 102], [83, 104], [83, 106], [83, 113], [83, 115], [83, 118], [83, 119], [84, 85], [84, 86], [84, 91], [84, 97], [84, 98], [84, 99], [84, 100], [84, 101], [84, 102], [84, 103], [84, 104], [84, 108], [84, 109], [84, 110], [84, 112], [84, 113], [84, 114], [84, 116], [84, 117], [84, 119], [85, 88], [85, 90], [85, 91], [85, 93], [85, 94], [85, 95], [85, 97], [85, 98], [85, 99], [85, 100], [85, 103], [85, 105], [85, 107], [85, 108], [85, 109], [85, 116], [85, 117], [86, 87], [86, 90], [86, 94], [86, 95], [86, 96], [86, 100], [86, 101], [86, 102], [86, 107], [86, 108], [86, 109], [86, 111], [86, 113], [86, 115], [86, 116], [86, 119], [87, 89], [87, 90], [87, 91], [87, 92], [87, 93], [87, 94], [87, 96], [87, 97], [87, 99], [87, 101], [87, 103], [87, 105], [87, 106], [87, 107], [87, 110], [87, 111], [87, 113], [87, 114], [87, 115], [87, 118], [88, 89], [88, 91], [88, 92], [88, 93], [88, 98], [88, 101], [88, 102], [88, 103], [88, 104], [88, 109], [88, 112], [88, 115], [88, 117], [88, 118], [88, 119], [89, 90], [89, 91], [89, 93], [89, 95], [89, 96], [89, 97], [89, 99], [89, 100], [89, 106], [89, 107], [89, 108], [89, 110], [89, 111], [89, 112], [89, 113], [89, 114], [89, 116], [89, 118], [89, 119], [90, 91], [90, 92], [90, 93], [90, 94], [90, 96], [90, 97], [90, 98], [90, 100], [90, 101], [90, 104], [90, 107], [90, 109], [90, 110], [90, 114], [90, 116], [90, 117], [90, 118], [90, 119], [91, 92], [91, 95], [91, 97], [91, 99], [91, 101], [91, 106], [91, 108], [91, 109], [91, 112], [91, 113], [91, 116], [91, 117], [91, 119], [92, 93], [92, 94], [92, 96], [92, 97], [92, 98], [92, 104], [92, 105], [92, 108], [92, 109], [92, 113], [92, 116], [92, 117], [93, 94], [93, 95], [93, 98], [93, 99], [93, 100], [93, 101], [93, 105], [93, 107], [93, 111], [93, 117], [93, 118], [94, 95], [94, 96], [94, 97], [94, 98], [94, 100], [94, 102], [94, 104], [94, 107], [94, 108], [94, 110], [94, 113], [94, 114], [94, 115], [94, 116], [94, 117], [94, 119], [95, 97], [95, 99], [95, 100], [95, 105], [95, 108], [95, 111], [95, 114], [95, 115], [95, 118], [96, 97], [96, 100], [96, 101], [96, 102], [96, 104], [96, 105], [96, 107], [96, 109], [96, 110], [96, 117], [96, 119], [97, 100], [97, 102], [97, 105], [97, 106], [97, 108], [97, 112], [97, 113], [97, 115], [97, 116], [97, 117], [97, 119], [98, 100], [98, 101], [98, 104], [98, 105], [98, 107], [98, 108], [98, 110], [98, 111], [98, 113], [98, 115], [98, 116], [98, 119], [99, 102], [99, 104], [99, 105], [99, 106], [99, 109], [99, 110], [99, 111], [99, 112], [99, 113], [99, 115], [100, 103], [100, 105], [100, 106], [100, 107], [100, 108], [100, 109], [100, 110], [100, 112], [100, 114], [100, 115], [100, 116], [100, 117], [100, 118], [101, 104], [101, 106], [101, 112], [101, 116], [101, 119], [102, 103], [102, 105], [102, 107], [102, 108], [102, 109], [102, 112], [102, 116], [102, 117], [103, 105], [103, 106], [103, 108], [103, 109], [103, 113], [103, 114], [103, 117], [104, 106], [104, 108], [104, 109], [104, 111], [104, 112], [104, 118], [105, 106], [105, 108], [105, 111], [105, 117], [105, 119], [106, 107], [106, 108], [106, 109], [106, 111], [106, 112], [106, 116], [106, 118], [107, 110], [107, 111], [107, 113], [107, 116], [108, 113], [108, 115], [108, 119], [109, 110], [109, 115], [109, 117], [109, 119], [110, 113], [110, 114], [110, 115], [110, 116], [110, 117], [110, 118], [111, 113], [111, 119], [112, 114], [113, 114], [113, 116], [113, 117], [113, 119], [114, 115], [114, 116], [114, 118], [114, 119], [115, 116], [115, 119], [116, 117], [116, 118], [117, 118], [117, 119], [118, 119]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l6-s2/tests/run.py b/tasks/construct-mc-max-clique-l6-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-clique-l6-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-clique-l6-s2/tests/test.sh b/tasks/construct-mc-max-clique-l6-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-clique-l6-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-clique-l6-s5/environment/Dockerfile b/tasks/construct-mc-max-clique-l6-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-clique-l6-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-clique-l6-s5/environment/instance.json b/tasks/construct-mc-max-clique-l6-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d9aed8cebd5972452237bb85c6b94dc62fb557ce --- /dev/null +++ b/tasks/construct-mc-max-clique-l6-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 120, "k": 13, "edges": [[0, 3], [0, 4], [0, 7], [0, 9], [0, 10], [0, 12], [0, 15], [0, 16], [0, 18], [0, 19], [0, 21], [0, 23], [0, 24], [0, 26], [0, 27], [0, 28], [0, 29], [0, 30], [0, 31], [0, 32], [0, 33], [0, 34], [0, 36], [0, 37], [0, 38], [0, 43], [0, 44], [0, 45], [0, 46], [0, 52], [0, 56], [0, 57], [0, 58], [0, 59], [0, 60], [0, 63], [0, 65], [0, 66], [0, 67], [0, 68], [0, 69], [0, 70], [0, 72], [0, 74], [0, 75], [0, 76], [0, 78], [0, 84], [0, 85], [0, 86], [0, 87], [0, 89], [0, 90], [0, 92], [0, 93], [0, 94], [0, 103], [0, 106], [0, 108], [0, 110], [0, 111], [0, 113], [0, 115], [1, 2], [1, 5], [1, 10], [1, 12], [1, 13], [1, 14], [1, 16], [1, 18], [1, 19], [1, 21], [1, 23], [1, 25], [1, 31], [1, 33], [1, 34], [1, 36], [1, 37], [1, 38], [1, 39], [1, 43], [1, 46], [1, 48], [1, 50], [1, 51], [1, 54], [1, 56], [1, 58], [1, 60], [1, 61], [1, 62], [1, 63], [1, 65], [1, 66], [1, 70], [1, 71], [1, 73], [1, 75], [1, 76], [1, 77], [1, 79], [1, 83], [1, 85], [1, 88], [1, 89], [1, 90], [1, 91], [1, 92], [1, 93], [1, 94], [1, 95], [1, 101], [1, 104], [1, 106], [1, 109], [1, 110], [1, 114], [1, 117], [1, 118], [2, 5], [2, 6], [2, 8], [2, 9], [2, 12], [2, 13], [2, 15], [2, 17], [2, 18], [2, 19], [2, 23], [2, 24], [2, 28], [2, 29], [2, 33], [2, 34], [2, 37], [2, 43], [2, 46], [2, 48], [2, 49], [2, 50], [2, 54], [2, 55], [2, 56], [2, 59], [2, 63], [2, 67], [2, 70], [2, 71], [2, 74], [2, 75], [2, 77], [2, 79], [2, 80], [2, 82], [2, 84], [2, 87], [2, 89], [2, 91], [2, 92], [2, 93], [2, 94], [2, 95], [2, 96], [2, 98], [2, 99], [2, 100], [2, 103], [2, 104], [2, 105], [2, 108], [2, 109], [2, 110], [2, 111], [2, 112], [2, 113], [2, 115], [2, 117], [2, 118], [2, 119], [3, 5], [3, 8], [3, 10], [3, 11], [3, 15], [3, 17], [3, 18], [3, 20], [3, 23], [3, 30], [3, 32], [3, 37], [3, 41], [3, 42], [3, 43], [3, 46], [3, 47], [3, 51], [3, 53], [3, 55], [3, 59], [3, 60], [3, 62], [3, 64], [3, 68], [3, 70], [3, 71], [3, 72], [3, 73], [3, 74], [3, 83], [3, 84], [3, 85], [3, 86], [3, 88], [3, 90], [3, 93], [3, 95], [3, 96], [3, 97], [3, 98], [3, 99], [3, 103], [3, 105], [3, 106], [3, 107], [3, 109], [3, 110], [3, 111], [3, 115], [3, 116], [3, 118], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 12], [4, 14], [4, 15], [4, 18], [4, 20], [4, 22], [4, 23], [4, 24], [4, 26], [4, 32], [4, 36], [4, 41], [4, 45], [4, 47], [4, 50], [4, 52], [4, 55], [4, 56], [4, 58], [4, 59], [4, 61], [4, 62], [4, 63], [4, 64], [4, 66], [4, 67], [4, 68], [4, 75], [4, 76], [4, 77], [4, 78], [4, 79], [4, 83], [4, 85], [4, 87], [4, 88], [4, 89], [4, 90], [4, 92], [4, 93], [4, 96], [4, 98], [4, 100], [4, 108], [4, 109], [4, 110], [4, 111], [4, 115], [4, 116], [4, 117], [4, 119], [5, 6], [5, 9], [5, 10], [5, 12], [5, 14], [5, 18], [5, 26], [5, 27], [5, 29], [5, 32], [5, 34], [5, 35], [5, 41], [5, 43], [5, 45], [5, 46], [5, 49], [5, 50], [5, 54], [5, 55], [5, 56], [5, 57], [5, 60], [5, 61], [5, 62], [5, 64], [5, 65], [5, 66], [5, 69], [5, 70], [5, 73], [5, 74], [5, 75], [5, 77], [5, 78], [5, 79], [5, 80], [5, 81], [5, 82], [5, 83], [5, 90], [5, 92], [5, 93], [5, 95], [5, 96], [5, 98], [5, 99], [5, 102], [5, 103], [5, 104], [5, 105], [5, 106], [5, 107], [5, 109], [5, 110], [5, 111], [5, 112], [5, 114], [5, 117], [5, 118], [5, 119], [6, 7], [6, 10], [6, 12], [6, 14], [6, 15], [6, 18], [6, 20], [6, 21], [6, 22], [6, 26], [6, 29], [6, 31], [6, 32], [6, 33], [6, 34], [6, 39], [6, 40], [6, 42], [6, 43], [6, 45], [6, 47], [6, 48], [6, 49], [6, 52], [6, 53], [6, 54], [6, 56], [6, 57], [6, 63], [6, 65], [6, 67], [6, 68], [6, 71], [6, 72], [6, 74], [6, 75], [6, 79], [6, 80], [6, 82], [6, 83], [6, 84], [6, 86], [6, 90], [6, 91], [6, 95], [6, 96], [6, 97], [6, 98], [6, 99], [6, 102], [6, 106], [6, 108], [6, 110], [6, 111], [6, 113], [6, 114], [6, 116], [6, 119], [7, 9], [7, 10], [7, 12], [7, 14], [7, 15], [7, 19], [7, 20], [7, 21], [7, 23], [7, 25], [7, 28], [7, 31], [7, 32], [7, 33], [7, 34], [7, 43], [7, 45], [7, 47], [7, 48], [7, 49], [7, 50], [7, 53], [7, 54], [7, 55], [7, 56], [7, 58], [7, 59], [7, 60], [7, 63], [7, 65], [7, 67], [7, 72], [7, 73], [7, 75], [7, 80], [7, 81], [7, 84], [7, 85], [7, 87], [7, 90], [7, 91], [7, 92], [7, 93], [7, 95], [7, 97], [7, 98], [7, 101], [7, 103], [7, 105], [7, 106], [7, 107], [7, 110], [7, 111], [7, 113], [7, 114], [7, 115], [7, 116], [7, 117], [8, 9], [8, 10], [8, 12], [8, 15], [8, 16], [8, 20], [8, 21], [8, 22], [8, 23], [8, 25], [8, 26], [8, 28], [8, 31], [8, 34], [8, 37], [8, 39], [8, 51], [8, 52], [8, 53], [8, 54], [8, 56], [8, 57], [8, 58], [8, 60], [8, 61], [8, 62], [8, 63], [8, 65], [8, 66], [8, 68], [8, 70], [8, 71], [8, 73], [8, 74], [8, 75], [8, 76], [8, 77], [8, 78], [8, 80], [8, 81], [8, 85], [8, 87], [8, 89], [8, 90], [8, 94], [8, 95], [8, 96], [8, 98], [8, 99], [8, 101], [8, 102], [8, 106], [8, 107], [8, 108], [8, 109], [8, 110], [8, 111], [8, 113], [8, 114], [8, 119], [9, 11], [9, 14], [9, 15], [9, 17], [9, 20], [9, 21], [9, 22], [9, 26], [9, 27], [9, 28], [9, 29], [9, 31], [9, 34], [9, 39], [9, 42], [9, 43], [9, 45], [9, 47], [9, 49], [9, 50], [9, 53], [9, 54], [9, 58], [9, 60], [9, 61], [9, 63], [9, 64], [9, 65], [9, 67], [9, 69], [9, 70], [9, 73], [9, 74], [9, 75], [9, 77], [9, 78], [9, 79], [9, 81], [9, 82], [9, 83], [9, 84], [9, 85], [9, 86], [9, 89], [9, 91], [9, 92], [9, 93], [9, 95], [9, 96], [9, 97], [9, 98], [9, 99], [9, 100], [9, 102], [9, 103], [9, 104], [9, 108], [9, 109], [9, 111], [9, 114], [10, 11], [10, 14], [10, 15], [10, 17], [10, 18], [10, 21], [10, 26], [10, 28], [10, 30], [10, 31], [10, 32], [10, 33], [10, 34], [10, 35], [10, 36], [10, 39], [10, 40], [10, 42], [10, 43], [10, 44], [10, 45], [10, 48], [10, 49], [10, 52], [10, 54], [10, 55], [10, 57], [10, 58], [10, 59], [10, 61], [10, 64], [10, 65], [10, 68], [10, 69], [10, 70], [10, 72], [10, 74], [10, 77], [10, 81], [10, 84], [10, 87], [10, 89], [10, 90], [10, 93], [10, 94], [10, 96], [10, 100], [10, 102], [10, 104], [10, 105], [10, 106], [10, 107], [10, 108], [10, 114], [10, 116], [10, 117], [10, 119], [11, 15], [11, 16], [11, 18], [11, 19], [11, 23], [11, 27], [11, 28], [11, 30], [11, 31], [11, 33], [11, 34], [11, 35], [11, 37], [11, 38], [11, 39], [11, 40], [11, 41], [11, 42], [11, 44], [11, 45], [11, 46], [11, 49], [11, 50], [11, 52], [11, 56], [11, 57], [11, 58], [11, 59], [11, 60], [11, 63], [11, 64], [11, 69], [11, 77], [11, 78], [11, 80], [11, 81], [11, 82], [11, 85], [11, 86], [11, 87], [11, 88], [11, 90], [11, 94], [11, 97], [11, 101], [11, 102], [11, 104], [11, 106], [11, 107], [11, 108], [11, 111], [11, 112], [11, 113], [11, 114], [12, 14], [12, 15], [12, 16], [12, 17], [12, 22], [12, 23], [12, 25], [12, 26], [12, 32], [12, 41], [12, 46], [12, 47], [12, 50], [12, 51], [12, 52], [12, 58], [12, 59], [12, 60], [12, 61], [12, 64], [12, 67], [12, 69], [12, 70], [12, 71], [12, 76], [12, 77], [12, 78], [12, 79], [12, 80], [12, 81], [12, 84], [12, 85], [12, 88], [12, 91], [12, 92], [12, 94], [12, 97], [12, 102], [12, 104], [12, 106], [12, 108], [12, 110], [12, 111], [12, 116], [12, 117], [13, 17], [13, 20], [13, 25], [13, 26], [13, 27], [13, 29], [13, 30], [13, 32], [13, 35], [13, 37], [13, 40], [13, 49], [13, 50], [13, 52], [13, 55], [13, 56], [13, 57], [13, 59], [13, 62], [13, 64], [13, 68], [13, 69], [13, 72], [13, 75], [13, 77], [13, 79], [13, 81], [13, 83], [13, 85], [13, 87], [13, 88], [13, 89], [13, 90], [13, 93], [13, 94], [13, 100], [13, 101], [13, 102], [13, 104], [13, 105], [13, 106], [13, 108], [13, 109], [13, 110], [13, 112], [13, 113], [13, 117], [13, 119], [14, 21], [14, 23], [14, 28], [14, 29], [14, 31], [14, 35], [14, 37], [14, 39], [14, 40], [14, 42], [14, 44], [14, 47], [14, 48], [14, 49], [14, 53], [14, 54], [14, 55], [14, 57], [14, 58], [14, 59], [14, 61], [14, 63], [14, 65], [14, 67], [14, 68], [14, 69], [14, 71], [14, 72], [14, 73], [14, 74], [14, 76], [14, 77], [14, 81], [14, 84], [14, 88], [14, 92], [14, 100], [14, 103], [14, 104], [14, 105], [14, 109], [14, 112], [14, 115], [14, 116], [14, 117], [15, 19], [15, 21], [15, 23], [15, 24], [15, 25], [15, 26], [15, 28], [15, 29], [15, 30], [15, 32], [15, 33], [15, 34], [15, 37], [15, 39], [15, 41], [15, 42], [15, 43], [15, 47], [15, 50], [15, 53], [15, 56], [15, 58], [15, 62], [15, 64], [15, 67], [15, 68], [15, 69], [15, 71], [15, 72], [15, 73], [15, 75], [15, 77], [15, 79], [15, 80], [15, 83], [15, 84], [15, 87], [15, 88], [15, 91], [15, 92], [15, 97], [15, 98], [15, 100], [15, 103], [15, 104], [15, 105], [15, 108], [15, 109], [15, 110], [15, 113], [15, 114], [15, 115], [15, 116], [15, 117], [15, 118], [16, 17], [16, 20], [16, 21], [16, 27], [16, 28], [16, 29], [16, 30], [16, 31], [16, 34], [16, 36], [16, 39], [16, 40], [16, 42], [16, 46], [16, 48], [16, 49], [16, 50], [16, 51], [16, 54], [16, 56], [16, 57], [16, 61], [16, 63], [16, 64], [16, 65], [16, 66], [16, 70], [16, 71], [16, 78], [16, 80], [16, 81], [16, 85], [16, 90], [16, 91], [16, 92], [16, 94], [16, 97], [16, 99], [16, 100], [16, 104], [16, 105], [16, 106], [16, 108], [16, 109], [16, 111], [16, 112], [16, 113], [16, 114], [16, 115], [16, 117], [16, 118], [17, 19], [17, 20], [17, 21], [17, 22], [17, 26], [17, 27], [17, 29], [17, 32], [17, 33], [17, 34], [17, 35], [17, 36], [17, 39], [17, 40], [17, 42], [17, 45], [17, 47], [17, 48], [17, 49], [17, 51], [17, 52], [17, 54], [17, 57], [17, 58], [17, 63], [17, 65], [17, 68], [17, 69], [17, 75], [17, 76], [17, 78], [17, 79], [17, 80], [17, 81], [17, 84], [17, 86], [17, 88], [17, 89], [17, 90], [17, 91], [17, 92], [17, 93], [17, 94], [17, 96], [17, 97], [17, 99], [17, 100], [17, 101], [17, 102], [17, 103], [17, 104], [17, 105], [17, 106], [17, 109], [17, 111], [17, 114], [17, 115], [17, 116], [17, 117], [18, 19], [18, 20], [18, 23], [18, 24], [18, 26], [18, 27], [18, 29], [18, 31], [18, 32], [18, 33], [18, 37], [18, 38], [18, 41], [18, 43], [18, 46], [18, 47], [18, 48], [18, 51], [18, 52], [18, 53], [18, 58], [18, 59], [18, 63], [18, 65], [18, 67], [18, 70], [18, 71], [18, 73], [18, 75], [18, 76], [18, 77], [18, 81], [18, 83], [18, 86], [18, 88], [18, 90], [18, 91], [18, 92], [18, 96], [18, 98], [18, 99], [18, 100], [18, 101], [18, 107], [18, 108], [18, 109], [18, 111], [18, 113], [18, 115], [18, 118], [18, 119], [19, 22], [19, 23], [19, 24], [19, 25], [19, 26], [19, 31], [19, 32], [19, 33], [19, 34], [19, 35], [19, 36], [19, 37], [19, 38], [19, 40], [19, 43], [19, 44], [19, 46], [19, 47], [19, 52], [19, 56], [19, 57], [19, 58], [19, 61], [19, 62], [19, 63], [19, 70], [19, 73], [19, 74], [19, 77], [19, 81], [19, 83], [19, 84], [19, 86], [19, 88], [19, 90], [19, 93], [19, 94], [19, 95], [19, 98], [19, 100], [19, 103], [19, 104], [19, 106], [19, 107], [19, 108], [19, 109], [19, 110], [19, 113], [19, 114], [19, 115], [19, 117], [20, 21], [20, 22], [20, 24], [20, 25], [20, 26], [20, 27], [20, 29], [20, 32], [20, 33], [20, 36], [20, 39], [20, 41], [20, 42], [20, 43], [20, 45], [20, 48], [20, 49], [20, 54], [20, 58], [20, 59], [20, 61], [20, 64], [20, 65], [20, 67], [20, 71], [20, 72], [20, 74], [20, 82], [20, 84], [20, 86], [20, 90], [20, 99], [20, 100], [20, 102], [20, 105], [20, 106], [20, 107], [20, 108], [20, 109], [20, 113], [20, 118], [21, 22], [21, 24], [21, 26], [21, 27], [21, 28], [21, 29], [21, 34], [21, 35], [21, 36], [21, 39], [21, 40], [21, 41], [21, 42], [21, 43], [21, 44], [21, 45], [21, 48], [21, 49], [21, 50], [21, 51], [21, 53], [21, 54], [21, 57], [21, 60], [21, 61], [21, 66], [21, 72], [21, 73], [21, 74], [21, 75], [21, 76], [21, 77], [21, 81], [21, 82], [21, 83], [21, 86], [21, 89], [21, 90], [21, 92], [21, 93], [21, 94], [21, 98], [21, 99], [21, 100], [21, 101], [21, 102], [21, 105], [21, 107], [21, 108], [21, 109], [21, 111], [21, 112], [21, 116], [21, 117], [22, 23], [22, 27], [22, 28], [22, 29], [22, 30], [22, 31], [22, 32], [22, 34], [22, 36], [22, 37], [22, 38], [22, 41], [22, 42], [22, 44], [22, 46], [22, 47], [22, 48], [22, 51], [22, 55], [22, 56], [22, 58], [22, 60], [22, 61], [22, 64], [22, 65], [22, 66], [22, 67], [22, 68], [22, 70], [22, 71], [22, 73], [22, 74], [22, 75], [22, 77], [22, 78], [22, 79], [22, 80], [22, 81], [22, 85], [22, 86], [22, 87], [22, 89], [22, 90], [22, 91], [22, 93], [22, 94], [22, 96], [22, 98], [22, 99], [22, 100], [22, 101], [22, 105], [22, 107], [22, 111], [22, 113], [22, 116], [22, 119], [23, 24], [23, 25], [23, 27], [23, 28], [23, 29], [23, 30], [23, 31], [23, 32], [23, 35], [23, 36], [23, 38], [23, 41], [23, 44], [23, 46], [23, 50], [23, 54], [23, 55], [23, 57], [23, 59], [23, 60], [23, 64], [23, 66], [23, 71], [23, 73], [23, 74], [23, 77], [23, 78], [23, 80], [23, 87], [23, 89], [23, 90], [23, 91], [23, 100], [23, 103], [23, 104], [23, 106], [23, 111], [23, 112], [23, 118], [23, 119], [24, 29], [24, 32], [24, 33], [24, 34], [24, 35], [24, 37], [24, 38], [24, 40], [24, 41], [24, 44], [24, 50], [24, 51], [24, 52], [24, 53], [24, 55], [24, 59], [24, 60], [24, 61], [24, 64], [24, 65], [24, 66], [24, 67], [24, 68], [24, 72], [24, 75], [24, 76], [24, 77], [24, 81], [24, 83], [24, 84], [24, 85], [24, 88], [24, 91], [24, 93], [24, 94], [24, 98], [24, 99], [24, 104], [24, 105], [24, 106], [24, 108], [24, 111], [24, 112], [24, 117], [24, 118], [24, 119], [25, 27], [25, 28], [25, 29], [25, 30], [25, 32], [25, 33], [25, 34], [25, 35], [25, 41], [25, 44], [25, 45], [25, 52], [25, 53], [25, 63], [25, 64], [25, 65], [25, 66], [25, 68], [25, 70], [25, 71], [25, 72], [25, 75], [25, 78], [25, 82], [25, 88], [25, 89], [25, 90], [25, 91], [25, 92], [25, 95], [25, 100], [25, 101], [25, 102], [25, 103], [25, 106], [25, 110], [25, 112], [25, 113], [25, 117], [25, 118], [25, 119], [26, 27], [26, 28], [26, 29], [26, 31], [26, 36], [26, 38], [26, 42], [26, 43], [26, 44], [26, 45], [26, 47], [26, 49], [26, 50], [26, 51], [26, 52], [26, 53], [26, 54], [26, 55], [26, 59], [26, 60], [26, 65], [26, 66], [26, 68], [26, 70], [26, 71], [26, 72], [26, 74], [26, 75], [26, 81], [26, 86], [26, 89], [26, 90], [26, 92], [26, 94], [26, 97], [26, 99], [26, 100], [26, 102], [26, 103], [26, 106], [26, 107], [26, 108], [26, 109], [26, 111], [26, 115], [26, 117], [26, 119], [27, 28], [27, 31], [27, 32], [27, 34], [27, 35], [27, 36], [27, 37], [27, 41], [27, 43], [27, 46], [27, 48], [27, 52], [27, 53], [27, 54], [27, 56], [27, 57], [27, 58], [27, 59], [27, 61], [27, 63], [27, 64], [27, 66], [27, 73], [27, 75], [27, 76], [27, 79], [27, 80], [27, 81], [27, 82], [27, 83], [27, 85], [27, 88], [27, 89], [27, 91], [27, 92], [27, 93], [27, 94], [27, 97], [27, 101], [27, 104], [27, 106], [27, 113], [27, 118], [27, 119], [28, 29], [28, 30], [28, 35], [28, 38], [28, 39], [28, 40], [28, 43], [28, 46], [28, 48], [28, 49], [28, 50], [28, 51], [28, 57], [28, 59], [28, 60], [28, 61], [28, 62], [28, 63], [28, 65], [28, 66], [28, 67], [28, 68], [28, 70], [28, 72], [28, 73], [28, 76], [28, 80], [28, 82], [28, 83], [28, 85], [28, 86], [28, 87], [28, 89], [28, 90], [28, 93], [28, 94], [28, 95], [28, 100], [28, 103], [28, 108], [28, 109], [28, 110], [28, 111], [28, 112], [28, 115], [28, 117], [28, 118], [28, 119], [29, 30], [29, 37], [29, 39], [29, 41], [29, 42], [29, 43], [29, 45], [29, 47], [29, 48], [29, 50], [29, 51], [29, 52], [29, 56], [29, 57], [29, 58], [29, 60], [29, 63], [29, 65], [29, 70], [29, 71], [29, 73], [29, 74], [29, 75], [29, 77], [29, 80], [29, 84], [29, 85], [29, 86], [29, 87], [29, 88], [29, 89], [29, 91], [29, 94], [29, 95], [29, 98], [29, 101], [29, 102], [29, 104], [29, 107], [29, 111], [29, 112], [29, 115], [30, 31], [30, 32], [30, 33], [30, 34], [30, 35], [30, 36], [30, 43], [30, 44], [30, 45], [30, 46], [30, 49], [30, 51], [30, 52], [30, 53], [30, 54], [30, 57], [30, 62], [30, 64], [30, 67], [30, 71], [30, 73], [30, 74], [30, 75], [30, 76], [30, 81], [30, 82], [30, 83], [30, 86], [30, 87], [30, 90], [30, 91], [30, 93], [30, 94], [30, 95], [30, 100], [30, 105], [30, 106], [30, 107], [30, 108], [30, 110], [30, 111], [30, 114], [30, 115], [30, 117], [30, 118], [30, 119], [31, 34], [31, 35], [31, 36], [31, 37], [31, 38], [31, 40], [31, 42], [31, 44], [31, 46], [31, 48], [31, 49], [31, 51], [31, 52], [31, 54], [31, 55], [31, 59], [31, 60], [31, 62], [31, 63], [31, 66], [31, 68], [31, 69], [31, 74], [31, 76], [31, 81], [31, 82], [31, 84], [31, 86], [31, 88], [31, 89], [31, 95], [31, 97], [31, 99], [31, 102], [31, 105], [31, 106], [31, 107], [31, 113], [31, 117], [31, 118], [32, 33], [32, 35], [32, 37], [32, 38], [32, 39], [32, 40], [32, 41], [32, 42], [32, 43], [32, 45], [32, 46], [32, 47], [32, 49], [32, 51], [32, 52], [32, 59], [32, 60], [32, 61], [32, 62], [32, 65], [32, 66], [32, 68], [32, 69], [32, 70], [32, 72], [32, 75], [32, 80], [32, 81], [32, 84], [32, 85], [32, 86], [32, 87], [32, 89], [32, 90], [32, 92], [32, 93], [32, 95], [32, 96], [32, 103], [32, 104], [32, 105], [32, 107], [32, 108], [32, 112], [32, 114], [32, 115], [32, 116], [32, 118], [32, 119], [33, 37], [33, 38], [33, 39], [33, 40], [33, 42], [33, 44], [33, 47], [33, 49], [33, 55], [33, 58], [33, 59], [33, 60], [33, 61], [33, 64], [33, 66], [33, 68], [33, 69], [33, 70], [33, 71], [33, 72], [33, 73], [33, 75], [33, 78], [33, 79], [33, 82], [33, 85], [33, 88], [33, 91], [33, 92], [33, 96], [33, 99], [33, 101], [33, 103], [33, 105], [33, 106], [33, 107], [33, 109], [33, 110], [33, 111], [33, 113], [33, 114], [33, 117], [33, 118], [33, 119], [34, 36], [34, 43], [34, 47], [34, 49], [34, 50], [34, 51], [34, 52], [34, 55], [34, 56], [34, 61], [34, 66], [34, 69], [34, 72], [34, 73], [34, 74], [34, 75], [34, 76], [34, 77], [34, 86], [34, 88], [34, 89], [34, 91], [34, 92], [34, 93], [34, 95], [34, 96], [34, 97], [34, 98], [34, 101], [34, 102], [34, 105], [34, 110], [34, 115], [34, 116], [34, 117], [35, 37], [35, 39], [35, 40], [35, 41], [35, 43], [35, 44], [35, 51], [35, 52], [35, 53], [35, 54], [35, 55], [35, 56], [35, 59], [35, 60], [35, 62], [35, 63], [35, 68], [35, 69], [35, 70], [35, 72], [35, 74], [35, 76], [35, 77], [35, 79], [35, 81], [35, 84], [35, 86], [35, 87], [35, 89], [35, 90], [35, 92], [35, 93], [35, 94], [35, 95], [35, 97], [35, 99], [35, 101], [35, 104], [35, 105], [35, 109], [35, 114], [35, 117], [35, 119], [36, 39], [36, 40], [36, 42], [36, 43], [36, 44], [36, 45], [36, 46], [36, 49], [36, 50], [36, 53], [36, 54], [36, 55], [36, 56], [36, 58], [36, 60], [36, 61], [36, 66], [36, 69], [36, 70], [36, 74], [36, 75], [36, 77], [36, 80], [36, 81], [36, 84], [36, 88], [36, 89], [36, 90], [36, 91], [36, 93], [36, 95], [36, 100], [36, 101], [36, 108], [36, 111], [36, 118], [37, 38], [37, 41], [37, 42], [37, 43], [37, 44], [37, 45], [37, 47], [37, 48], [37, 49], [37, 51], [37, 53], [37, 59], [37, 60], [37, 61], [37, 63], [37, 64], [37, 66], [37, 70], [37, 73], [37, 74], [37, 75], [37, 77], [37, 79], [37, 82], [37, 83], [37, 84], [37, 87], [37, 88], [37, 92], [37, 93], [37, 95], [37, 96], [37, 98], [37, 100], [37, 102], [37, 103], [37, 104], [37, 109], [37, 110], [37, 111], [37, 112], [37, 113], [37, 114], [37, 115], [37, 116], [37, 119], [38, 40], [38, 44], [38, 45], [38, 47], [38, 48], [38, 50], [38, 55], [38, 57], [38, 59], [38, 60], [38, 67], [38, 69], [38, 71], [38, 77], [38, 80], [38, 81], [38, 82], [38, 83], [38, 85], [38, 86], [38, 89], [38, 91], [38, 95], [38, 102], [38, 104], [38, 105], [38, 107], [38, 109], [38, 110], [38, 111], [38, 113], [38, 114], [38, 115], [38, 118], [38, 119], [39, 40], [39, 44], [39, 45], [39, 49], [39, 53], [39, 55], [39, 58], [39, 59], [39, 60], [39, 61], [39, 64], [39, 65], [39, 67], [39, 69], [39, 74], [39, 76], [39, 77], [39, 78], [39, 79], [39, 82], [39, 84], [39, 85], [39, 87], [39, 88], [39, 91], [39, 92], [39, 93], [39, 95], [39, 97], [39, 100], [39, 101], [39, 103], [39, 105], [39, 106], [39, 109], [39, 110], [39, 111], [39, 112], [39, 116], [39, 118], [39, 119], [40, 42], [40, 44], [40, 46], [40, 47], [40, 49], [40, 50], [40, 51], [40, 54], [40, 55], [40, 56], [40, 58], [40, 62], [40, 63], [40, 65], [40, 66], [40, 71], [40, 73], [40, 74], [40, 75], [40, 76], [40, 77], [40, 78], [40, 80], [40, 83], [40, 87], [40, 88], [40, 90], [40, 91], [40, 92], [40, 93], [40, 96], [40, 99], [40, 102], [40, 107], [40, 108], [40, 109], [40, 116], [41, 42], [41, 44], [41, 47], [41, 48], [41, 52], [41, 53], [41, 58], [41, 59], [41, 60], [41, 61], [41, 63], [41, 66], [41, 67], [41, 68], [41, 69], [41, 70], [41, 71], [41, 72], [41, 75], [41, 77], [41, 78], [41, 80], [41, 81], [41, 84], [41, 85], [41, 89], [41, 90], [41, 91], [41, 92], [41, 94], [41, 95], [41, 96], [41, 98], [41, 101], [41, 102], [41, 104], [41, 107], [41, 108], [41, 109], [41, 110], [41, 117], [41, 118], [42, 44], [42, 46], [42, 49], [42, 51], [42, 52], [42, 53], [42, 54], [42, 55], [42, 56], [42, 59], [42, 67], [42, 69], [42, 71], [42, 72], [42, 73], [42, 74], [42, 76], [42, 77], [42, 78], [42, 84], [42, 85], [42, 87], [42, 89], [42, 90], [42, 92], [42, 94], [42, 95], [42, 96], [42, 98], [42, 99], [42, 101], [42, 102], [42, 106], [42, 107], [42, 109], [42, 110], [42, 111], [42, 114], [42, 115], [42, 116], [42, 117], [42, 119], [43, 44], [43, 45], [43, 47], [43, 48], [43, 49], [43, 51], [43, 52], [43, 54], [43, 55], [43, 59], [43, 62], [43, 66], [43, 67], [43, 68], [43, 69], [43, 72], [43, 73], [43, 75], [43, 77], [43, 78], [43, 79], [43, 81], [43, 84], [43, 86], [43, 87], [43, 89], [43, 91], [43, 92], [43, 93], [43, 94], [43, 95], [43, 96], [43, 98], [43, 99], [43, 100], [43, 104], [43, 105], [43, 107], [43, 108], [43, 111], [43, 113], [43, 114], [43, 115], [43, 118], [43, 119], [44, 45], [44, 46], [44, 50], [44, 53], [44, 54], [44, 56], [44, 57], [44, 58], [44, 62], [44, 64], [44, 65], [44, 66], [44, 67], [44, 68], [44, 72], [44, 73], [44, 78], [44, 79], [44, 81], [44, 82], [44, 83], [44, 84], [44, 87], [44, 91], [44, 93], [44, 95], [44, 96], [44, 98], [44, 101], [44, 103], [44, 108], [44, 110], [44, 112], [44, 116], [44, 117], [44, 118], [45, 46], [45, 50], [45, 51], [45, 56], [45, 57], [45, 58], [45, 64], [45, 67], [45, 72], [45, 73], [45, 74], [45, 77], [45, 79], [45, 80], [45, 81], [45, 86], [45, 87], [45, 89], [45, 90], [45, 92], [45, 97], [45, 100], [45, 103], [45, 107], [45, 113], [45, 115], [45, 116], [45, 117], [45, 118], [46, 47], [46, 51], [46, 53], [46, 54], [46, 57], [46, 60], [46, 63], [46, 64], [46, 67], [46, 69], [46, 74], [46, 75], [46, 77], [46, 79], [46, 80], [46, 81], [46, 82], [46, 88], [46, 89], [46, 90], [46, 93], [46, 95], [46, 96], [46, 98], [46, 99], [46, 101], [46, 103], [46, 105], [46, 106], [46, 107], [46, 111], [46, 113], [46, 114], [46, 115], [46, 116], [46, 118], [47, 50], [47, 53], [47, 54], [47, 58], [47, 63], [47, 65], [47, 67], [47, 68], [47, 69], [47, 70], [47, 72], [47, 75], [47, 76], [47, 79], [47, 81], [47, 84], [47, 86], [47, 88], [47, 90], [47, 91], [47, 93], [47, 95], [47, 99], [47, 100], [47, 101], [47, 102], [47, 105], [47, 106], [47, 107], [47, 108], [47, 109], [47, 112], [47, 115], [47, 119], [48, 50], [48, 51], [48, 52], [48, 53], [48, 54], [48, 55], [48, 61], [48, 63], [48, 64], [48, 65], [48, 67], [48, 68], [48, 71], [48, 74], [48, 75], [48, 78], [48, 79], [48, 81], [48, 86], [48, 90], [48, 92], [48, 93], [48, 94], [48, 95], [48, 99], [48, 100], [48, 101], [48, 103], [48, 105], [48, 106], [48, 107], [48, 108], [48, 110], [48, 113], [48, 115], [49, 51], [49, 52], [49, 53], [49, 57], [49, 58], [49, 59], [49, 60], [49, 61], [49, 62], [49, 65], [49, 66], [49, 71], [49, 73], [49, 74], [49, 75], [49, 76], [49, 78], [49, 79], [49, 80], [49, 81], [49, 86], [49, 88], [49, 90], [49, 91], [49, 93], [49, 94], [49, 97], [49, 98], [49, 100], [49, 104], [49, 106], [49, 108], [49, 109], [49, 110], [49, 111], [49, 112], [49, 114], [49, 115], [49, 117], [49, 119], [50, 55], [50, 59], [50, 60], [50, 61], [50, 62], [50, 63], [50, 64], [50, 65], [50, 66], [50, 67], [50, 68], [50, 69], [50, 71], [50, 72], [50, 74], [50, 75], [50, 76], [50, 78], [50, 79], [50, 84], [50, 87], [50, 88], [50, 89], [50, 95], [50, 96], [50, 100], [50, 102], [50, 103], [50, 106], [50, 107], [50, 108], [50, 109], [50, 110], [50, 111], [50, 115], [50, 118], [51, 53], [51, 58], [51, 59], [51, 60], [51, 61], [51, 65], [51, 66], [51, 67], [51, 68], [51, 69], [51, 71], [51, 72], [51, 73], [51, 76], [51, 80], [51, 83], [51, 84], [51, 86], [51, 90], [51, 91], [51, 93], [51, 94], [51, 96], [51, 99], [51, 100], [51, 101], [51, 102], [51, 106], [51, 109], [51, 110], [51, 111], [51, 112], [51, 113], [51, 115], [51, 116], [51, 117], [51, 118], [51, 119], [52, 56], [52, 58], [52, 60], [52, 65], [52, 69], [52, 73], [52, 75], [52, 77], [52, 78], [52, 79], [52, 81], [52, 86], [52, 88], [52, 92], [52, 96], [52, 97], [52, 98], [52, 104], [52, 105], [52, 106], [52, 107], [52, 111], [52, 114], [52, 115], [52, 118], [53, 54], [53, 56], [53, 57], [53, 59], [53, 61], [53, 62], [53, 63], [53, 64], [53, 66], [53, 67], [53, 72], [53, 73], [53, 75], [53, 78], [53, 81], [53, 82], [53, 83], [53, 85], [53, 86], [53, 87], [53, 91], [53, 93], [53, 94], [53, 96], [53, 97], [53, 98], [53, 100], [53, 101], [53, 103], [53, 104], [53, 108], [53, 111], [53, 114], [53, 115], [53, 116], [53, 117], [53, 119], [54, 57], [54, 58], [54, 59], [54, 60], [54, 64], [54, 68], [54, 70], [54, 71], [54, 73], [54, 77], [54, 81], [54, 82], [54, 85], [54, 88], [54, 90], [54, 91], [54, 98], [54, 101], [54, 108], [54, 111], [54, 112], [54, 114], [54, 116], [54, 117], [54, 119], [55, 59], [55, 60], [55, 63], [55, 65], [55, 66], [55, 68], [55, 69], [55, 70], [55, 71], [55, 73], [55, 74], [55, 83], [55, 84], [55, 85], [55, 88], [55, 93], [55, 94], [55, 104], [55, 107], [55, 110], [55, 112], [55, 114], [55, 115], [56, 57], [56, 58], [56, 61], [56, 62], [56, 64], [56, 65], [56, 66], [56, 69], [56, 70], [56, 71], [56, 73], [56, 76], [56, 81], [56, 82], [56, 83], [56, 84], [56, 86], [56, 87], [56, 89], [56, 91], [56, 92], [56, 98], [56, 100], [56, 102], [56, 103], [56, 104], [56, 115], [56, 116], [56, 118], [57, 58], [57, 59], [57, 60], [57, 61], [57, 65], [57, 67], [57, 68], [57, 70], [57, 71], [57, 73], [57, 74], [57, 75], [57, 76], [57, 77], [57, 78], [57, 79], [57, 81], [57, 82], [57, 84], [57, 87], [57, 90], [57, 91], [57, 92], [57, 94], [57, 100], [57, 103], [57, 104], [57, 106], [57, 107], [57, 109], [57, 111], [57, 112], [57, 113], [57, 115], [57, 116], [57, 117], [57, 119], [58, 59], [58, 61], [58, 62], [58, 63], [58, 65], [58, 66], [58, 69], [58, 71], [58, 76], [58, 78], [58, 82], [58, 83], [58, 86], [58, 89], [58, 91], [58, 97], [58, 99], [58, 100], [58, 102], [58, 103], [58, 104], [58, 106], [58, 112], [58, 113], [58, 114], [58, 118], [59, 60], [59, 64], [59, 66], [59, 68], [59, 70], [59, 71], [59, 75], [59, 76], [59, 77], [59, 78], [59, 80], [59, 81], [59, 82], [59, 83], [59, 84], [59, 85], [59, 86], [59, 90], [59, 93], [59, 97], [59, 100], [59, 101], [59, 105], [59, 107], [59, 109], [59, 110], [59, 111], [59, 113], [59, 116], [59, 117], [59, 118], [60, 63], [60, 64], [60, 65], [60, 66], [60, 67], [60, 68], [60, 69], [60, 72], [60, 73], [60, 74], [60, 84], [60, 85], [60, 86], [60, 87], [60, 88], [60, 89], [60, 90], [60, 91], [60, 92], [60, 93], [60, 94], [60, 96], [60, 97], [60, 99], [60, 100], [60, 102], [60, 104], [60, 105], [60, 107], [60, 108], [60, 109], [60, 110], [60, 111], [60, 113], [60, 114], [60, 116], [60, 117], [60, 118], [60, 119], [61, 62], [61, 64], [61, 66], [61, 67], [61, 68], [61, 69], [61, 70], [61, 73], [61, 77], [61, 78], [61, 79], [61, 81], [61, 82], [61, 83], [61, 85], [61, 87], [61, 88], [61, 90], [61, 92], [61, 95], [61, 96], [61, 97], [61, 98], [61, 99], [61, 101], [61, 102], [61, 103], [61, 104], [61, 105], [61, 110], [61, 112], [61, 115], [61, 117], [61, 118], [62, 63], [62, 65], [62, 67], [62, 69], [62, 71], [62, 73], [62, 74], [62, 78], [62, 79], [62, 80], [62, 81], [62, 82], [62, 84], [62, 86], [62, 89], [62, 90], [62, 91], [62, 93], [62, 96], [62, 97], [62, 98], [62, 99], [62, 100], [62, 104], [62, 108], [62, 111], [62, 112], [62, 113], [62, 115], [62, 117], [62, 118], [63, 66], [63, 68], [63, 73], [63, 74], [63, 75], [63, 76], [63, 77], [63, 78], [63, 79], [63, 81], [63, 83], [63, 84], [63, 85], [63, 86], [63, 90], [63, 95], [63, 96], [63, 98], [63, 101], [63, 103], [63, 105], [63, 106], [63, 107], [63, 111], [63, 114], [63, 116], [63, 117], [64, 65], [64, 68], [64, 71], [64, 72], [64, 73], [64, 80], [64, 81], [64, 82], [64, 83], [64, 84], [64, 85], [64, 86], [64, 87], [64, 89], [64, 90], [64, 91], [64, 92], [64, 94], [64, 98], [64, 99], [64, 100], [64, 101], [64, 102], [64, 107], [64, 109], [64, 111], [64, 112], [64, 114], [64, 116], [64, 117], [65, 68], [65, 69], [65, 72], [65, 73], [65, 74], [65, 78], [65, 79], [65, 80], [65, 82], [65, 85], [65, 88], [65, 89], [65, 91], [65, 92], [65, 93], [65, 96], [65, 98], [65, 100], [65, 101], [65, 102], [65, 103], [65, 110], [65, 111], [65, 112], [65, 114], [65, 116], [65, 117], [65, 118], [65, 119], [66, 68], [66, 70], [66, 71], [66, 73], [66, 74], [66, 77], [66, 78], [66, 81], [66, 83], [66, 84], [66, 86], [66, 87], [66, 88], [66, 89], [66, 90], [66, 91], [66, 94], [66, 95], [66, 98], [66, 99], [66, 100], [66, 104], [66, 106], [66, 108], [66, 109], [66, 110], [66, 111], [66, 112], [66, 117], [66, 119], [67, 68], [67, 69], [67, 70], [67, 75], [67, 77], [67, 78], [67, 82], [67, 83], [67, 86], [67, 87], [67, 88], [67, 91], [67, 92], [67, 93], [67, 94], [67, 99], [67, 100], [67, 104], [67, 105], [67, 109], [67, 111], [67, 113], [67, 117], [67, 118], [68, 70], [68, 73], [68, 74], [68, 77], [68, 79], [68, 81], [68, 83], [68, 84], [68, 86], [68, 88], [68, 90], [68, 91], [68, 96], [68, 99], [68, 100], [68, 101], [68, 102], [68, 103], [68, 105], [68, 107], [68, 108], [68, 109], [68, 111], [68, 112], [68, 113], [68, 116], [68, 117], [69, 70], [69, 72], [69, 74], [69, 75], [69, 76], [69, 77], [69, 79], [69, 83], [69, 86], [69, 89], [69, 95], [69, 96], [69, 100], [69, 101], [69, 102], [69, 104], [69, 105], [69, 107], [69, 108], [69, 109], [69, 110], [69, 113], [69, 114], [69, 116], [70, 72], [70, 73], [70, 74], [70, 75], [70, 76], [70, 78], [70, 79], [70, 80], [70, 81], [70, 82], [70, 84], [70, 85], [70, 86], [70, 87], [70, 88], [70, 89], [70, 90], [70, 91], [70, 92], [70, 93], [70, 94], [70, 96], [70, 97], [70, 99], [70, 100], [70, 102], [70, 104], [70, 105], [70, 106], [70, 108], [70, 109], [70, 110], [70, 111], [70, 113], [70, 117], [71, 72], [71, 76], [71, 78], [71, 79], [71, 81], [71, 82], [71, 83], [71, 84], [71, 88], [71, 89], [71, 91], [71, 92], [71, 94], [71, 95], [71, 96], [71, 98], [71, 99], [71, 102], [71, 103], [71, 104], [71, 109], [71, 112], [71, 113], [71, 114], [71, 116], [71, 117], [72, 73], [72, 75], [72, 77], [72, 80], [72, 83], [72, 84], [72, 86], [72, 92], [72, 97], [72, 99], [72, 100], [72, 102], [72, 104], [72, 105], [72, 110], [72, 112], [72, 114], [72, 115], [72, 116], [72, 119], [73, 76], [73, 78], [73, 82], [73, 84], [73, 85], [73, 86], [73, 88], [73, 89], [73, 90], [73, 93], [73, 94], [73, 97], [73, 98], [73, 99], [73, 101], [73, 103], [73, 105], [73, 106], [73, 108], [73, 109], [73, 113], [73, 117], [74, 75], [74, 76], [74, 77], [74, 78], [74, 79], [74, 81], [74, 82], [74, 84], [74, 86], [74, 87], [74, 90], [74, 91], [74, 92], [74, 93], [74, 95], [74, 96], [74, 97], [74, 102], [74, 103], [74, 104], [74, 105], [74, 106], [74, 108], [74, 109], [74, 110], [74, 111], [74, 113], [74, 114], [74, 115], [74, 118], [75, 77], [75, 84], [75, 85], [75, 86], [75, 92], [75, 94], [75, 95], [75, 97], [75, 98], [75, 100], [75, 101], [75, 102], [75, 105], [75, 106], [75, 107], [75, 109], [75, 110], [75, 111], [75, 112], [75, 114], [75, 116], [75, 117], [75, 118], [76, 78], [76, 79], [76, 80], [76, 81], [76, 82], [76, 85], [76, 87], [76, 90], [76, 92], [76, 93], [76, 94], [76, 95], [76, 97], [76, 103], [76, 107], [76, 109], [76, 111], [76, 114], [76, 116], [77, 78], [77, 79], [77, 80], [77, 84], [77, 85], [77, 87], [77, 89], [77, 90], [77, 91], [77, 92], [77, 94], [77, 95], [77, 98], [77, 101], [77, 106], [77, 108], [77, 109], [77, 111], [77, 112], [77, 114], [77, 116], [77, 117], [78, 80], [78, 81], [78, 84], [78, 86], [78, 87], [78, 88], [78, 91], [78, 92], [78, 95], [78, 96], [78, 97], [78, 101], [78, 102], [78, 103], [78, 104], [78, 105], [78, 108], [78, 109], [78, 112], [78, 113], [78, 114], [78, 115], [78, 116], [78, 117], [78, 118], [79, 81], [79, 83], [79, 85], [79, 87], [79, 91], [79, 92], [79, 93], [79, 97], [79, 98], [79, 99], [79, 100], [79, 101], [79, 103], [79, 106], [79, 107], [79, 108], [79, 110], [79, 113], [79, 116], [79, 117], [79, 119], [80, 85], [80, 86], [80, 87], [80, 88], [80, 89], [80, 91], [80, 94], [80, 95], [80, 96], [80, 97], [80, 100], [80, 102], [80, 103], [80, 104], [80, 105], [80, 106], [80, 108], [80, 110], [80, 117], [80, 119], [81, 83], [81, 84], [81, 86], [81, 87], [81, 89], [81, 91], [81, 92], [81, 95], [81, 96], [81, 97], [81, 98], [81, 105], [81, 107], [81, 108], [81, 111], [81, 112], [81, 113], [81, 114], [81, 115], [81, 118], [81, 119], [82, 85], [82, 88], [82, 90], [82, 91], [82, 92], [82, 96], [82, 98], [82, 99], [82, 100], [82, 103], [82, 104], [82, 106], [82, 109], [82, 110], [82, 111], [82, 115], [82, 116], [83, 84], [83, 85], [83, 86], [83, 87], [83, 88], [83, 91], [83, 95], [83, 96], [83, 97], [83, 98], [83, 101], [83, 103], [83, 104], [83, 105], [83, 107], [83, 110], [83, 112], [83, 114], [83, 115], [83, 116], [83, 118], [83, 119], [84, 86], [84, 89], [84, 90], [84, 91], [84, 97], [84, 101], [84, 103], [84, 104], [84, 105], [84, 106], [84, 108], [84, 111], [84, 113], [84, 114], [84, 116], [84, 117], [84, 118], [85, 86], [85, 91], [85, 92], [85, 93], [85, 99], [85, 103], [85, 104], [85, 105], [85, 107], [85, 108], [85, 110], [85, 111], [85, 115], [86, 87], [86, 88], [86, 89], [86, 90], [86, 92], [86, 94], [86, 96], [86, 97], [86, 99], [86, 100], [86, 101], [86, 103], [86, 104], [86, 105], [86, 108], [86, 109], [86, 111], [86, 112], [86, 116], [87, 88], [87, 89], [87, 90], [87, 91], [87, 93], [87, 96], [87, 97], [87, 98], [87, 99], [87, 102], [87, 104], [87, 106], [87, 107], [87, 108], [87, 111], [87, 113], [87, 115], [87, 117], [87, 118], [88, 90], [88, 91], [88, 92], [88, 93], [88, 94], [88, 96], [88, 99], [88, 101], [88, 103], [88, 104], [88, 105], [88, 107], [88, 109], [88, 113], [88, 114], [88, 115], [88, 117], [88, 118], [88, 119], [89, 91], [89, 93], [89, 95], [89, 96], [89, 97], [89, 101], [89, 102], [89, 104], [89, 106], [89, 107], [89, 108], [89, 110], [89, 111], [89, 112], [89, 113], [89, 115], [89, 116], [89, 119], [90, 91], [90, 93], [90, 94], [90, 95], [90, 100], [90, 101], [90, 107], [90, 108], [90, 109], [90, 111], [90, 113], [90, 115], [90, 116], [90, 118], [90, 119], [91, 92], [91, 94], [91, 95], [91, 97], [91, 98], [91, 99], [91, 105], [91, 113], [91, 114], [91, 115], [91, 117], [91, 118], [91, 119], [92, 94], [92, 95], [92, 96], [92, 98], [92, 101], [92, 102], [92, 104], [92, 105], [92, 107], [92, 111], [92, 113], [92, 115], [92, 118], [93, 94], [93, 96], [93, 98], [93, 99], [93, 100], [93, 101], [93, 103], [93, 104], [93, 105], [93, 107], [93, 110], [93, 111], [93, 113], [93, 114], [93, 115], [93, 119], [94, 95], [94, 96], [94, 97], [94, 98], [94, 99], [94, 100], [94, 102], [94, 103], [94, 104], [94, 106], [94, 107], [94, 108], [94, 109], [94, 110], [94, 111], [94, 112], [94, 113], [94, 114], [95, 96], [95, 98], [95, 99], [95, 101], [95, 102], [95, 103], [95, 104], [95, 105], [95, 106], [95, 107], [95, 108], [95, 112], [95, 117], [95, 118], [96, 97], [96, 99], [96, 104], [96, 105], [96, 109], [96, 110], [96, 112], [96, 116], [96, 117], [96, 119], [97, 100], [97, 101], [97, 102], [97, 106], [97, 107], [97, 109], [97, 113], [97, 114], [97, 116], [97, 117], [97, 119], [98, 103], [98, 104], [98, 106], [98, 109], [98, 114], [98, 115], [98, 116], [98, 117], [98, 119], [99, 101], [99, 102], [99, 103], [99, 104], [99, 105], [99, 106], [99, 108], [99, 113], [99, 115], [99, 116], [99, 117], [99, 118], [99, 119], [100, 101], [100, 103], [100, 104], [100, 105], [100, 107], [100, 109], [100, 111], [100, 113], [100, 114], [100, 117], [100, 118], [100, 119], [101, 102], [101, 103], [101, 105], [101, 107], [101, 110], [101, 111], [101, 115], [101, 117], [101, 118], [101, 119], [102, 103], [102, 104], [102, 105], [102, 109], [102, 111], [102, 113], [102, 115], [102, 116], [102, 117], [102, 118], [102, 119], [103, 104], [103, 107], [103, 109], [103, 110], [103, 111], [103, 113], [103, 114], [103, 116], [103, 118], [103, 119], [104, 105], [104, 107], [104, 110], [104, 111], [104, 113], [104, 114], [104, 118], [105, 106], [105, 107], [105, 108], [105, 109], [105, 111], [105, 112], [105, 114], [105, 115], [106, 107], [106, 108], [106, 110], [106, 112], [106, 113], [106, 115], [106, 116], [106, 118], [106, 119], [107, 108], [107, 110], [107, 111], [107, 112], [107, 113], [107, 116], [107, 117], [108, 109], [108, 110], [108, 111], [108, 114], [108, 115], [108, 117], [108, 118], [109, 110], [109, 111], [109, 112], [109, 113], [109, 116], [109, 118], [109, 119], [110, 111], [110, 114], [110, 118], [110, 119], [111, 112], [111, 113], [111, 114], [111, 115], [111, 116], [112, 114], [112, 115], [112, 116], [112, 117], [112, 119], [113, 114], [113, 116], [113, 118], [114, 115], [114, 116], [114, 119], [115, 117], [115, 119], [116, 119], [117, 118], [117, 119]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l6-s5/solution/solve.sh b/tasks/construct-mc-max-clique-l6-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7c55e0c57de9bb6d4b1f07e9fd2f521e0dab300a --- /dev/null +++ b/tasks/construct-mc-max-clique-l6-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [21, 26, 28, 49, 51, 60, 66, 86, 90, 94, 100, 109, 111]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-clique-l6-s5/tests/check.py b/tasks/construct-mc-max-clique-l6-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3f70dbd5b155a3514c2102aa4ad460201495210 --- /dev/null +++ b/tasks/construct-mc-max-clique-l6-s5/tests/check.py @@ -0,0 +1,18 @@ +"""Clique of size >= k in a given graph (MathConstraint max_clique decision version, CC-BY-4.0).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("clique"), None, 0, n - 1, "clique") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) < k: + raise Invalid(f"clique has {len(S)} vertices, need at least {k}") + E = {(u, v) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(S), 2): + if (u, v) not in E: + raise Invalid(f"vertices {u} and {v} are not adjacent") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-max-clique-l6-s5/tests/instance.json b/tasks/construct-mc-max-clique-l6-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d9aed8cebd5972452237bb85c6b94dc62fb557ce --- /dev/null +++ b/tasks/construct-mc-max-clique-l6-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 120, "k": 13, "edges": [[0, 3], [0, 4], [0, 7], [0, 9], [0, 10], [0, 12], [0, 15], [0, 16], [0, 18], [0, 19], [0, 21], [0, 23], [0, 24], [0, 26], [0, 27], [0, 28], [0, 29], [0, 30], [0, 31], [0, 32], [0, 33], [0, 34], [0, 36], [0, 37], [0, 38], [0, 43], [0, 44], [0, 45], [0, 46], [0, 52], [0, 56], [0, 57], [0, 58], [0, 59], [0, 60], [0, 63], [0, 65], [0, 66], [0, 67], [0, 68], [0, 69], [0, 70], [0, 72], [0, 74], [0, 75], [0, 76], [0, 78], [0, 84], [0, 85], [0, 86], [0, 87], [0, 89], [0, 90], [0, 92], [0, 93], [0, 94], [0, 103], [0, 106], [0, 108], [0, 110], [0, 111], [0, 113], [0, 115], [1, 2], [1, 5], [1, 10], [1, 12], [1, 13], [1, 14], [1, 16], [1, 18], [1, 19], [1, 21], [1, 23], [1, 25], [1, 31], [1, 33], [1, 34], [1, 36], [1, 37], [1, 38], [1, 39], [1, 43], [1, 46], [1, 48], [1, 50], [1, 51], [1, 54], [1, 56], [1, 58], [1, 60], [1, 61], [1, 62], [1, 63], [1, 65], [1, 66], [1, 70], [1, 71], [1, 73], [1, 75], [1, 76], [1, 77], [1, 79], [1, 83], [1, 85], [1, 88], [1, 89], [1, 90], [1, 91], [1, 92], [1, 93], [1, 94], [1, 95], [1, 101], [1, 104], [1, 106], [1, 109], [1, 110], [1, 114], [1, 117], [1, 118], [2, 5], [2, 6], [2, 8], [2, 9], [2, 12], [2, 13], [2, 15], [2, 17], [2, 18], [2, 19], [2, 23], [2, 24], [2, 28], [2, 29], [2, 33], [2, 34], [2, 37], [2, 43], [2, 46], [2, 48], [2, 49], [2, 50], [2, 54], [2, 55], [2, 56], [2, 59], [2, 63], [2, 67], [2, 70], [2, 71], [2, 74], [2, 75], [2, 77], [2, 79], [2, 80], [2, 82], [2, 84], [2, 87], [2, 89], [2, 91], [2, 92], [2, 93], [2, 94], [2, 95], [2, 96], [2, 98], [2, 99], [2, 100], [2, 103], [2, 104], [2, 105], [2, 108], [2, 109], [2, 110], [2, 111], [2, 112], [2, 113], [2, 115], [2, 117], [2, 118], [2, 119], [3, 5], [3, 8], [3, 10], [3, 11], [3, 15], [3, 17], [3, 18], [3, 20], [3, 23], [3, 30], [3, 32], [3, 37], [3, 41], [3, 42], [3, 43], [3, 46], [3, 47], [3, 51], [3, 53], [3, 55], [3, 59], [3, 60], [3, 62], [3, 64], [3, 68], [3, 70], [3, 71], [3, 72], [3, 73], [3, 74], [3, 83], [3, 84], [3, 85], [3, 86], [3, 88], [3, 90], [3, 93], [3, 95], [3, 96], [3, 97], [3, 98], [3, 99], [3, 103], [3, 105], [3, 106], [3, 107], [3, 109], [3, 110], [3, 111], [3, 115], [3, 116], [3, 118], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 12], [4, 14], [4, 15], [4, 18], [4, 20], [4, 22], [4, 23], [4, 24], [4, 26], [4, 32], [4, 36], [4, 41], [4, 45], [4, 47], [4, 50], [4, 52], [4, 55], [4, 56], [4, 58], [4, 59], [4, 61], [4, 62], [4, 63], [4, 64], [4, 66], [4, 67], [4, 68], [4, 75], [4, 76], [4, 77], [4, 78], [4, 79], [4, 83], [4, 85], [4, 87], [4, 88], [4, 89], [4, 90], [4, 92], [4, 93], [4, 96], [4, 98], [4, 100], [4, 108], [4, 109], [4, 110], [4, 111], [4, 115], [4, 116], [4, 117], [4, 119], [5, 6], [5, 9], [5, 10], [5, 12], [5, 14], [5, 18], [5, 26], [5, 27], [5, 29], [5, 32], [5, 34], [5, 35], [5, 41], [5, 43], [5, 45], [5, 46], [5, 49], [5, 50], [5, 54], [5, 55], [5, 56], [5, 57], [5, 60], [5, 61], [5, 62], [5, 64], [5, 65], [5, 66], [5, 69], [5, 70], [5, 73], [5, 74], [5, 75], [5, 77], [5, 78], [5, 79], [5, 80], [5, 81], [5, 82], [5, 83], [5, 90], [5, 92], [5, 93], [5, 95], [5, 96], [5, 98], [5, 99], [5, 102], [5, 103], [5, 104], [5, 105], [5, 106], [5, 107], [5, 109], [5, 110], [5, 111], [5, 112], [5, 114], [5, 117], [5, 118], [5, 119], [6, 7], [6, 10], [6, 12], [6, 14], [6, 15], [6, 18], [6, 20], [6, 21], [6, 22], [6, 26], [6, 29], [6, 31], [6, 32], [6, 33], [6, 34], [6, 39], [6, 40], [6, 42], [6, 43], [6, 45], [6, 47], [6, 48], [6, 49], [6, 52], [6, 53], [6, 54], [6, 56], [6, 57], [6, 63], [6, 65], [6, 67], [6, 68], [6, 71], [6, 72], [6, 74], [6, 75], [6, 79], [6, 80], [6, 82], [6, 83], [6, 84], [6, 86], [6, 90], [6, 91], [6, 95], [6, 96], [6, 97], [6, 98], [6, 99], [6, 102], [6, 106], [6, 108], [6, 110], [6, 111], [6, 113], [6, 114], [6, 116], [6, 119], [7, 9], [7, 10], [7, 12], [7, 14], [7, 15], [7, 19], [7, 20], [7, 21], [7, 23], [7, 25], [7, 28], [7, 31], [7, 32], [7, 33], [7, 34], [7, 43], [7, 45], [7, 47], [7, 48], [7, 49], [7, 50], [7, 53], [7, 54], [7, 55], [7, 56], [7, 58], [7, 59], [7, 60], [7, 63], [7, 65], [7, 67], [7, 72], [7, 73], [7, 75], [7, 80], [7, 81], [7, 84], [7, 85], [7, 87], [7, 90], [7, 91], [7, 92], [7, 93], [7, 95], [7, 97], [7, 98], [7, 101], [7, 103], [7, 105], [7, 106], [7, 107], [7, 110], [7, 111], [7, 113], [7, 114], [7, 115], [7, 116], [7, 117], [8, 9], [8, 10], [8, 12], [8, 15], [8, 16], [8, 20], [8, 21], [8, 22], [8, 23], [8, 25], [8, 26], [8, 28], [8, 31], [8, 34], [8, 37], [8, 39], [8, 51], [8, 52], [8, 53], [8, 54], [8, 56], [8, 57], [8, 58], [8, 60], [8, 61], [8, 62], [8, 63], [8, 65], [8, 66], [8, 68], [8, 70], [8, 71], [8, 73], [8, 74], [8, 75], [8, 76], [8, 77], [8, 78], [8, 80], [8, 81], [8, 85], [8, 87], [8, 89], [8, 90], [8, 94], [8, 95], [8, 96], [8, 98], [8, 99], [8, 101], [8, 102], [8, 106], [8, 107], [8, 108], [8, 109], [8, 110], [8, 111], [8, 113], [8, 114], [8, 119], [9, 11], [9, 14], [9, 15], [9, 17], [9, 20], [9, 21], [9, 22], [9, 26], [9, 27], [9, 28], [9, 29], [9, 31], [9, 34], [9, 39], [9, 42], [9, 43], [9, 45], [9, 47], [9, 49], [9, 50], [9, 53], [9, 54], [9, 58], [9, 60], [9, 61], [9, 63], [9, 64], [9, 65], [9, 67], [9, 69], [9, 70], [9, 73], [9, 74], [9, 75], [9, 77], [9, 78], [9, 79], [9, 81], [9, 82], [9, 83], [9, 84], [9, 85], [9, 86], [9, 89], [9, 91], [9, 92], [9, 93], [9, 95], [9, 96], [9, 97], [9, 98], [9, 99], [9, 100], [9, 102], [9, 103], [9, 104], [9, 108], [9, 109], [9, 111], [9, 114], [10, 11], [10, 14], [10, 15], [10, 17], [10, 18], [10, 21], [10, 26], [10, 28], [10, 30], [10, 31], [10, 32], [10, 33], [10, 34], [10, 35], [10, 36], [10, 39], [10, 40], [10, 42], [10, 43], [10, 44], [10, 45], [10, 48], [10, 49], [10, 52], [10, 54], [10, 55], [10, 57], [10, 58], [10, 59], [10, 61], [10, 64], [10, 65], [10, 68], [10, 69], [10, 70], [10, 72], [10, 74], [10, 77], [10, 81], [10, 84], [10, 87], [10, 89], [10, 90], [10, 93], [10, 94], [10, 96], [10, 100], [10, 102], [10, 104], [10, 105], [10, 106], [10, 107], [10, 108], [10, 114], [10, 116], [10, 117], [10, 119], [11, 15], [11, 16], [11, 18], [11, 19], [11, 23], [11, 27], [11, 28], [11, 30], [11, 31], [11, 33], [11, 34], [11, 35], [11, 37], [11, 38], [11, 39], [11, 40], [11, 41], [11, 42], [11, 44], [11, 45], [11, 46], [11, 49], [11, 50], [11, 52], [11, 56], [11, 57], [11, 58], [11, 59], [11, 60], [11, 63], [11, 64], [11, 69], [11, 77], [11, 78], [11, 80], [11, 81], [11, 82], [11, 85], [11, 86], [11, 87], [11, 88], [11, 90], [11, 94], [11, 97], [11, 101], [11, 102], [11, 104], [11, 106], [11, 107], [11, 108], [11, 111], [11, 112], [11, 113], [11, 114], [12, 14], [12, 15], [12, 16], [12, 17], [12, 22], [12, 23], [12, 25], [12, 26], [12, 32], [12, 41], [12, 46], [12, 47], [12, 50], [12, 51], [12, 52], [12, 58], [12, 59], [12, 60], [12, 61], [12, 64], [12, 67], [12, 69], [12, 70], [12, 71], [12, 76], [12, 77], [12, 78], [12, 79], [12, 80], [12, 81], [12, 84], [12, 85], [12, 88], [12, 91], [12, 92], [12, 94], [12, 97], [12, 102], [12, 104], [12, 106], [12, 108], [12, 110], [12, 111], [12, 116], [12, 117], [13, 17], [13, 20], [13, 25], [13, 26], [13, 27], [13, 29], [13, 30], [13, 32], [13, 35], [13, 37], [13, 40], [13, 49], [13, 50], [13, 52], [13, 55], [13, 56], [13, 57], [13, 59], [13, 62], [13, 64], [13, 68], [13, 69], [13, 72], [13, 75], [13, 77], [13, 79], [13, 81], [13, 83], [13, 85], [13, 87], [13, 88], [13, 89], [13, 90], [13, 93], [13, 94], [13, 100], [13, 101], [13, 102], [13, 104], [13, 105], [13, 106], [13, 108], [13, 109], [13, 110], [13, 112], [13, 113], [13, 117], [13, 119], [14, 21], [14, 23], [14, 28], [14, 29], [14, 31], [14, 35], [14, 37], [14, 39], [14, 40], [14, 42], [14, 44], [14, 47], [14, 48], [14, 49], [14, 53], [14, 54], [14, 55], [14, 57], [14, 58], [14, 59], [14, 61], [14, 63], [14, 65], [14, 67], [14, 68], [14, 69], [14, 71], [14, 72], [14, 73], [14, 74], [14, 76], [14, 77], [14, 81], [14, 84], [14, 88], [14, 92], [14, 100], [14, 103], [14, 104], [14, 105], [14, 109], [14, 112], [14, 115], [14, 116], [14, 117], [15, 19], [15, 21], [15, 23], [15, 24], [15, 25], [15, 26], [15, 28], [15, 29], [15, 30], [15, 32], [15, 33], [15, 34], [15, 37], [15, 39], [15, 41], [15, 42], [15, 43], [15, 47], [15, 50], [15, 53], [15, 56], [15, 58], [15, 62], [15, 64], [15, 67], [15, 68], [15, 69], [15, 71], [15, 72], [15, 73], [15, 75], [15, 77], [15, 79], [15, 80], [15, 83], [15, 84], [15, 87], [15, 88], [15, 91], [15, 92], [15, 97], [15, 98], [15, 100], [15, 103], [15, 104], [15, 105], [15, 108], [15, 109], [15, 110], [15, 113], [15, 114], [15, 115], [15, 116], [15, 117], [15, 118], [16, 17], [16, 20], [16, 21], [16, 27], [16, 28], [16, 29], [16, 30], [16, 31], [16, 34], [16, 36], [16, 39], [16, 40], [16, 42], [16, 46], [16, 48], [16, 49], [16, 50], [16, 51], [16, 54], [16, 56], [16, 57], [16, 61], [16, 63], [16, 64], [16, 65], [16, 66], [16, 70], [16, 71], [16, 78], [16, 80], [16, 81], [16, 85], [16, 90], [16, 91], [16, 92], [16, 94], [16, 97], [16, 99], [16, 100], [16, 104], [16, 105], [16, 106], [16, 108], [16, 109], [16, 111], [16, 112], [16, 113], [16, 114], [16, 115], [16, 117], [16, 118], [17, 19], [17, 20], [17, 21], [17, 22], [17, 26], [17, 27], [17, 29], [17, 32], [17, 33], [17, 34], [17, 35], [17, 36], [17, 39], [17, 40], [17, 42], [17, 45], [17, 47], [17, 48], [17, 49], [17, 51], [17, 52], [17, 54], [17, 57], [17, 58], [17, 63], [17, 65], [17, 68], [17, 69], [17, 75], [17, 76], [17, 78], [17, 79], [17, 80], [17, 81], [17, 84], [17, 86], [17, 88], [17, 89], [17, 90], [17, 91], [17, 92], [17, 93], [17, 94], [17, 96], [17, 97], [17, 99], [17, 100], [17, 101], [17, 102], [17, 103], [17, 104], [17, 105], [17, 106], [17, 109], [17, 111], [17, 114], [17, 115], [17, 116], [17, 117], [18, 19], [18, 20], [18, 23], [18, 24], [18, 26], [18, 27], [18, 29], [18, 31], [18, 32], [18, 33], [18, 37], [18, 38], [18, 41], [18, 43], [18, 46], [18, 47], [18, 48], [18, 51], [18, 52], [18, 53], [18, 58], [18, 59], [18, 63], [18, 65], [18, 67], [18, 70], [18, 71], [18, 73], [18, 75], [18, 76], [18, 77], [18, 81], [18, 83], [18, 86], [18, 88], [18, 90], [18, 91], [18, 92], [18, 96], [18, 98], [18, 99], [18, 100], [18, 101], [18, 107], [18, 108], [18, 109], [18, 111], [18, 113], [18, 115], [18, 118], [18, 119], [19, 22], [19, 23], [19, 24], [19, 25], [19, 26], [19, 31], [19, 32], [19, 33], [19, 34], [19, 35], [19, 36], [19, 37], [19, 38], [19, 40], [19, 43], [19, 44], [19, 46], [19, 47], [19, 52], [19, 56], [19, 57], [19, 58], [19, 61], [19, 62], [19, 63], [19, 70], [19, 73], [19, 74], [19, 77], [19, 81], [19, 83], [19, 84], [19, 86], [19, 88], [19, 90], [19, 93], [19, 94], [19, 95], [19, 98], [19, 100], [19, 103], [19, 104], [19, 106], [19, 107], [19, 108], [19, 109], [19, 110], [19, 113], [19, 114], [19, 115], [19, 117], [20, 21], [20, 22], [20, 24], [20, 25], [20, 26], [20, 27], [20, 29], [20, 32], [20, 33], [20, 36], [20, 39], [20, 41], [20, 42], [20, 43], [20, 45], [20, 48], [20, 49], [20, 54], [20, 58], [20, 59], [20, 61], [20, 64], [20, 65], [20, 67], [20, 71], [20, 72], [20, 74], [20, 82], [20, 84], [20, 86], [20, 90], [20, 99], [20, 100], [20, 102], [20, 105], [20, 106], [20, 107], [20, 108], [20, 109], [20, 113], [20, 118], [21, 22], [21, 24], [21, 26], [21, 27], [21, 28], [21, 29], [21, 34], [21, 35], [21, 36], [21, 39], [21, 40], [21, 41], [21, 42], [21, 43], [21, 44], [21, 45], [21, 48], [21, 49], [21, 50], [21, 51], [21, 53], [21, 54], [21, 57], [21, 60], [21, 61], [21, 66], [21, 72], [21, 73], [21, 74], [21, 75], [21, 76], [21, 77], [21, 81], [21, 82], [21, 83], [21, 86], [21, 89], [21, 90], [21, 92], [21, 93], [21, 94], [21, 98], [21, 99], [21, 100], [21, 101], [21, 102], [21, 105], [21, 107], [21, 108], [21, 109], [21, 111], [21, 112], [21, 116], [21, 117], [22, 23], [22, 27], [22, 28], [22, 29], [22, 30], [22, 31], [22, 32], [22, 34], [22, 36], [22, 37], [22, 38], [22, 41], [22, 42], [22, 44], [22, 46], [22, 47], [22, 48], [22, 51], [22, 55], [22, 56], [22, 58], [22, 60], [22, 61], [22, 64], [22, 65], [22, 66], [22, 67], [22, 68], [22, 70], [22, 71], [22, 73], [22, 74], [22, 75], [22, 77], [22, 78], [22, 79], [22, 80], [22, 81], [22, 85], [22, 86], [22, 87], [22, 89], [22, 90], [22, 91], [22, 93], [22, 94], [22, 96], [22, 98], [22, 99], [22, 100], [22, 101], [22, 105], [22, 107], [22, 111], [22, 113], [22, 116], [22, 119], [23, 24], [23, 25], [23, 27], [23, 28], [23, 29], [23, 30], [23, 31], [23, 32], [23, 35], [23, 36], [23, 38], [23, 41], [23, 44], [23, 46], [23, 50], [23, 54], [23, 55], [23, 57], [23, 59], [23, 60], [23, 64], [23, 66], [23, 71], [23, 73], [23, 74], [23, 77], [23, 78], [23, 80], [23, 87], [23, 89], [23, 90], [23, 91], [23, 100], [23, 103], [23, 104], [23, 106], [23, 111], [23, 112], [23, 118], [23, 119], [24, 29], [24, 32], [24, 33], [24, 34], [24, 35], [24, 37], [24, 38], [24, 40], [24, 41], [24, 44], [24, 50], [24, 51], [24, 52], [24, 53], [24, 55], [24, 59], [24, 60], [24, 61], [24, 64], [24, 65], [24, 66], [24, 67], [24, 68], [24, 72], [24, 75], [24, 76], [24, 77], [24, 81], [24, 83], [24, 84], [24, 85], [24, 88], [24, 91], [24, 93], [24, 94], [24, 98], [24, 99], [24, 104], [24, 105], [24, 106], [24, 108], [24, 111], [24, 112], [24, 117], [24, 118], [24, 119], [25, 27], [25, 28], [25, 29], [25, 30], [25, 32], [25, 33], [25, 34], [25, 35], [25, 41], [25, 44], [25, 45], [25, 52], [25, 53], [25, 63], [25, 64], [25, 65], [25, 66], [25, 68], [25, 70], [25, 71], [25, 72], [25, 75], [25, 78], [25, 82], [25, 88], [25, 89], [25, 90], [25, 91], [25, 92], [25, 95], [25, 100], [25, 101], [25, 102], [25, 103], [25, 106], [25, 110], [25, 112], [25, 113], [25, 117], [25, 118], [25, 119], [26, 27], [26, 28], [26, 29], [26, 31], [26, 36], [26, 38], [26, 42], [26, 43], [26, 44], [26, 45], [26, 47], [26, 49], [26, 50], [26, 51], [26, 52], [26, 53], [26, 54], [26, 55], [26, 59], [26, 60], [26, 65], [26, 66], [26, 68], [26, 70], [26, 71], [26, 72], [26, 74], [26, 75], [26, 81], [26, 86], [26, 89], [26, 90], [26, 92], [26, 94], [26, 97], [26, 99], [26, 100], [26, 102], [26, 103], [26, 106], [26, 107], [26, 108], [26, 109], [26, 111], [26, 115], [26, 117], [26, 119], [27, 28], [27, 31], [27, 32], [27, 34], [27, 35], [27, 36], [27, 37], [27, 41], [27, 43], [27, 46], [27, 48], [27, 52], [27, 53], [27, 54], [27, 56], [27, 57], [27, 58], [27, 59], [27, 61], [27, 63], [27, 64], [27, 66], [27, 73], [27, 75], [27, 76], [27, 79], [27, 80], [27, 81], [27, 82], [27, 83], [27, 85], [27, 88], [27, 89], [27, 91], [27, 92], [27, 93], [27, 94], [27, 97], [27, 101], [27, 104], [27, 106], [27, 113], [27, 118], [27, 119], [28, 29], [28, 30], [28, 35], [28, 38], [28, 39], [28, 40], [28, 43], [28, 46], [28, 48], [28, 49], [28, 50], [28, 51], [28, 57], [28, 59], [28, 60], [28, 61], [28, 62], [28, 63], [28, 65], [28, 66], [28, 67], [28, 68], [28, 70], [28, 72], [28, 73], [28, 76], [28, 80], [28, 82], [28, 83], [28, 85], [28, 86], [28, 87], [28, 89], [28, 90], [28, 93], [28, 94], [28, 95], [28, 100], [28, 103], [28, 108], [28, 109], [28, 110], [28, 111], [28, 112], [28, 115], [28, 117], [28, 118], [28, 119], [29, 30], [29, 37], [29, 39], [29, 41], [29, 42], [29, 43], [29, 45], [29, 47], [29, 48], [29, 50], [29, 51], [29, 52], [29, 56], [29, 57], [29, 58], [29, 60], [29, 63], [29, 65], [29, 70], [29, 71], [29, 73], [29, 74], [29, 75], [29, 77], [29, 80], [29, 84], [29, 85], [29, 86], [29, 87], [29, 88], [29, 89], [29, 91], [29, 94], [29, 95], [29, 98], [29, 101], [29, 102], [29, 104], [29, 107], [29, 111], [29, 112], [29, 115], [30, 31], [30, 32], [30, 33], [30, 34], [30, 35], [30, 36], [30, 43], [30, 44], [30, 45], [30, 46], [30, 49], [30, 51], [30, 52], [30, 53], [30, 54], [30, 57], [30, 62], [30, 64], [30, 67], [30, 71], [30, 73], [30, 74], [30, 75], [30, 76], [30, 81], [30, 82], [30, 83], [30, 86], [30, 87], [30, 90], [30, 91], [30, 93], [30, 94], [30, 95], [30, 100], [30, 105], [30, 106], [30, 107], [30, 108], [30, 110], [30, 111], [30, 114], [30, 115], [30, 117], [30, 118], [30, 119], [31, 34], [31, 35], [31, 36], [31, 37], [31, 38], [31, 40], [31, 42], [31, 44], [31, 46], [31, 48], [31, 49], [31, 51], [31, 52], [31, 54], [31, 55], [31, 59], [31, 60], [31, 62], [31, 63], [31, 66], [31, 68], [31, 69], [31, 74], [31, 76], [31, 81], [31, 82], [31, 84], [31, 86], [31, 88], [31, 89], [31, 95], [31, 97], [31, 99], [31, 102], [31, 105], [31, 106], [31, 107], [31, 113], [31, 117], [31, 118], [32, 33], [32, 35], [32, 37], [32, 38], [32, 39], [32, 40], [32, 41], [32, 42], [32, 43], [32, 45], [32, 46], [32, 47], [32, 49], [32, 51], [32, 52], [32, 59], [32, 60], [32, 61], [32, 62], [32, 65], [32, 66], [32, 68], [32, 69], [32, 70], [32, 72], [32, 75], [32, 80], [32, 81], [32, 84], [32, 85], [32, 86], [32, 87], [32, 89], [32, 90], [32, 92], [32, 93], [32, 95], [32, 96], [32, 103], [32, 104], [32, 105], [32, 107], [32, 108], [32, 112], [32, 114], [32, 115], [32, 116], [32, 118], [32, 119], [33, 37], [33, 38], [33, 39], [33, 40], [33, 42], [33, 44], [33, 47], [33, 49], [33, 55], [33, 58], [33, 59], [33, 60], [33, 61], [33, 64], [33, 66], [33, 68], [33, 69], [33, 70], [33, 71], [33, 72], [33, 73], [33, 75], [33, 78], [33, 79], [33, 82], [33, 85], [33, 88], [33, 91], [33, 92], [33, 96], [33, 99], [33, 101], [33, 103], [33, 105], [33, 106], [33, 107], [33, 109], [33, 110], [33, 111], [33, 113], [33, 114], [33, 117], [33, 118], [33, 119], [34, 36], [34, 43], [34, 47], [34, 49], [34, 50], [34, 51], [34, 52], [34, 55], [34, 56], [34, 61], [34, 66], [34, 69], [34, 72], [34, 73], [34, 74], [34, 75], [34, 76], [34, 77], [34, 86], [34, 88], [34, 89], [34, 91], [34, 92], [34, 93], [34, 95], [34, 96], [34, 97], [34, 98], [34, 101], [34, 102], [34, 105], [34, 110], [34, 115], [34, 116], [34, 117], [35, 37], [35, 39], [35, 40], [35, 41], [35, 43], [35, 44], [35, 51], [35, 52], [35, 53], [35, 54], [35, 55], [35, 56], [35, 59], [35, 60], [35, 62], [35, 63], [35, 68], [35, 69], [35, 70], [35, 72], [35, 74], [35, 76], [35, 77], [35, 79], [35, 81], [35, 84], [35, 86], [35, 87], [35, 89], [35, 90], [35, 92], [35, 93], [35, 94], [35, 95], [35, 97], [35, 99], [35, 101], [35, 104], [35, 105], [35, 109], [35, 114], [35, 117], [35, 119], [36, 39], [36, 40], [36, 42], [36, 43], [36, 44], [36, 45], [36, 46], [36, 49], [36, 50], [36, 53], [36, 54], [36, 55], [36, 56], [36, 58], [36, 60], [36, 61], [36, 66], [36, 69], [36, 70], [36, 74], [36, 75], [36, 77], [36, 80], [36, 81], [36, 84], [36, 88], [36, 89], [36, 90], [36, 91], [36, 93], [36, 95], [36, 100], [36, 101], [36, 108], [36, 111], [36, 118], [37, 38], [37, 41], [37, 42], [37, 43], [37, 44], [37, 45], [37, 47], [37, 48], [37, 49], [37, 51], [37, 53], [37, 59], [37, 60], [37, 61], [37, 63], [37, 64], [37, 66], [37, 70], [37, 73], [37, 74], [37, 75], [37, 77], [37, 79], [37, 82], [37, 83], [37, 84], [37, 87], [37, 88], [37, 92], [37, 93], [37, 95], [37, 96], [37, 98], [37, 100], [37, 102], [37, 103], [37, 104], [37, 109], [37, 110], [37, 111], [37, 112], [37, 113], [37, 114], [37, 115], [37, 116], [37, 119], [38, 40], [38, 44], [38, 45], [38, 47], [38, 48], [38, 50], [38, 55], [38, 57], [38, 59], [38, 60], [38, 67], [38, 69], [38, 71], [38, 77], [38, 80], [38, 81], [38, 82], [38, 83], [38, 85], [38, 86], [38, 89], [38, 91], [38, 95], [38, 102], [38, 104], [38, 105], [38, 107], [38, 109], [38, 110], [38, 111], [38, 113], [38, 114], [38, 115], [38, 118], [38, 119], [39, 40], [39, 44], [39, 45], [39, 49], [39, 53], [39, 55], [39, 58], [39, 59], [39, 60], [39, 61], [39, 64], [39, 65], [39, 67], [39, 69], [39, 74], [39, 76], [39, 77], [39, 78], [39, 79], [39, 82], [39, 84], [39, 85], [39, 87], [39, 88], [39, 91], [39, 92], [39, 93], [39, 95], [39, 97], [39, 100], [39, 101], [39, 103], [39, 105], [39, 106], [39, 109], [39, 110], [39, 111], [39, 112], [39, 116], [39, 118], [39, 119], [40, 42], [40, 44], [40, 46], [40, 47], [40, 49], [40, 50], [40, 51], [40, 54], [40, 55], [40, 56], [40, 58], [40, 62], [40, 63], [40, 65], [40, 66], [40, 71], [40, 73], [40, 74], [40, 75], [40, 76], [40, 77], [40, 78], [40, 80], [40, 83], [40, 87], [40, 88], [40, 90], [40, 91], [40, 92], [40, 93], [40, 96], [40, 99], [40, 102], [40, 107], [40, 108], [40, 109], [40, 116], [41, 42], [41, 44], [41, 47], [41, 48], [41, 52], [41, 53], [41, 58], [41, 59], [41, 60], [41, 61], [41, 63], [41, 66], [41, 67], [41, 68], [41, 69], [41, 70], [41, 71], [41, 72], [41, 75], [41, 77], [41, 78], [41, 80], [41, 81], [41, 84], [41, 85], [41, 89], [41, 90], [41, 91], [41, 92], [41, 94], [41, 95], [41, 96], [41, 98], [41, 101], [41, 102], [41, 104], [41, 107], [41, 108], [41, 109], [41, 110], [41, 117], [41, 118], [42, 44], [42, 46], [42, 49], [42, 51], [42, 52], [42, 53], [42, 54], [42, 55], [42, 56], [42, 59], [42, 67], [42, 69], [42, 71], [42, 72], [42, 73], [42, 74], [42, 76], [42, 77], [42, 78], [42, 84], [42, 85], [42, 87], [42, 89], [42, 90], [42, 92], [42, 94], [42, 95], [42, 96], [42, 98], [42, 99], [42, 101], [42, 102], [42, 106], [42, 107], [42, 109], [42, 110], [42, 111], [42, 114], [42, 115], [42, 116], [42, 117], [42, 119], [43, 44], [43, 45], [43, 47], [43, 48], [43, 49], [43, 51], [43, 52], [43, 54], [43, 55], [43, 59], [43, 62], [43, 66], [43, 67], [43, 68], [43, 69], [43, 72], [43, 73], [43, 75], [43, 77], [43, 78], [43, 79], [43, 81], [43, 84], [43, 86], [43, 87], [43, 89], [43, 91], [43, 92], [43, 93], [43, 94], [43, 95], [43, 96], [43, 98], [43, 99], [43, 100], [43, 104], [43, 105], [43, 107], [43, 108], [43, 111], [43, 113], [43, 114], [43, 115], [43, 118], [43, 119], [44, 45], [44, 46], [44, 50], [44, 53], [44, 54], [44, 56], [44, 57], [44, 58], [44, 62], [44, 64], [44, 65], [44, 66], [44, 67], [44, 68], [44, 72], [44, 73], [44, 78], [44, 79], [44, 81], [44, 82], [44, 83], [44, 84], [44, 87], [44, 91], [44, 93], [44, 95], [44, 96], [44, 98], [44, 101], [44, 103], [44, 108], [44, 110], [44, 112], [44, 116], [44, 117], [44, 118], [45, 46], [45, 50], [45, 51], [45, 56], [45, 57], [45, 58], [45, 64], [45, 67], [45, 72], [45, 73], [45, 74], [45, 77], [45, 79], [45, 80], [45, 81], [45, 86], [45, 87], [45, 89], [45, 90], [45, 92], [45, 97], [45, 100], [45, 103], [45, 107], [45, 113], [45, 115], [45, 116], [45, 117], [45, 118], [46, 47], [46, 51], [46, 53], [46, 54], [46, 57], [46, 60], [46, 63], [46, 64], [46, 67], [46, 69], [46, 74], [46, 75], [46, 77], [46, 79], [46, 80], [46, 81], [46, 82], [46, 88], [46, 89], [46, 90], [46, 93], [46, 95], [46, 96], [46, 98], [46, 99], [46, 101], [46, 103], [46, 105], [46, 106], [46, 107], [46, 111], [46, 113], [46, 114], [46, 115], [46, 116], [46, 118], [47, 50], [47, 53], [47, 54], [47, 58], [47, 63], [47, 65], [47, 67], [47, 68], [47, 69], [47, 70], [47, 72], [47, 75], [47, 76], [47, 79], [47, 81], [47, 84], [47, 86], [47, 88], [47, 90], [47, 91], [47, 93], [47, 95], [47, 99], [47, 100], [47, 101], [47, 102], [47, 105], [47, 106], [47, 107], [47, 108], [47, 109], [47, 112], [47, 115], [47, 119], [48, 50], [48, 51], [48, 52], [48, 53], [48, 54], [48, 55], [48, 61], [48, 63], [48, 64], [48, 65], [48, 67], [48, 68], [48, 71], [48, 74], [48, 75], [48, 78], [48, 79], [48, 81], [48, 86], [48, 90], [48, 92], [48, 93], [48, 94], [48, 95], [48, 99], [48, 100], [48, 101], [48, 103], [48, 105], [48, 106], [48, 107], [48, 108], [48, 110], [48, 113], [48, 115], [49, 51], [49, 52], [49, 53], [49, 57], [49, 58], [49, 59], [49, 60], [49, 61], [49, 62], [49, 65], [49, 66], [49, 71], [49, 73], [49, 74], [49, 75], [49, 76], [49, 78], [49, 79], [49, 80], [49, 81], [49, 86], [49, 88], [49, 90], [49, 91], [49, 93], [49, 94], [49, 97], [49, 98], [49, 100], [49, 104], [49, 106], [49, 108], [49, 109], [49, 110], [49, 111], [49, 112], [49, 114], [49, 115], [49, 117], [49, 119], [50, 55], [50, 59], [50, 60], [50, 61], [50, 62], [50, 63], [50, 64], [50, 65], [50, 66], [50, 67], [50, 68], [50, 69], [50, 71], [50, 72], [50, 74], [50, 75], [50, 76], [50, 78], [50, 79], [50, 84], [50, 87], [50, 88], [50, 89], [50, 95], [50, 96], [50, 100], [50, 102], [50, 103], [50, 106], [50, 107], [50, 108], [50, 109], [50, 110], [50, 111], [50, 115], [50, 118], [51, 53], [51, 58], [51, 59], [51, 60], [51, 61], [51, 65], [51, 66], [51, 67], [51, 68], [51, 69], [51, 71], [51, 72], [51, 73], [51, 76], [51, 80], [51, 83], [51, 84], [51, 86], [51, 90], [51, 91], [51, 93], [51, 94], [51, 96], [51, 99], [51, 100], [51, 101], [51, 102], [51, 106], [51, 109], [51, 110], [51, 111], [51, 112], [51, 113], [51, 115], [51, 116], [51, 117], [51, 118], [51, 119], [52, 56], [52, 58], [52, 60], [52, 65], [52, 69], [52, 73], [52, 75], [52, 77], [52, 78], [52, 79], [52, 81], [52, 86], [52, 88], [52, 92], [52, 96], [52, 97], [52, 98], [52, 104], [52, 105], [52, 106], [52, 107], [52, 111], [52, 114], [52, 115], [52, 118], [53, 54], [53, 56], [53, 57], [53, 59], [53, 61], [53, 62], [53, 63], [53, 64], [53, 66], [53, 67], [53, 72], [53, 73], [53, 75], [53, 78], [53, 81], [53, 82], [53, 83], [53, 85], [53, 86], [53, 87], [53, 91], [53, 93], [53, 94], [53, 96], [53, 97], [53, 98], [53, 100], [53, 101], [53, 103], [53, 104], [53, 108], [53, 111], [53, 114], [53, 115], [53, 116], [53, 117], [53, 119], [54, 57], [54, 58], [54, 59], [54, 60], [54, 64], [54, 68], [54, 70], [54, 71], [54, 73], [54, 77], [54, 81], [54, 82], [54, 85], [54, 88], [54, 90], [54, 91], [54, 98], [54, 101], [54, 108], [54, 111], [54, 112], [54, 114], [54, 116], [54, 117], [54, 119], [55, 59], [55, 60], [55, 63], [55, 65], [55, 66], [55, 68], [55, 69], [55, 70], [55, 71], [55, 73], [55, 74], [55, 83], [55, 84], [55, 85], [55, 88], [55, 93], [55, 94], [55, 104], [55, 107], [55, 110], [55, 112], [55, 114], [55, 115], [56, 57], [56, 58], [56, 61], [56, 62], [56, 64], [56, 65], [56, 66], [56, 69], [56, 70], [56, 71], [56, 73], [56, 76], [56, 81], [56, 82], [56, 83], [56, 84], [56, 86], [56, 87], [56, 89], [56, 91], [56, 92], [56, 98], [56, 100], [56, 102], [56, 103], [56, 104], [56, 115], [56, 116], [56, 118], [57, 58], [57, 59], [57, 60], [57, 61], [57, 65], [57, 67], [57, 68], [57, 70], [57, 71], [57, 73], [57, 74], [57, 75], [57, 76], [57, 77], [57, 78], [57, 79], [57, 81], [57, 82], [57, 84], [57, 87], [57, 90], [57, 91], [57, 92], [57, 94], [57, 100], [57, 103], [57, 104], [57, 106], [57, 107], [57, 109], [57, 111], [57, 112], [57, 113], [57, 115], [57, 116], [57, 117], [57, 119], [58, 59], [58, 61], [58, 62], [58, 63], [58, 65], [58, 66], [58, 69], [58, 71], [58, 76], [58, 78], [58, 82], [58, 83], [58, 86], [58, 89], [58, 91], [58, 97], [58, 99], [58, 100], [58, 102], [58, 103], [58, 104], [58, 106], [58, 112], [58, 113], [58, 114], [58, 118], [59, 60], [59, 64], [59, 66], [59, 68], [59, 70], [59, 71], [59, 75], [59, 76], [59, 77], [59, 78], [59, 80], [59, 81], [59, 82], [59, 83], [59, 84], [59, 85], [59, 86], [59, 90], [59, 93], [59, 97], [59, 100], [59, 101], [59, 105], [59, 107], [59, 109], [59, 110], [59, 111], [59, 113], [59, 116], [59, 117], [59, 118], [60, 63], [60, 64], [60, 65], [60, 66], [60, 67], [60, 68], [60, 69], [60, 72], [60, 73], [60, 74], [60, 84], [60, 85], [60, 86], [60, 87], [60, 88], [60, 89], [60, 90], [60, 91], [60, 92], [60, 93], [60, 94], [60, 96], [60, 97], [60, 99], [60, 100], [60, 102], [60, 104], [60, 105], [60, 107], [60, 108], [60, 109], [60, 110], [60, 111], [60, 113], [60, 114], [60, 116], [60, 117], [60, 118], [60, 119], [61, 62], [61, 64], [61, 66], [61, 67], [61, 68], [61, 69], [61, 70], [61, 73], [61, 77], [61, 78], [61, 79], [61, 81], [61, 82], [61, 83], [61, 85], [61, 87], [61, 88], [61, 90], [61, 92], [61, 95], [61, 96], [61, 97], [61, 98], [61, 99], [61, 101], [61, 102], [61, 103], [61, 104], [61, 105], [61, 110], [61, 112], [61, 115], [61, 117], [61, 118], [62, 63], [62, 65], [62, 67], [62, 69], [62, 71], [62, 73], [62, 74], [62, 78], [62, 79], [62, 80], [62, 81], [62, 82], [62, 84], [62, 86], [62, 89], [62, 90], [62, 91], [62, 93], [62, 96], [62, 97], [62, 98], [62, 99], [62, 100], [62, 104], [62, 108], [62, 111], [62, 112], [62, 113], [62, 115], [62, 117], [62, 118], [63, 66], [63, 68], [63, 73], [63, 74], [63, 75], [63, 76], [63, 77], [63, 78], [63, 79], [63, 81], [63, 83], [63, 84], [63, 85], [63, 86], [63, 90], [63, 95], [63, 96], [63, 98], [63, 101], [63, 103], [63, 105], [63, 106], [63, 107], [63, 111], [63, 114], [63, 116], [63, 117], [64, 65], [64, 68], [64, 71], [64, 72], [64, 73], [64, 80], [64, 81], [64, 82], [64, 83], [64, 84], [64, 85], [64, 86], [64, 87], [64, 89], [64, 90], [64, 91], [64, 92], [64, 94], [64, 98], [64, 99], [64, 100], [64, 101], [64, 102], [64, 107], [64, 109], [64, 111], [64, 112], [64, 114], [64, 116], [64, 117], [65, 68], [65, 69], [65, 72], [65, 73], [65, 74], [65, 78], [65, 79], [65, 80], [65, 82], [65, 85], [65, 88], [65, 89], [65, 91], [65, 92], [65, 93], [65, 96], [65, 98], [65, 100], [65, 101], [65, 102], [65, 103], [65, 110], [65, 111], [65, 112], [65, 114], [65, 116], [65, 117], [65, 118], [65, 119], [66, 68], [66, 70], [66, 71], [66, 73], [66, 74], [66, 77], [66, 78], [66, 81], [66, 83], [66, 84], [66, 86], [66, 87], [66, 88], [66, 89], [66, 90], [66, 91], [66, 94], [66, 95], [66, 98], [66, 99], [66, 100], [66, 104], [66, 106], [66, 108], [66, 109], [66, 110], [66, 111], [66, 112], [66, 117], [66, 119], [67, 68], [67, 69], [67, 70], [67, 75], [67, 77], [67, 78], [67, 82], [67, 83], [67, 86], [67, 87], [67, 88], [67, 91], [67, 92], [67, 93], [67, 94], [67, 99], [67, 100], [67, 104], [67, 105], [67, 109], [67, 111], [67, 113], [67, 117], [67, 118], [68, 70], [68, 73], [68, 74], [68, 77], [68, 79], [68, 81], [68, 83], [68, 84], [68, 86], [68, 88], [68, 90], [68, 91], [68, 96], [68, 99], [68, 100], [68, 101], [68, 102], [68, 103], [68, 105], [68, 107], [68, 108], [68, 109], [68, 111], [68, 112], [68, 113], [68, 116], [68, 117], [69, 70], [69, 72], [69, 74], [69, 75], [69, 76], [69, 77], [69, 79], [69, 83], [69, 86], [69, 89], [69, 95], [69, 96], [69, 100], [69, 101], [69, 102], [69, 104], [69, 105], [69, 107], [69, 108], [69, 109], [69, 110], [69, 113], [69, 114], [69, 116], [70, 72], [70, 73], [70, 74], [70, 75], [70, 76], [70, 78], [70, 79], [70, 80], [70, 81], [70, 82], [70, 84], [70, 85], [70, 86], [70, 87], [70, 88], [70, 89], [70, 90], [70, 91], [70, 92], [70, 93], [70, 94], [70, 96], [70, 97], [70, 99], [70, 100], [70, 102], [70, 104], [70, 105], [70, 106], [70, 108], [70, 109], [70, 110], [70, 111], [70, 113], [70, 117], [71, 72], [71, 76], [71, 78], [71, 79], [71, 81], [71, 82], [71, 83], [71, 84], [71, 88], [71, 89], [71, 91], [71, 92], [71, 94], [71, 95], [71, 96], [71, 98], [71, 99], [71, 102], [71, 103], [71, 104], [71, 109], [71, 112], [71, 113], [71, 114], [71, 116], [71, 117], [72, 73], [72, 75], [72, 77], [72, 80], [72, 83], [72, 84], [72, 86], [72, 92], [72, 97], [72, 99], [72, 100], [72, 102], [72, 104], [72, 105], [72, 110], [72, 112], [72, 114], [72, 115], [72, 116], [72, 119], [73, 76], [73, 78], [73, 82], [73, 84], [73, 85], [73, 86], [73, 88], [73, 89], [73, 90], [73, 93], [73, 94], [73, 97], [73, 98], [73, 99], [73, 101], [73, 103], [73, 105], [73, 106], [73, 108], [73, 109], [73, 113], [73, 117], [74, 75], [74, 76], [74, 77], [74, 78], [74, 79], [74, 81], [74, 82], [74, 84], [74, 86], [74, 87], [74, 90], [74, 91], [74, 92], [74, 93], [74, 95], [74, 96], [74, 97], [74, 102], [74, 103], [74, 104], [74, 105], [74, 106], [74, 108], [74, 109], [74, 110], [74, 111], [74, 113], [74, 114], [74, 115], [74, 118], [75, 77], [75, 84], [75, 85], [75, 86], [75, 92], [75, 94], [75, 95], [75, 97], [75, 98], [75, 100], [75, 101], [75, 102], [75, 105], [75, 106], [75, 107], [75, 109], [75, 110], [75, 111], [75, 112], [75, 114], [75, 116], [75, 117], [75, 118], [76, 78], [76, 79], [76, 80], [76, 81], [76, 82], [76, 85], [76, 87], [76, 90], [76, 92], [76, 93], [76, 94], [76, 95], [76, 97], [76, 103], [76, 107], [76, 109], [76, 111], [76, 114], [76, 116], [77, 78], [77, 79], [77, 80], [77, 84], [77, 85], [77, 87], [77, 89], [77, 90], [77, 91], [77, 92], [77, 94], [77, 95], [77, 98], [77, 101], [77, 106], [77, 108], [77, 109], [77, 111], [77, 112], [77, 114], [77, 116], [77, 117], [78, 80], [78, 81], [78, 84], [78, 86], [78, 87], [78, 88], [78, 91], [78, 92], [78, 95], [78, 96], [78, 97], [78, 101], [78, 102], [78, 103], [78, 104], [78, 105], [78, 108], [78, 109], [78, 112], [78, 113], [78, 114], [78, 115], [78, 116], [78, 117], [78, 118], [79, 81], [79, 83], [79, 85], [79, 87], [79, 91], [79, 92], [79, 93], [79, 97], [79, 98], [79, 99], [79, 100], [79, 101], [79, 103], [79, 106], [79, 107], [79, 108], [79, 110], [79, 113], [79, 116], [79, 117], [79, 119], [80, 85], [80, 86], [80, 87], [80, 88], [80, 89], [80, 91], [80, 94], [80, 95], [80, 96], [80, 97], [80, 100], [80, 102], [80, 103], [80, 104], [80, 105], [80, 106], [80, 108], [80, 110], [80, 117], [80, 119], [81, 83], [81, 84], [81, 86], [81, 87], [81, 89], [81, 91], [81, 92], [81, 95], [81, 96], [81, 97], [81, 98], [81, 105], [81, 107], [81, 108], [81, 111], [81, 112], [81, 113], [81, 114], [81, 115], [81, 118], [81, 119], [82, 85], [82, 88], [82, 90], [82, 91], [82, 92], [82, 96], [82, 98], [82, 99], [82, 100], [82, 103], [82, 104], [82, 106], [82, 109], [82, 110], [82, 111], [82, 115], [82, 116], [83, 84], [83, 85], [83, 86], [83, 87], [83, 88], [83, 91], [83, 95], [83, 96], [83, 97], [83, 98], [83, 101], [83, 103], [83, 104], [83, 105], [83, 107], [83, 110], [83, 112], [83, 114], [83, 115], [83, 116], [83, 118], [83, 119], [84, 86], [84, 89], [84, 90], [84, 91], [84, 97], [84, 101], [84, 103], [84, 104], [84, 105], [84, 106], [84, 108], [84, 111], [84, 113], [84, 114], [84, 116], [84, 117], [84, 118], [85, 86], [85, 91], [85, 92], [85, 93], [85, 99], [85, 103], [85, 104], [85, 105], [85, 107], [85, 108], [85, 110], [85, 111], [85, 115], [86, 87], [86, 88], [86, 89], [86, 90], [86, 92], [86, 94], [86, 96], [86, 97], [86, 99], [86, 100], [86, 101], [86, 103], [86, 104], [86, 105], [86, 108], [86, 109], [86, 111], [86, 112], [86, 116], [87, 88], [87, 89], [87, 90], [87, 91], [87, 93], [87, 96], [87, 97], [87, 98], [87, 99], [87, 102], [87, 104], [87, 106], [87, 107], [87, 108], [87, 111], [87, 113], [87, 115], [87, 117], [87, 118], [88, 90], [88, 91], [88, 92], [88, 93], [88, 94], [88, 96], [88, 99], [88, 101], [88, 103], [88, 104], [88, 105], [88, 107], [88, 109], [88, 113], [88, 114], [88, 115], [88, 117], [88, 118], [88, 119], [89, 91], [89, 93], [89, 95], [89, 96], [89, 97], [89, 101], [89, 102], [89, 104], [89, 106], [89, 107], [89, 108], [89, 110], [89, 111], [89, 112], [89, 113], [89, 115], [89, 116], [89, 119], [90, 91], [90, 93], [90, 94], [90, 95], [90, 100], [90, 101], [90, 107], [90, 108], [90, 109], [90, 111], [90, 113], [90, 115], [90, 116], [90, 118], [90, 119], [91, 92], [91, 94], [91, 95], [91, 97], [91, 98], [91, 99], [91, 105], [91, 113], [91, 114], [91, 115], [91, 117], [91, 118], [91, 119], [92, 94], [92, 95], [92, 96], [92, 98], [92, 101], [92, 102], [92, 104], [92, 105], [92, 107], [92, 111], [92, 113], [92, 115], [92, 118], [93, 94], [93, 96], [93, 98], [93, 99], [93, 100], [93, 101], [93, 103], [93, 104], [93, 105], [93, 107], [93, 110], [93, 111], [93, 113], [93, 114], [93, 115], [93, 119], [94, 95], [94, 96], [94, 97], [94, 98], [94, 99], [94, 100], [94, 102], [94, 103], [94, 104], [94, 106], [94, 107], [94, 108], [94, 109], [94, 110], [94, 111], [94, 112], [94, 113], [94, 114], [95, 96], [95, 98], [95, 99], [95, 101], [95, 102], [95, 103], [95, 104], [95, 105], [95, 106], [95, 107], [95, 108], [95, 112], [95, 117], [95, 118], [96, 97], [96, 99], [96, 104], [96, 105], [96, 109], [96, 110], [96, 112], [96, 116], [96, 117], [96, 119], [97, 100], [97, 101], [97, 102], [97, 106], [97, 107], [97, 109], [97, 113], [97, 114], [97, 116], [97, 117], [97, 119], [98, 103], [98, 104], [98, 106], [98, 109], [98, 114], [98, 115], [98, 116], [98, 117], [98, 119], [99, 101], [99, 102], [99, 103], [99, 104], [99, 105], [99, 106], [99, 108], [99, 113], [99, 115], [99, 116], [99, 117], [99, 118], [99, 119], [100, 101], [100, 103], [100, 104], [100, 105], [100, 107], [100, 109], [100, 111], [100, 113], [100, 114], [100, 117], [100, 118], [100, 119], [101, 102], [101, 103], [101, 105], [101, 107], [101, 110], [101, 111], [101, 115], [101, 117], [101, 118], [101, 119], [102, 103], [102, 104], [102, 105], [102, 109], [102, 111], [102, 113], [102, 115], [102, 116], [102, 117], [102, 118], [102, 119], [103, 104], [103, 107], [103, 109], [103, 110], [103, 111], [103, 113], [103, 114], [103, 116], [103, 118], [103, 119], [104, 105], [104, 107], [104, 110], [104, 111], [104, 113], [104, 114], [104, 118], [105, 106], [105, 107], [105, 108], [105, 109], [105, 111], [105, 112], [105, 114], [105, 115], [106, 107], [106, 108], [106, 110], [106, 112], [106, 113], [106, 115], [106, 116], [106, 118], [106, 119], [107, 108], [107, 110], [107, 111], [107, 112], [107, 113], [107, 116], [107, 117], [108, 109], [108, 110], [108, 111], [108, 114], [108, 115], [108, 117], [108, 118], [109, 110], [109, 111], [109, 112], [109, 113], [109, 116], [109, 118], [109, 119], [110, 111], [110, 114], [110, 118], [110, 119], [111, 112], [111, 113], [111, 114], [111, 115], [111, 116], [112, 114], [112, 115], [112, 116], [112, 117], [112, 119], [113, 114], [113, 116], [113, 118], [114, 115], [114, 116], [114, 119], [115, 117], [115, 119], [116, 119], [117, 118], [117, 119]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l6-s5/tests/run.py b/tasks/construct-mc-max-clique-l6-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-clique-l6-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-clique-l6-s5/tests/test.sh b/tasks/construct-mc-max-clique-l6-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-clique-l6-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-independent-set-l1-s1/environment/Dockerfile b/tasks/construct-mc-max-independent-set-l1-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l1-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-independent-set-l1-s1/environment/instance.json b/tasks/construct-mc-max-independent-set-l1-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cabc08065cb0bbe916885204e67b7e3f228c8715 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l1-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 20, "k": 7, "edges": [[0, 4], [1, 3], [1, 7], [1, 15], [1, 16], [1, 19], [2, 6], [2, 8], [2, 10], [2, 15], [3, 5], [3, 9], [3, 11], [3, 19], [4, 9], [4, 10], [4, 14], [4, 17], [4, 19], [5, 11], [5, 12], [5, 14], [7, 11], [7, 13], [7, 14], [7, 18], [8, 13], [8, 16], [9, 11], [10, 11], [10, 16], [11, 17], [11, 19], [12, 13], [13, 15], [13, 17], [14, 16], [14, 18], [15, 16], [16, 17], [16, 18], [17, 19]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l1-s1/solution/solve.sh b/tasks/construct-mc-max-independent-set-l1-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..33bfe9554578151d64291b276b21cb07d412b5f7 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l1-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"independent_set": [0, 6, 8, 9, 12, 14, 15]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-independent-set-l1-s1/tests/check.py b/tasks/construct-mc-max-independent-set-l1-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..adce413e8578d996549583b990e4ff559f38ed41 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l1-s1/tests/check.py @@ -0,0 +1,18 @@ +"""Independent set of size >= k in a given graph (MathConstraint max_independent_set, CC-BY-4.0).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("independent_set"), None, 0, n - 1, "independent_set") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) < k: + raise Invalid(f"set has {len(S)} vertices, need at least {k}") + E = {(u, v) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(S), 2): + if (u, v) in E: + raise Invalid(f"vertices {u} and {v} are adjacent") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-max-independent-set-l1-s1/tests/instance.json b/tasks/construct-mc-max-independent-set-l1-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cabc08065cb0bbe916885204e67b7e3f228c8715 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l1-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 20, "k": 7, "edges": [[0, 4], [1, 3], [1, 7], [1, 15], [1, 16], [1, 19], [2, 6], [2, 8], [2, 10], [2, 15], [3, 5], [3, 9], [3, 11], [3, 19], [4, 9], [4, 10], [4, 14], [4, 17], [4, 19], [5, 11], [5, 12], [5, 14], [7, 11], [7, 13], [7, 14], [7, 18], [8, 13], [8, 16], [9, 11], [10, 11], [10, 16], [11, 17], [11, 19], [12, 13], [13, 15], [13, 17], [14, 16], [14, 18], [15, 16], [16, 17], [16, 18], [17, 19]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l1-s1/tests/run.py b/tasks/construct-mc-max-independent-set-l1-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l1-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-independent-set-l1-s1/tests/test.sh b/tasks/construct-mc-max-independent-set-l1-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l1-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-independent-set-l1-s6/environment/Dockerfile b/tasks/construct-mc-max-independent-set-l1-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l1-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-independent-set-l1-s6/environment/instance.json b/tasks/construct-mc-max-independent-set-l1-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8c9ed550f3531835518a786c39c7addab6160b44 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l1-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 20, "k": 7, "edges": [[0, 1], [0, 3], [0, 5], [0, 7], [0, 8], [0, 9], [0, 10], [0, 13], [0, 17], [1, 2], [1, 5], [1, 11], [1, 13], [1, 15], [1, 17], [1, 18], [2, 10], [2, 14], [2, 17], [3, 5], [3, 6], [3, 9], [3, 10], [3, 15], [3, 19], [4, 5], [4, 6], [4, 10], [4, 14], [4, 18], [5, 6], [5, 9], [5, 10], [5, 15], [5, 17], [6, 8], [6, 12], [6, 16], [6, 19], [8, 12], [8, 15], [8, 18], [9, 12], [9, 15], [9, 16], [9, 17], [9, 18], [9, 19], [10, 11], [10, 19], [11, 13], [12, 14], [12, 15], [13, 14], [14, 15], [14, 16], [14, 19], [15, 17], [15, 18], [16, 17], [16, 19]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l1-s6/solution/solve.sh b/tasks/construct-mc-max-independent-set-l1-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1ab240129eb216c16e1ce3828119328c074b6b07 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l1-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"independent_set": [2, 3, 4, 7, 12, 13, 16]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-independent-set-l1-s6/tests/check.py b/tasks/construct-mc-max-independent-set-l1-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..adce413e8578d996549583b990e4ff559f38ed41 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l1-s6/tests/check.py @@ -0,0 +1,18 @@ +"""Independent set of size >= k in a given graph (MathConstraint max_independent_set, CC-BY-4.0).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("independent_set"), None, 0, n - 1, "independent_set") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) < k: + raise Invalid(f"set has {len(S)} vertices, need at least {k}") + E = {(u, v) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(S), 2): + if (u, v) in E: + raise Invalid(f"vertices {u} and {v} are adjacent") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-max-independent-set-l1-s6/tests/instance.json b/tasks/construct-mc-max-independent-set-l1-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8c9ed550f3531835518a786c39c7addab6160b44 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l1-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 20, "k": 7, "edges": [[0, 1], [0, 3], [0, 5], [0, 7], [0, 8], [0, 9], [0, 10], [0, 13], [0, 17], [1, 2], [1, 5], [1, 11], [1, 13], [1, 15], [1, 17], [1, 18], [2, 10], [2, 14], [2, 17], [3, 5], [3, 6], [3, 9], [3, 10], [3, 15], [3, 19], [4, 5], [4, 6], [4, 10], [4, 14], [4, 18], [5, 6], [5, 9], [5, 10], [5, 15], [5, 17], [6, 8], [6, 12], [6, 16], [6, 19], [8, 12], [8, 15], [8, 18], [9, 12], [9, 15], [9, 16], [9, 17], [9, 18], [9, 19], [10, 11], [10, 19], [11, 13], [12, 14], [12, 15], [13, 14], [14, 15], [14, 16], [14, 19], [15, 17], [15, 18], [16, 17], [16, 19]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l1-s6/tests/run.py b/tasks/construct-mc-max-independent-set-l1-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l1-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-independent-set-l1-s6/tests/test.sh b/tasks/construct-mc-max-independent-set-l1-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l1-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-independent-set-l1-s8/environment/Dockerfile b/tasks/construct-mc-max-independent-set-l1-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l1-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-independent-set-l1-s8/environment/instance.json b/tasks/construct-mc-max-independent-set-l1-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b04dc484b917af7088d6cea3c14a6d558eb8690f --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l1-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 20, "k": 7, "edges": [[0, 12], [0, 13], [0, 15], [0, 16], [0, 17], [0, 19], [1, 5], [1, 7], [1, 8], [1, 15], [1, 16], [2, 3], [2, 5], [2, 7], [2, 8], [2, 11], [2, 12], [2, 14], [2, 15], [2, 17], [3, 10], [3, 17], [4, 12], [4, 13], [4, 14], [4, 16], [5, 8], [5, 11], [6, 12], [6, 17], [7, 9], [7, 14], [7, 15], [7, 16], [7, 17], [8, 14], [8, 17], [9, 12], [9, 14], [10, 12], [10, 13], [10, 15], [10, 17], [11, 18], [11, 19], [12, 13], [13, 15], [13, 16], [13, 19], [14, 17], [15, 16], [15, 17], [16, 19], [17, 18], [17, 19], [18, 19]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l1-s8/solution/solve.sh b/tasks/construct-mc-max-independent-set-l1-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2c0adceec82be4ade8ae2c69e3ed0b021f36343f --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l1-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"independent_set": [0, 1, 2, 4, 6, 9, 10]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-independent-set-l1-s8/tests/check.py b/tasks/construct-mc-max-independent-set-l1-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..adce413e8578d996549583b990e4ff559f38ed41 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l1-s8/tests/check.py @@ -0,0 +1,18 @@ +"""Independent set of size >= k in a given graph (MathConstraint max_independent_set, CC-BY-4.0).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("independent_set"), None, 0, n - 1, "independent_set") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) < k: + raise Invalid(f"set has {len(S)} vertices, need at least {k}") + E = {(u, v) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(S), 2): + if (u, v) in E: + raise Invalid(f"vertices {u} and {v} are adjacent") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-max-independent-set-l1-s8/tests/instance.json b/tasks/construct-mc-max-independent-set-l1-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b04dc484b917af7088d6cea3c14a6d558eb8690f --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l1-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 20, "k": 7, "edges": [[0, 12], [0, 13], [0, 15], [0, 16], [0, 17], [0, 19], [1, 5], [1, 7], [1, 8], [1, 15], [1, 16], [2, 3], [2, 5], [2, 7], [2, 8], [2, 11], [2, 12], [2, 14], [2, 15], [2, 17], [3, 10], [3, 17], [4, 12], [4, 13], [4, 14], [4, 16], [5, 8], [5, 11], [6, 12], [6, 17], [7, 9], [7, 14], [7, 15], [7, 16], [7, 17], [8, 14], [8, 17], [9, 12], [9, 14], [10, 12], [10, 13], [10, 15], [10, 17], [11, 18], [11, 19], [12, 13], [13, 15], [13, 16], [13, 19], [14, 17], [15, 16], [15, 17], [16, 19], [17, 18], [17, 19], [18, 19]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l1-s8/tests/run.py b/tasks/construct-mc-max-independent-set-l1-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l1-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-independent-set-l1-s8/tests/test.sh b/tasks/construct-mc-max-independent-set-l1-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l1-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-independent-set-l5-s0/environment/Dockerfile b/tasks/construct-mc-max-independent-set-l5-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l5-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-independent-set-l5-s0/environment/instance.json b/tasks/construct-mc-max-independent-set-l5-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..14b32f14717129a3fc9d9f4456db285afda65734 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l5-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 90, "k": 16, "edges": [[0, 13], [0, 18], [0, 23], [0, 24], [0, 35], [0, 44], [0, 46], [0, 52], [0, 53], [0, 58], [0, 60], [0, 61], [0, 63], [0, 70], [0, 81], [0, 88], [1, 3], [1, 10], [1, 15], [1, 19], [1, 20], [1, 21], [1, 22], [1, 23], [1, 25], [1, 27], [1, 28], [1, 29], [1, 32], [1, 35], [1, 43], [1, 47], [1, 48], [1, 52], [1, 53], [1, 58], [1, 59], [1, 60], [1, 61], [1, 62], [1, 65], [1, 73], [1, 75], [1, 76], [1, 79], [1, 83], [2, 9], [2, 13], [2, 14], [2, 17], [2, 18], [2, 23], [2, 33], [2, 34], [2, 41], [2, 43], [2, 46], [2, 49], [2, 50], [2, 52], [2, 53], [2, 56], [2, 61], [2, 62], [2, 63], [2, 72], [2, 73], [2, 75], [2, 76], [2, 77], [2, 78], [2, 84], [2, 85], [3, 8], [3, 11], [3, 16], [3, 20], [3, 22], [3, 24], [3, 25], [3, 27], [3, 29], [3, 31], [3, 37], [3, 41], [3, 42], [3, 48], [3, 50], [3, 51], [3, 52], [3, 53], [3, 54], [3, 57], [3, 60], [3, 61], [3, 64], [3, 68], [3, 69], [3, 71], [3, 73], [3, 77], [3, 84], [4, 11], [4, 13], [4, 14], [4, 18], [4, 24], [4, 27], [4, 30], [4, 32], [4, 37], [4, 50], [4, 52], [4, 54], [4, 56], [4, 69], [4, 73], [4, 77], [4, 82], [4, 88], [4, 89], [5, 16], [5, 17], [5, 24], [5, 27], [5, 28], [5, 40], [5, 47], [5, 54], [5, 60], [5, 63], [5, 70], [5, 73], [5, 74], [5, 75], [5, 77], [5, 81], [5, 84], [5, 88], [6, 9], [6, 12], [6, 17], [6, 18], [6, 23], [6, 24], [6, 25], [6, 26], [6, 30], [6, 31], [6, 33], [6, 34], [6, 37], [6, 43], [6, 48], [6, 49], [6, 51], [6, 56], [6, 60], [6, 66], [6, 69], [6, 70], [6, 75], [6, 77], [6, 81], [6, 82], [6, 84], [7, 8], [7, 10], [7, 12], [7, 14], [7, 16], [7, 17], [7, 24], [7, 26], [7, 28], [7, 29], [7, 35], [7, 39], [7, 40], [7, 43], [7, 45], [7, 47], [7, 52], [7, 53], [7, 55], [7, 57], [7, 58], [7, 59], [7, 67], [7, 70], [7, 77], [7, 81], [7, 85], [7, 86], [7, 89], [8, 13], [8, 15], [8, 24], [8, 28], [8, 31], [8, 32], [8, 39], [8, 42], [8, 44], [8, 45], [8, 47], [8, 64], [8, 69], [8, 73], [8, 78], [8, 81], [8, 82], [8, 86], [8, 89], [9, 15], [9, 18], [9, 19], [9, 26], [9, 33], [9, 36], [9, 39], [9, 42], [9, 45], [9, 47], [9, 48], [9, 49], [9, 52], [9, 54], [9, 55], [9, 60], [9, 62], [9, 64], [9, 69], [9, 71], [9, 73], [9, 75], [9, 77], [9, 78], [9, 79], [9, 84], [9, 85], [9, 87], [9, 89], [10, 13], [10, 18], [10, 21], [10, 39], [10, 44], [10, 45], [10, 53], [10, 56], [10, 67], [10, 73], [10, 74], [10, 84], [11, 13], [11, 18], [11, 20], [11, 26], [11, 27], [11, 35], [11, 40], [11, 49], [11, 50], [11, 54], [11, 55], [11, 58], [11, 59], [11, 62], [11, 66], [11, 71], [11, 72], [11, 77], [11, 81], [11, 84], [11, 85], [11, 89], [12, 17], [12, 18], [12, 22], [12, 23], [12, 27], [12, 28], [12, 33], [12, 39], [12, 41], [12, 42], [12, 44], [12, 47], [12, 55], [12, 58], [12, 59], [12, 63], [12, 64], [12, 66], [12, 70], [12, 75], [12, 82], [12, 85], [12, 86], [12, 88], [13, 14], [13, 18], [13, 22], [13, 23], [13, 25], [13, 26], [13, 28], [13, 34], [13, 40], [13, 49], [13, 51], [13, 53], [13, 57], [13, 59], [13, 60], [13, 61], [13, 62], [13, 63], [13, 64], [13, 66], [13, 67], [13, 71], [13, 72], [13, 73], [13, 78], [13, 81], [13, 83], [13, 84], [13, 87], [14, 25], [14, 29], [14, 31], [14, 34], [14, 37], [14, 44], [14, 47], [14, 51], [14, 52], [14, 58], [14, 63], [14, 65], [14, 68], [14, 72], [14, 74], [14, 76], [14, 88], [15, 21], [15, 27], [15, 28], [15, 44], [15, 46], [15, 47], [15, 50], [15, 51], [15, 52], [15, 56], [15, 60], [15, 65], [15, 66], [15, 69], [15, 76], [15, 77], [15, 79], [15, 85], [16, 17], [16, 18], [16, 21], [16, 22], [16, 24], [16, 27], [16, 32], [16, 33], [16, 42], [16, 48], [16, 49], [16, 50], [16, 56], [16, 58], [16, 59], [16, 60], [16, 61], [16, 66], [16, 70], [16, 71], [16, 72], [16, 74], [16, 81], [16, 82], [17, 22], [17, 23], [17, 28], [17, 30], [17, 31], [17, 35], [17, 36], [17, 38], [17, 39], [17, 40], [17, 45], [17, 50], [17, 62], [17, 65], [17, 66], [17, 67], [17, 69], [17, 75], [17, 76], [17, 79], [17, 80], [18, 25], [18, 30], [18, 31], [18, 33], [18, 36], [18, 37], [18, 38], [18, 45], [18, 51], [18, 60], [18, 62], [18, 65], [18, 72], [18, 76], [18, 78], [18, 81], [18, 84], [18, 85], [18, 86], [19, 21], [19, 23], [19, 25], [19, 28], [19, 29], [19, 34], [19, 35], [19, 43], [19, 44], [19, 46], [19, 47], [19, 50], [19, 53], [19, 60], [19, 66], [19, 68], [19, 73], [19, 74], [19, 75], [19, 77], [19, 78], [19, 81], [19, 82], [19, 89], [20, 22], [20, 23], [20, 24], [20, 27], [20, 29], [20, 30], [20, 32], [20, 34], [20, 36], [20, 50], [20, 52], [20, 59], [20, 60], [20, 64], [20, 67], [20, 68], [20, 70], [20, 80], [20, 81], [20, 89], [21, 22], [21, 34], [21, 35], [21, 44], [21, 45], [21, 47], [21, 49], [21, 50], [21, 52], [21, 55], [21, 58], [21, 59], [21, 60], [21, 62], [21, 71], [21, 72], [21, 74], [21, 76], [21, 79], [21, 82], [21, 83], [21, 84], [22, 29], [22, 30], [22, 32], [22, 35], [22, 36], [22, 42], [22, 47], [22, 52], [22, 58], [22, 61], [22, 68], [22, 72], [22, 88], [23, 25], [23, 32], [23, 34], [23, 35], [23, 36], [23, 39], [23, 41], [23, 43], [23, 51], [23, 57], [23, 59], [23, 62], [23, 66], [23, 76], [23, 80], [23, 83], [23, 86], [23, 87], [23, 89], [24, 28], [24, 38], [24, 42], [24, 46], [24, 57], [24, 61], [24, 63], [24, 64], [24, 72], [24, 75], [24, 79], [24, 87], [24, 88], [25, 28], [25, 30], [25, 31], [25, 33], [25, 36], [25, 39], [25, 40], [25, 46], [25, 47], [25, 53], [25, 57], [25, 61], [25, 65], [25, 70], [25, 71], [25, 72], [25, 73], [25, 74], [25, 76], [25, 78], [25, 84], [25, 87], [25, 89], [26, 29], [26, 30], [26, 32], [26, 37], [26, 46], [26, 48], [26, 50], [26, 52], [26, 53], [26, 58], [26, 62], [26, 65], [26, 66], [26, 70], [26, 79], [26, 81], [26, 82], [26, 83], [26, 86], [27, 29], [27, 31], [27, 32], [27, 34], [27, 38], [27, 44], [27, 45], [27, 56], [27, 58], [27, 63], [27, 67], [27, 70], [27, 71], [27, 75], [27, 81], [27, 82], [27, 84], [27, 87], [28, 32], [28, 41], [28, 44], [28, 45], [28, 47], [28, 48], [28, 50], [28, 51], [28, 60], [28, 62], [28, 63], [28, 70], [28, 73], [28, 74], [28, 76], [28, 77], [28, 78], [28, 82], [28, 83], [28, 86], [28, 88], [29, 30], [29, 33], [29, 34], [29, 38], [29, 40], [29, 41], [29, 43], [29, 45], [29, 50], [29, 51], [29, 54], [29, 55], [29, 56], [29, 62], [29, 68], [29, 69], [29, 70], [29, 75], [29, 80], [29, 88], [30, 31], [30, 33], [30, 37], [30, 38], [30, 40], [30, 41], [30, 45], [30, 48], [30, 52], [30, 54], [30, 56], [30, 63], [30, 66], [30, 67], [30, 72], [30, 74], [30, 75], [30, 85], [30, 87], [31, 32], [31, 33], [31, 44], [31, 47], [31, 49], [31, 50], [31, 60], [31, 64], [31, 70], [31, 71], [31, 72], [31, 77], [31, 78], [31, 80], [31, 85], [31, 86], [32, 34], [32, 38], [32, 45], [32, 47], [32, 50], [32, 51], [32, 52], [32, 58], [32, 63], [32, 66], [32, 88], [33, 34], [33, 35], [33, 36], [33, 39], [33, 46], [33, 50], [33, 52], [33, 53], [33, 56], [33, 59], [33, 60], [33, 63], [33, 64], [33, 65], [33, 66], [33, 72], [33, 73], [33, 81], [33, 84], [33, 87], [33, 88], [34, 37], [34, 43], [34, 44], [34, 46], [34, 48], [34, 51], [34, 54], [34, 57], [34, 59], [34, 65], [34, 68], [34, 70], [34, 71], [34, 72], [34, 73], [34, 74], [34, 79], [34, 80], [34, 83], [34, 84], [34, 85], [34, 89], [35, 40], [35, 41], [35, 42], [35, 43], [35, 44], [35, 45], [35, 47], [35, 51], [35, 53], [35, 54], [35, 57], [35, 58], [35, 59], [35, 61], [35, 63], [35, 66], [35, 70], [35, 76], [35, 77], [35, 80], [35, 86], [35, 87], [35, 88], [36, 39], [36, 44], [36, 60], [36, 62], [36, 67], [36, 73], [36, 78], [36, 79], [36, 80], [36, 82], [36, 85], [36, 87], [36, 88], [36, 89], [37, 40], [37, 47], [37, 49], [37, 52], [37, 53], [37, 57], [37, 58], [37, 60], [37, 62], [37, 65], [37, 67], [37, 69], [37, 71], [37, 72], [37, 73], [37, 75], [37, 79], [37, 81], [37, 82], [37, 83], [37, 86], [37, 87], [38, 39], [38, 40], [38, 41], [38, 42], [38, 47], [38, 50], [38, 60], [38, 68], [38, 69], [38, 71], [38, 72], [38, 73], [38, 74], [38, 78], [38, 81], [38, 82], [39, 40], [39, 41], [39, 42], [39, 44], [39, 50], [39, 56], [39, 60], [39, 64], [39, 66], [39, 67], [39, 69], [39, 78], [39, 84], [39, 85], [39, 87], [40, 41], [40, 44], [40, 48], [40, 50], [40, 53], [40, 54], [40, 62], [40, 63], [40, 64], [40, 66], [40, 70], [40, 71], [40, 76], [40, 83], [40, 86], [40, 87], [40, 88], [41, 46], [41, 48], [41, 49], [41, 51], [41, 55], [41, 75], [41, 80], [41, 84], [41, 87], [42, 47], [42, 49], [42, 50], [42, 52], [42, 54], [42, 55], [42, 56], [42, 58], [42, 59], [42, 61], [42, 64], [42, 66], [42, 69], [42, 71], [42, 72], [42, 75], [42, 77], [42, 78], [42, 80], [42, 83], [43, 48], [43, 49], [43, 52], [43, 54], [43, 55], [43, 66], [43, 69], [43, 70], [43, 71], [43, 73], [43, 75], [43, 76], [43, 78], [43, 80], [43, 81], [43, 85], [43, 86], [43, 88], [43, 89], [44, 46], [44, 50], [44, 56], [44, 59], [44, 67], [44, 70], [44, 77], [44, 79], [44, 81], [44, 82], [44, 85], [44, 88], [45, 50], [45, 51], [45, 52], [45, 54], [45, 61], [45, 62], [45, 63], [45, 69], [45, 70], [45, 73], [45, 76], [45, 77], [45, 78], [46, 49], [46, 54], [46, 55], [46, 56], [46, 58], [46, 62], [46, 71], [46, 73], [46, 78], [46, 85], [46, 86], [46, 88], [46, 89], [47, 59], [47, 60], [47, 61], [47, 63], [47, 68], [47, 72], [47, 73], [47, 74], [47, 79], [47, 82], [47, 84], [47, 89], [48, 49], [48, 51], [48, 54], [48, 61], [48, 65], [48, 70], [48, 72], [48, 75], [48, 77], [49, 50], [49, 52], [49, 55], [49, 56], [49, 60], [49, 62], [49, 66], [49, 67], [49, 72], [49, 75], [49, 76], [49, 77], [49, 79], [49, 83], [49, 84], [49, 86], [49, 88], [50, 65], [50, 68], [50, 71], [50, 75], [50, 80], [50, 83], [50, 85], [50, 87], [50, 88], [50, 89], [51, 53], [51, 54], [51, 58], [51, 61], [51, 68], [51, 69], [51, 71], [51, 72], [51, 75], [51, 76], [51, 78], [51, 79], [51, 80], [51, 81], [51, 83], [51, 86], [52, 54], [52, 56], [52, 58], [52, 60], [52, 64], [52, 66], [52, 69], [52, 72], [52, 74], [52, 81], [52, 84], [52, 85], [53, 66], [53, 68], [53, 69], [53, 74], [53, 78], [53, 80], [53, 82], [53, 84], [54, 58], [54, 61], [54, 62], [54, 63], [54, 64], [54, 66], [54, 70], [54, 71], [54, 72], [54, 73], [54, 78], [54, 80], [54, 81], [54, 82], [54, 83], [54, 85], [54, 86], [54, 87], [54, 88], [55, 56], [55, 57], [55, 58], [55, 61], [55, 62], [55, 63], [55, 64], [55, 66], [55, 70], [55, 73], [56, 70], [56, 72], [56, 74], [56, 78], [56, 82], [56, 84], [56, 85], [56, 86], [57, 59], [57, 64], [57, 67], [57, 69], [57, 70], [57, 72], [57, 73], [57, 74], [57, 75], [57, 76], [57, 77], [57, 83], [57, 88], [57, 89], [58, 60], [58, 63], [58, 65], [58, 69], [58, 71], [58, 73], [58, 79], [58, 81], [58, 84], [58, 85], [58, 86], [59, 73], [59, 82], [60, 61], [60, 62], [60, 64], [60, 66], [60, 68], [60, 69], [60, 74], [60, 78], [60, 82], [60, 88], [61, 63], [61, 64], [61, 67], [61, 73], [61, 74], [61, 80], [61, 82], [61, 84], [61, 87], [62, 71], [62, 74], [62, 75], [62, 76], [62, 77], [62, 83], [62, 86], [63, 74], [63, 77], [63, 80], [63, 82], [63, 83], [64, 65], [64, 67], [64, 73], [64, 76], [64, 77], [64, 82], [64, 83], [64, 89], [65, 67], [65, 71], [65, 75], [65, 77], [65, 82], [65, 83], [65, 87], [65, 89], [66, 68], [66, 71], [66, 75], [66, 76], [66, 77], [66, 82], [66, 83], [66, 86], [66, 89], [67, 73], [67, 76], [67, 85], [68, 76], [68, 79], [68, 86], [68, 89], [69, 71], [69, 74], [69, 78], [69, 80], [69, 82], [69, 84], [69, 86], [69, 88], [69, 89], [70, 73], [70, 77], [70, 79], [70, 85], [70, 88], [70, 89], [71, 75], [71, 78], [71, 80], [71, 81], [71, 88], [72, 81], [72, 84], [72, 85], [73, 75], [73, 79], [73, 81], [73, 85], [73, 87], [73, 89], [74, 81], [74, 82], [74, 84], [75, 85], [75, 86], [76, 77], [76, 78], [76, 79], [76, 88], [76, 89], [77, 78], [77, 85], [78, 80], [78, 83], [78, 86], [78, 87], [79, 83], [79, 85], [79, 86], [80, 84], [80, 89], [81, 83], [81, 84], [81, 85], [81, 86], [82, 87], [82, 88], [82, 89], [84, 85], [84, 86], [86, 88], [87, 89]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l5-s0/solution/solve.sh b/tasks/construct-mc-max-independent-set-l5-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..739047364168f3dafd8c34c2d98e0df27566b73d --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l5-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"independent_set": [0, 2, 3, 4, 5, 6, 15, 19, 38, 45, 55, 67, 80, 83, 86, 87]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-independent-set-l5-s0/tests/check.py b/tasks/construct-mc-max-independent-set-l5-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..adce413e8578d996549583b990e4ff559f38ed41 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l5-s0/tests/check.py @@ -0,0 +1,18 @@ +"""Independent set of size >= k in a given graph (MathConstraint max_independent_set, CC-BY-4.0).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("independent_set"), None, 0, n - 1, "independent_set") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) < k: + raise Invalid(f"set has {len(S)} vertices, need at least {k}") + E = {(u, v) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(S), 2): + if (u, v) in E: + raise Invalid(f"vertices {u} and {v} are adjacent") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-max-independent-set-l5-s0/tests/instance.json b/tasks/construct-mc-max-independent-set-l5-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..14b32f14717129a3fc9d9f4456db285afda65734 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l5-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 90, "k": 16, "edges": [[0, 13], [0, 18], [0, 23], [0, 24], [0, 35], [0, 44], [0, 46], [0, 52], [0, 53], [0, 58], [0, 60], [0, 61], [0, 63], [0, 70], [0, 81], [0, 88], [1, 3], [1, 10], [1, 15], [1, 19], [1, 20], [1, 21], [1, 22], [1, 23], [1, 25], [1, 27], [1, 28], [1, 29], [1, 32], [1, 35], [1, 43], [1, 47], [1, 48], [1, 52], [1, 53], [1, 58], [1, 59], [1, 60], [1, 61], [1, 62], [1, 65], [1, 73], [1, 75], [1, 76], [1, 79], [1, 83], [2, 9], [2, 13], [2, 14], [2, 17], [2, 18], [2, 23], [2, 33], [2, 34], [2, 41], [2, 43], [2, 46], [2, 49], [2, 50], [2, 52], [2, 53], [2, 56], [2, 61], [2, 62], [2, 63], [2, 72], [2, 73], [2, 75], [2, 76], [2, 77], [2, 78], [2, 84], [2, 85], [3, 8], [3, 11], [3, 16], [3, 20], [3, 22], [3, 24], [3, 25], [3, 27], [3, 29], [3, 31], [3, 37], [3, 41], [3, 42], [3, 48], [3, 50], [3, 51], [3, 52], [3, 53], [3, 54], [3, 57], [3, 60], [3, 61], [3, 64], [3, 68], [3, 69], [3, 71], [3, 73], [3, 77], [3, 84], [4, 11], [4, 13], [4, 14], [4, 18], [4, 24], [4, 27], [4, 30], [4, 32], [4, 37], [4, 50], [4, 52], [4, 54], [4, 56], [4, 69], [4, 73], [4, 77], [4, 82], [4, 88], [4, 89], [5, 16], [5, 17], [5, 24], [5, 27], [5, 28], [5, 40], [5, 47], [5, 54], [5, 60], [5, 63], [5, 70], [5, 73], [5, 74], [5, 75], [5, 77], [5, 81], [5, 84], [5, 88], [6, 9], [6, 12], [6, 17], [6, 18], [6, 23], [6, 24], [6, 25], [6, 26], [6, 30], [6, 31], [6, 33], [6, 34], [6, 37], [6, 43], [6, 48], [6, 49], [6, 51], [6, 56], [6, 60], [6, 66], [6, 69], [6, 70], [6, 75], [6, 77], [6, 81], [6, 82], [6, 84], [7, 8], [7, 10], [7, 12], [7, 14], [7, 16], [7, 17], [7, 24], [7, 26], [7, 28], [7, 29], [7, 35], [7, 39], [7, 40], [7, 43], [7, 45], [7, 47], [7, 52], [7, 53], [7, 55], [7, 57], [7, 58], [7, 59], [7, 67], [7, 70], [7, 77], [7, 81], [7, 85], [7, 86], [7, 89], [8, 13], [8, 15], [8, 24], [8, 28], [8, 31], [8, 32], [8, 39], [8, 42], [8, 44], [8, 45], [8, 47], [8, 64], [8, 69], [8, 73], [8, 78], [8, 81], [8, 82], [8, 86], [8, 89], [9, 15], [9, 18], [9, 19], [9, 26], [9, 33], [9, 36], [9, 39], [9, 42], [9, 45], [9, 47], [9, 48], [9, 49], [9, 52], [9, 54], [9, 55], [9, 60], [9, 62], [9, 64], [9, 69], [9, 71], [9, 73], [9, 75], [9, 77], [9, 78], [9, 79], [9, 84], [9, 85], [9, 87], [9, 89], [10, 13], [10, 18], [10, 21], [10, 39], [10, 44], [10, 45], [10, 53], [10, 56], [10, 67], [10, 73], [10, 74], [10, 84], [11, 13], [11, 18], [11, 20], [11, 26], [11, 27], [11, 35], [11, 40], [11, 49], [11, 50], [11, 54], [11, 55], [11, 58], [11, 59], [11, 62], [11, 66], [11, 71], [11, 72], [11, 77], [11, 81], [11, 84], [11, 85], [11, 89], [12, 17], [12, 18], [12, 22], [12, 23], [12, 27], [12, 28], [12, 33], [12, 39], [12, 41], [12, 42], [12, 44], [12, 47], [12, 55], [12, 58], [12, 59], [12, 63], [12, 64], [12, 66], [12, 70], [12, 75], [12, 82], [12, 85], [12, 86], [12, 88], [13, 14], [13, 18], [13, 22], [13, 23], [13, 25], [13, 26], [13, 28], [13, 34], [13, 40], [13, 49], [13, 51], [13, 53], [13, 57], [13, 59], [13, 60], [13, 61], [13, 62], [13, 63], [13, 64], [13, 66], [13, 67], [13, 71], [13, 72], [13, 73], [13, 78], [13, 81], [13, 83], [13, 84], [13, 87], [14, 25], [14, 29], [14, 31], [14, 34], [14, 37], [14, 44], [14, 47], [14, 51], [14, 52], [14, 58], [14, 63], [14, 65], [14, 68], [14, 72], [14, 74], [14, 76], [14, 88], [15, 21], [15, 27], [15, 28], [15, 44], [15, 46], [15, 47], [15, 50], [15, 51], [15, 52], [15, 56], [15, 60], [15, 65], [15, 66], [15, 69], [15, 76], [15, 77], [15, 79], [15, 85], [16, 17], [16, 18], [16, 21], [16, 22], [16, 24], [16, 27], [16, 32], [16, 33], [16, 42], [16, 48], [16, 49], [16, 50], [16, 56], [16, 58], [16, 59], [16, 60], [16, 61], [16, 66], [16, 70], [16, 71], [16, 72], [16, 74], [16, 81], [16, 82], [17, 22], [17, 23], [17, 28], [17, 30], [17, 31], [17, 35], [17, 36], [17, 38], [17, 39], [17, 40], [17, 45], [17, 50], [17, 62], [17, 65], [17, 66], [17, 67], [17, 69], [17, 75], [17, 76], [17, 79], [17, 80], [18, 25], [18, 30], [18, 31], [18, 33], [18, 36], [18, 37], [18, 38], [18, 45], [18, 51], [18, 60], [18, 62], [18, 65], [18, 72], [18, 76], [18, 78], [18, 81], [18, 84], [18, 85], [18, 86], [19, 21], [19, 23], [19, 25], [19, 28], [19, 29], [19, 34], [19, 35], [19, 43], [19, 44], [19, 46], [19, 47], [19, 50], [19, 53], [19, 60], [19, 66], [19, 68], [19, 73], [19, 74], [19, 75], [19, 77], [19, 78], [19, 81], [19, 82], [19, 89], [20, 22], [20, 23], [20, 24], [20, 27], [20, 29], [20, 30], [20, 32], [20, 34], [20, 36], [20, 50], [20, 52], [20, 59], [20, 60], [20, 64], [20, 67], [20, 68], [20, 70], [20, 80], [20, 81], [20, 89], [21, 22], [21, 34], [21, 35], [21, 44], [21, 45], [21, 47], [21, 49], [21, 50], [21, 52], [21, 55], [21, 58], [21, 59], [21, 60], [21, 62], [21, 71], [21, 72], [21, 74], [21, 76], [21, 79], [21, 82], [21, 83], [21, 84], [22, 29], [22, 30], [22, 32], [22, 35], [22, 36], [22, 42], [22, 47], [22, 52], [22, 58], [22, 61], [22, 68], [22, 72], [22, 88], [23, 25], [23, 32], [23, 34], [23, 35], [23, 36], [23, 39], [23, 41], [23, 43], [23, 51], [23, 57], [23, 59], [23, 62], [23, 66], [23, 76], [23, 80], [23, 83], [23, 86], [23, 87], [23, 89], [24, 28], [24, 38], [24, 42], [24, 46], [24, 57], [24, 61], [24, 63], [24, 64], [24, 72], [24, 75], [24, 79], [24, 87], [24, 88], [25, 28], [25, 30], [25, 31], [25, 33], [25, 36], [25, 39], [25, 40], [25, 46], [25, 47], [25, 53], [25, 57], [25, 61], [25, 65], [25, 70], [25, 71], [25, 72], [25, 73], [25, 74], [25, 76], [25, 78], [25, 84], [25, 87], [25, 89], [26, 29], [26, 30], [26, 32], [26, 37], [26, 46], [26, 48], [26, 50], [26, 52], [26, 53], [26, 58], [26, 62], [26, 65], [26, 66], [26, 70], [26, 79], [26, 81], [26, 82], [26, 83], [26, 86], [27, 29], [27, 31], [27, 32], [27, 34], [27, 38], [27, 44], [27, 45], [27, 56], [27, 58], [27, 63], [27, 67], [27, 70], [27, 71], [27, 75], [27, 81], [27, 82], [27, 84], [27, 87], [28, 32], [28, 41], [28, 44], [28, 45], [28, 47], [28, 48], [28, 50], [28, 51], [28, 60], [28, 62], [28, 63], [28, 70], [28, 73], [28, 74], [28, 76], [28, 77], [28, 78], [28, 82], [28, 83], [28, 86], [28, 88], [29, 30], [29, 33], [29, 34], [29, 38], [29, 40], [29, 41], [29, 43], [29, 45], [29, 50], [29, 51], [29, 54], [29, 55], [29, 56], [29, 62], [29, 68], [29, 69], [29, 70], [29, 75], [29, 80], [29, 88], [30, 31], [30, 33], [30, 37], [30, 38], [30, 40], [30, 41], [30, 45], [30, 48], [30, 52], [30, 54], [30, 56], [30, 63], [30, 66], [30, 67], [30, 72], [30, 74], [30, 75], [30, 85], [30, 87], [31, 32], [31, 33], [31, 44], [31, 47], [31, 49], [31, 50], [31, 60], [31, 64], [31, 70], [31, 71], [31, 72], [31, 77], [31, 78], [31, 80], [31, 85], [31, 86], [32, 34], [32, 38], [32, 45], [32, 47], [32, 50], [32, 51], [32, 52], [32, 58], [32, 63], [32, 66], [32, 88], [33, 34], [33, 35], [33, 36], [33, 39], [33, 46], [33, 50], [33, 52], [33, 53], [33, 56], [33, 59], [33, 60], [33, 63], [33, 64], [33, 65], [33, 66], [33, 72], [33, 73], [33, 81], [33, 84], [33, 87], [33, 88], [34, 37], [34, 43], [34, 44], [34, 46], [34, 48], [34, 51], [34, 54], [34, 57], [34, 59], [34, 65], [34, 68], [34, 70], [34, 71], [34, 72], [34, 73], [34, 74], [34, 79], [34, 80], [34, 83], [34, 84], [34, 85], [34, 89], [35, 40], [35, 41], [35, 42], [35, 43], [35, 44], [35, 45], [35, 47], [35, 51], [35, 53], [35, 54], [35, 57], [35, 58], [35, 59], [35, 61], [35, 63], [35, 66], [35, 70], [35, 76], [35, 77], [35, 80], [35, 86], [35, 87], [35, 88], [36, 39], [36, 44], [36, 60], [36, 62], [36, 67], [36, 73], [36, 78], [36, 79], [36, 80], [36, 82], [36, 85], [36, 87], [36, 88], [36, 89], [37, 40], [37, 47], [37, 49], [37, 52], [37, 53], [37, 57], [37, 58], [37, 60], [37, 62], [37, 65], [37, 67], [37, 69], [37, 71], [37, 72], [37, 73], [37, 75], [37, 79], [37, 81], [37, 82], [37, 83], [37, 86], [37, 87], [38, 39], [38, 40], [38, 41], [38, 42], [38, 47], [38, 50], [38, 60], [38, 68], [38, 69], [38, 71], [38, 72], [38, 73], [38, 74], [38, 78], [38, 81], [38, 82], [39, 40], [39, 41], [39, 42], [39, 44], [39, 50], [39, 56], [39, 60], [39, 64], [39, 66], [39, 67], [39, 69], [39, 78], [39, 84], [39, 85], [39, 87], [40, 41], [40, 44], [40, 48], [40, 50], [40, 53], [40, 54], [40, 62], [40, 63], [40, 64], [40, 66], [40, 70], [40, 71], [40, 76], [40, 83], [40, 86], [40, 87], [40, 88], [41, 46], [41, 48], [41, 49], [41, 51], [41, 55], [41, 75], [41, 80], [41, 84], [41, 87], [42, 47], [42, 49], [42, 50], [42, 52], [42, 54], [42, 55], [42, 56], [42, 58], [42, 59], [42, 61], [42, 64], [42, 66], [42, 69], [42, 71], [42, 72], [42, 75], [42, 77], [42, 78], [42, 80], [42, 83], [43, 48], [43, 49], [43, 52], [43, 54], [43, 55], [43, 66], [43, 69], [43, 70], [43, 71], [43, 73], [43, 75], [43, 76], [43, 78], [43, 80], [43, 81], [43, 85], [43, 86], [43, 88], [43, 89], [44, 46], [44, 50], [44, 56], [44, 59], [44, 67], [44, 70], [44, 77], [44, 79], [44, 81], [44, 82], [44, 85], [44, 88], [45, 50], [45, 51], [45, 52], [45, 54], [45, 61], [45, 62], [45, 63], [45, 69], [45, 70], [45, 73], [45, 76], [45, 77], [45, 78], [46, 49], [46, 54], [46, 55], [46, 56], [46, 58], [46, 62], [46, 71], [46, 73], [46, 78], [46, 85], [46, 86], [46, 88], [46, 89], [47, 59], [47, 60], [47, 61], [47, 63], [47, 68], [47, 72], [47, 73], [47, 74], [47, 79], [47, 82], [47, 84], [47, 89], [48, 49], [48, 51], [48, 54], [48, 61], [48, 65], [48, 70], [48, 72], [48, 75], [48, 77], [49, 50], [49, 52], [49, 55], [49, 56], [49, 60], [49, 62], [49, 66], [49, 67], [49, 72], [49, 75], [49, 76], [49, 77], [49, 79], [49, 83], [49, 84], [49, 86], [49, 88], [50, 65], [50, 68], [50, 71], [50, 75], [50, 80], [50, 83], [50, 85], [50, 87], [50, 88], [50, 89], [51, 53], [51, 54], [51, 58], [51, 61], [51, 68], [51, 69], [51, 71], [51, 72], [51, 75], [51, 76], [51, 78], [51, 79], [51, 80], [51, 81], [51, 83], [51, 86], [52, 54], [52, 56], [52, 58], [52, 60], [52, 64], [52, 66], [52, 69], [52, 72], [52, 74], [52, 81], [52, 84], [52, 85], [53, 66], [53, 68], [53, 69], [53, 74], [53, 78], [53, 80], [53, 82], [53, 84], [54, 58], [54, 61], [54, 62], [54, 63], [54, 64], [54, 66], [54, 70], [54, 71], [54, 72], [54, 73], [54, 78], [54, 80], [54, 81], [54, 82], [54, 83], [54, 85], [54, 86], [54, 87], [54, 88], [55, 56], [55, 57], [55, 58], [55, 61], [55, 62], [55, 63], [55, 64], [55, 66], [55, 70], [55, 73], [56, 70], [56, 72], [56, 74], [56, 78], [56, 82], [56, 84], [56, 85], [56, 86], [57, 59], [57, 64], [57, 67], [57, 69], [57, 70], [57, 72], [57, 73], [57, 74], [57, 75], [57, 76], [57, 77], [57, 83], [57, 88], [57, 89], [58, 60], [58, 63], [58, 65], [58, 69], [58, 71], [58, 73], [58, 79], [58, 81], [58, 84], [58, 85], [58, 86], [59, 73], [59, 82], [60, 61], [60, 62], [60, 64], [60, 66], [60, 68], [60, 69], [60, 74], [60, 78], [60, 82], [60, 88], [61, 63], [61, 64], [61, 67], [61, 73], [61, 74], [61, 80], [61, 82], [61, 84], [61, 87], [62, 71], [62, 74], [62, 75], [62, 76], [62, 77], [62, 83], [62, 86], [63, 74], [63, 77], [63, 80], [63, 82], [63, 83], [64, 65], [64, 67], [64, 73], [64, 76], [64, 77], [64, 82], [64, 83], [64, 89], [65, 67], [65, 71], [65, 75], [65, 77], [65, 82], [65, 83], [65, 87], [65, 89], [66, 68], [66, 71], [66, 75], [66, 76], [66, 77], [66, 82], [66, 83], [66, 86], [66, 89], [67, 73], [67, 76], [67, 85], [68, 76], [68, 79], [68, 86], [68, 89], [69, 71], [69, 74], [69, 78], [69, 80], [69, 82], [69, 84], [69, 86], [69, 88], [69, 89], [70, 73], [70, 77], [70, 79], [70, 85], [70, 88], [70, 89], [71, 75], [71, 78], [71, 80], [71, 81], [71, 88], [72, 81], [72, 84], [72, 85], [73, 75], [73, 79], [73, 81], [73, 85], [73, 87], [73, 89], [74, 81], [74, 82], [74, 84], [75, 85], [75, 86], [76, 77], [76, 78], [76, 79], [76, 88], [76, 89], [77, 78], [77, 85], [78, 80], [78, 83], [78, 86], [78, 87], [79, 83], [79, 85], [79, 86], [80, 84], [80, 89], [81, 83], [81, 84], [81, 85], [81, 86], [82, 87], [82, 88], [82, 89], [84, 85], [84, 86], [86, 88], [87, 89]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l5-s0/tests/run.py b/tasks/construct-mc-max-independent-set-l5-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l5-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-independent-set-l5-s0/tests/test.sh b/tasks/construct-mc-max-independent-set-l5-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l5-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-independent-set-l5-s7/environment/Dockerfile b/tasks/construct-mc-max-independent-set-l5-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l5-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-independent-set-l5-s7/environment/instance.json b/tasks/construct-mc-max-independent-set-l5-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..23219ad99970eb71e4978838fc7c158083a6fb01 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l5-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 90, "k": 16, "edges": [[0, 6], [0, 12], [0, 14], [0, 15], [0, 17], [0, 19], [0, 21], [0, 23], [0, 26], [0, 27], [0, 32], [0, 35], [0, 38], [0, 45], [0, 48], [0, 58], [0, 60], [0, 64], [0, 66], [0, 68], [0, 70], [0, 77], [0, 78], [0, 84], [0, 86], [0, 88], [0, 89], [1, 4], [1, 7], [1, 8], [1, 13], [1, 20], [1, 23], [1, 28], [1, 38], [1, 40], [1, 41], [1, 48], [1, 51], [1, 60], [1, 62], [1, 69], [1, 72], [1, 73], [1, 76], [1, 81], [1, 82], [1, 85], [1, 88], [2, 7], [2, 14], [2, 15], [2, 17], [2, 18], [2, 25], [2, 31], [2, 32], [2, 34], [2, 37], [2, 41], [2, 43], [2, 44], [2, 46], [2, 47], [2, 49], [2, 51], [2, 53], [2, 59], [2, 60], [2, 62], [2, 64], [2, 67], [2, 69], [2, 76], [2, 81], [2, 84], [2, 87], [3, 9], [3, 11], [3, 12], [3, 15], [3, 19], [3, 24], [3, 31], [3, 32], [3, 33], [3, 40], [3, 42], [3, 44], [3, 46], [3, 47], [3, 51], [3, 52], [3, 54], [3, 55], [3, 56], [3, 57], [3, 61], [3, 62], [3, 64], [3, 65], [3, 66], [3, 67], [3, 68], [3, 70], [3, 72], [3, 73], [3, 74], [3, 75], [3, 77], [3, 79], [3, 83], [4, 6], [4, 7], [4, 8], [4, 10], [4, 11], [4, 12], [4, 13], [4, 14], [4, 15], [4, 19], [4, 22], [4, 25], [4, 26], [4, 28], [4, 32], [4, 34], [4, 36], [4, 38], [4, 39], [4, 41], [4, 44], [4, 45], [4, 46], [4, 48], [4, 52], [4, 54], [4, 56], [4, 57], [4, 62], [4, 73], [4, 74], [4, 78], [4, 79], [4, 80], [4, 81], [4, 86], [4, 89], [5, 8], [5, 9], [5, 10], [5, 11], [5, 13], [5, 14], [5, 16], [5, 18], [5, 22], [5, 23], [5, 29], [5, 31], [5, 32], [5, 38], [5, 42], [5, 49], [5, 53], [5, 57], [5, 59], [5, 62], [5, 70], [5, 72], [5, 74], [5, 76], [5, 81], [5, 87], [5, 88], [5, 89], [6, 8], [6, 11], [6, 16], [6, 23], [6, 26], [6, 30], [6, 37], [6, 43], [6, 45], [6, 47], [6, 49], [6, 51], [6, 52], [6, 56], [6, 57], [6, 62], [6, 67], [6, 69], [6, 73], [6, 75], [6, 83], [6, 85], [7, 10], [7, 12], [7, 13], [7, 16], [7, 20], [7, 30], [7, 32], [7, 33], [7, 35], [7, 36], [7, 37], [7, 43], [7, 47], [7, 50], [7, 54], [7, 58], [7, 61], [7, 67], [7, 68], [7, 69], [7, 70], [7, 72], [7, 73], [7, 80], [7, 82], [7, 84], [8, 12], [8, 14], [8, 16], [8, 20], [8, 37], [8, 39], [8, 42], [8, 44], [8, 50], [8, 51], [8, 52], [8, 53], [8, 54], [8, 67], [8, 70], [8, 72], [8, 79], [8, 80], [8, 84], [8, 85], [8, 86], [9, 18], [9, 19], [9, 21], [9, 29], [9, 31], [9, 39], [9, 40], [9, 42], [9, 46], [9, 48], [9, 50], [9, 52], [9, 53], [9, 60], [9, 67], [9, 69], [9, 70], [9, 71], [9, 72], [9, 74], [9, 84], [9, 87], [9, 88], [10, 18], [10, 19], [10, 27], [10, 29], [10, 34], [10, 39], [10, 40], [10, 44], [10, 58], [10, 60], [10, 61], [10, 70], [10, 75], [10, 80], [10, 83], [10, 85], [10, 88], [11, 12], [11, 13], [11, 18], [11, 19], [11, 21], [11, 28], [11, 34], [11, 35], [11, 36], [11, 37], [11, 39], [11, 40], [11, 42], [11, 43], [11, 44], [11, 49], [11, 54], [11, 57], [11, 58], [11, 63], [11, 66], [11, 67], [11, 69], [11, 71], [11, 77], [11, 83], [11, 85], [11, 88], [12, 17], [12, 21], [12, 22], [12, 23], [12, 24], [12, 32], [12, 37], [12, 39], [12, 43], [12, 45], [12, 46], [12, 52], [12, 54], [12, 58], [12, 61], [12, 64], [12, 69], [12, 70], [12, 72], [12, 81], [12, 87], [13, 18], [13, 19], [13, 22], [13, 24], [13, 25], [13, 27], [13, 28], [13, 30], [13, 32], [13, 33], [13, 37], [13, 41], [13, 42], [13, 55], [13, 62], [13, 65], [13, 67], [13, 68], [13, 71], [13, 75], [13, 77], [13, 78], [13, 86], [13, 88], [13, 89], [14, 17], [14, 21], [14, 22], [14, 34], [14, 42], [14, 43], [14, 48], [14, 54], [14, 58], [14, 60], [14, 64], [14, 65], [14, 67], [14, 68], [14, 72], [14, 73], [14, 76], [14, 77], [14, 87], [14, 88], [15, 18], [15, 22], [15, 23], [15, 24], [15, 33], [15, 36], [15, 45], [15, 46], [15, 50], [15, 51], [15, 54], [15, 60], [15, 64], [15, 67], [15, 68], [15, 70], [15, 73], [15, 78], [15, 79], [15, 84], [16, 19], [16, 21], [16, 22], [16, 23], [16, 26], [16, 33], [16, 36], [16, 39], [16, 41], [16, 48], [16, 54], [16, 55], [16, 56], [16, 60], [16, 62], [16, 63], [16, 64], [16, 68], [16, 70], [16, 71], [16, 80], [16, 82], [16, 84], [16, 86], [16, 87], [17, 18], [17, 25], [17, 26], [17, 29], [17, 31], [17, 32], [17, 33], [17, 34], [17, 39], [17, 50], [17, 54], [17, 55], [17, 56], [17, 58], [17, 66], [17, 67], [17, 70], [17, 72], [17, 74], [17, 79], [17, 81], [17, 82], [17, 83], [18, 20], [18, 22], [18, 23], [18, 24], [18, 26], [18, 33], [18, 35], [18, 39], [18, 43], [18, 44], [18, 48], [18, 50], [18, 61], [18, 63], [18, 67], [18, 70], [18, 71], [18, 73], [18, 75], [18, 76], [18, 84], [19, 24], [19, 28], [19, 29], [19, 30], [19, 33], [19, 37], [19, 46], [19, 47], [19, 53], [19, 54], [19, 55], [19, 57], [19, 62], [19, 66], [19, 67], [19, 68], [19, 69], [19, 70], [19, 73], [19, 76], [19, 79], [19, 81], [19, 88], [20, 21], [20, 27], [20, 31], [20, 32], [20, 36], [20, 45], [20, 53], [20, 60], [20, 64], [20, 68], [20, 70], [20, 74], [20, 75], [20, 77], [20, 78], [20, 80], [20, 82], [20, 83], [20, 85], [20, 88], [21, 25], [21, 27], [21, 32], [21, 33], [21, 35], [21, 43], [21, 45], [21, 47], [21, 48], [21, 55], [21, 57], [21, 61], [21, 66], [21, 67], [21, 70], [21, 82], [21, 83], [21, 86], [21, 87], [21, 89], [22, 23], [22, 28], [22, 30], [22, 34], [22, 36], [22, 39], [22, 40], [22, 41], [22, 44], [22, 45], [22, 50], [22, 51], [22, 53], [22, 55], [22, 56], [22, 57], [22, 60], [22, 62], [22, 67], [22, 69], [22, 72], [22, 77], [22, 81], [22, 84], [22, 89], [23, 25], [23, 31], [23, 34], [23, 40], [23, 42], [23, 52], [23, 53], [23, 54], [23, 55], [23, 56], [23, 57], [23, 59], [23, 65], [23, 70], [23, 72], [23, 73], [23, 83], [23, 85], [23, 86], [23, 89], [24, 30], [24, 32], [24, 34], [24, 37], [24, 40], [24, 42], [24, 49], [24, 51], [24, 53], [24, 55], [24, 56], [24, 60], [24, 61], [24, 62], [24, 71], [24, 72], [24, 74], [24, 84], [24, 87], [25, 31], [25, 34], [25, 36], [25, 37], [25, 38], [25, 43], [25, 46], [25, 52], [25, 57], [25, 58], [25, 59], [25, 63], [25, 78], [25, 83], [25, 85], [25, 86], [25, 89], [26, 31], [26, 33], [26, 35], [26, 45], [26, 47], [26, 48], [26, 49], [26, 50], [26, 54], [26, 55], [26, 56], [26, 62], [26, 64], [26, 65], [26, 67], [26, 73], [26, 82], [26, 86], [26, 88], [27, 30], [27, 35], [27, 37], [27, 38], [27, 40], [27, 44], [27, 49], [27, 50], [27, 53], [27, 57], [27, 61], [27, 62], [27, 67], [27, 71], [27, 74], [27, 85], [27, 88], [27, 89], [28, 30], [28, 37], [28, 43], [28, 45], [28, 47], [28, 50], [28, 58], [28, 62], [28, 73], [28, 74], [28, 83], [28, 85], [29, 35], [29, 38], [29, 42], [29, 43], [29, 44], [29, 45], [29, 46], [29, 57], [29, 58], [29, 63], [29, 66], [29, 68], [29, 70], [29, 73], [29, 78], [29, 85], [29, 88], [29, 89], [30, 39], [30, 41], [30, 42], [30, 46], [30, 49], [30, 52], [30, 56], [30, 61], [30, 65], [30, 66], [30, 67], [30, 68], [30, 69], [30, 71], [30, 76], [30, 89], [31, 32], [31, 33], [31, 34], [31, 38], [31, 41], [31, 47], [31, 53], [31, 57], [31, 61], [31, 62], [31, 63], [31, 66], [31, 68], [31, 69], [31, 71], [31, 72], [31, 74], [31, 75], [31, 79], [31, 82], [31, 87], [31, 88], [32, 47], [32, 52], [32, 56], [32, 64], [32, 79], [33, 39], [33, 42], [33, 43], [33, 47], [33, 51], [33, 53], [33, 56], [33, 59], [33, 65], [33, 70], [33, 71], [33, 73], [33, 75], [33, 81], [33, 82], [34, 35], [34, 38], [34, 40], [34, 41], [34, 49], [34, 50], [34, 54], [34, 66], [34, 70], [34, 73], [34, 74], [34, 76], [34, 85], [34, 86], [35, 37], [35, 51], [35, 53], [35, 56], [35, 57], [35, 59], [35, 62], [35, 63], [35, 65], [35, 72], [35, 78], [35, 84], [35, 85], [35, 88], [36, 37], [36, 40], [36, 41], [36, 43], [36, 44], [36, 53], [36, 56], [36, 57], [36, 63], [36, 74], [36, 78], [36, 80], [36, 83], [37, 45], [37, 47], [37, 49], [37, 50], [37, 59], [37, 60], [37, 64], [37, 65], [37, 67], [37, 71], [37, 83], [37, 84], [37, 87], [37, 88], [37, 89], [38, 40], [38, 45], [38, 48], [38, 54], [38, 57], [38, 58], [38, 59], [38, 69], [38, 72], [38, 77], [38, 81], [38, 82], [38, 83], [38, 86], [39, 41], [39, 42], [39, 51], [39, 61], [39, 70], [39, 83], [39, 84], [39, 85], [39, 86], [39, 88], [40, 41], [40, 43], [40, 50], [40, 53], [40, 57], [40, 58], [40, 60], [40, 61], [40, 63], [40, 70], [40, 79], [40, 80], [41, 44], [41, 46], [41, 48], [41, 49], [41, 52], [41, 57], [41, 58], [41, 63], [41, 64], [41, 67], [41, 70], [41, 73], [41, 74], [41, 76], [41, 78], [41, 79], [41, 80], [41, 81], [41, 82], [41, 86], [42, 43], [42, 47], [42, 48], [42, 52], [42, 54], [42, 56], [42, 61], [42, 63], [42, 64], [42, 68], [42, 71], [42, 75], [42, 84], [42, 89], [43, 45], [43, 49], [43, 50], [43, 52], [43, 55], [43, 59], [43, 62], [43, 64], [43, 68], [43, 71], [43, 79], [43, 82], [43, 85], [44, 45], [44, 52], [44, 54], [44, 60], [44, 67], [44, 68], [44, 69], [44, 71], [44, 72], [44, 75], [44, 77], [44, 78], [44, 82], [44, 86], [45, 51], [45, 54], [45, 59], [45, 62], [45, 69], [45, 72], [45, 73], [45, 78], [45, 80], [45, 82], [45, 87], [46, 47], [46, 48], [46, 54], [46, 60], [46, 65], [46, 69], [46, 70], [46, 71], [46, 72], [46, 73], [46, 76], [46, 82], [46, 89], [47, 48], [47, 49], [47, 56], [47, 58], [47, 61], [47, 67], [47, 70], [47, 78], [47, 79], [47, 81], [47, 82], [47, 84], [47, 87], [47, 88], [47, 89], [48, 56], [48, 59], [48, 65], [48, 69], [48, 71], [48, 83], [48, 87], [48, 88], [48, 89], [49, 55], [49, 57], [49, 58], [49, 59], [49, 61], [49, 65], [49, 74], [49, 83], [49, 84], [49, 85], [50, 58], [50, 60], [50, 68], [50, 75], [50, 77], [50, 79], [50, 84], [51, 56], [51, 64], [51, 68], [51, 69], [51, 71], [51, 73], [51, 77], [51, 79], [51, 80], [51, 85], [52, 58], [52, 59], [52, 65], [52, 73], [52, 74], [52, 76], [52, 77], [52, 78], [52, 82], [52, 83], [52, 84], [52, 88], [53, 55], [53, 58], [53, 64], [53, 65], [53, 67], [53, 68], [53, 72], [53, 73], [53, 75], [53, 76], [53, 77], [53, 78], [53, 79], [53, 80], [53, 81], [53, 84], [53, 87], [53, 89], [54, 60], [54, 62], [54, 63], [54, 68], [54, 75], [54, 78], [54, 79], [54, 84], [55, 57], [55, 62], [55, 64], [55, 73], [55, 74], [55, 80], [55, 83], [55, 84], [56, 58], [56, 65], [56, 67], [56, 72], [56, 86], [56, 89], [57, 58], [57, 62], [57, 63], [57, 65], [57, 68], [57, 72], [57, 73], [57, 74], [57, 75], [57, 79], [57, 80], [57, 86], [57, 89], [58, 59], [58, 60], [58, 69], [58, 74], [58, 75], [58, 79], [58, 89], [59, 64], [59, 66], [59, 67], [59, 69], [59, 79], [59, 80], [59, 86], [60, 76], [60, 77], [60, 79], [60, 80], [60, 81], [60, 82], [61, 63], [61, 65], [61, 66], [61, 72], [61, 73], [61, 80], [61, 81], [61, 82], [61, 86], [61, 87], [62, 63], [62, 69], [62, 70], [62, 73], [62, 85], [62, 88], [62, 89], [63, 72], [63, 76], [63, 79], [63, 80], [63, 82], [64, 66], [64, 70], [64, 77], [64, 80], [64, 86], [65, 67], [65, 85], [65, 86], [65, 89], [66, 67], [66, 69], [66, 73], [66, 75], [66, 83], [66, 84], [66, 86], [67, 68], [67, 72], [67, 73], [67, 84], [68, 70], [68, 73], [68, 75], [68, 76], [68, 78], [68, 86], [68, 89], [69, 73], [69, 76], [69, 79], [69, 87], [70, 75], [70, 79], [70, 83], [71, 75], [71, 80], [71, 86], [72, 78], [72, 80], [73, 76], [73, 79], [73, 81], [73, 85], [73, 86], [73, 89], [74, 75], [74, 77], [74, 85], [74, 86], [74, 87], [74, 88], [75, 86], [75, 89], [76, 77], [76, 82], [76, 87], [77, 78], [77, 83], [78, 86], [78, 88], [81, 86], [81, 89], [82, 84], [82, 85], [83, 86], [85, 88], [85, 89], [86, 88], [86, 89]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l5-s7/solution/solve.sh b/tasks/construct-mc-max-independent-set-l5-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ee249b64f8c5db0508bc4a7fc1a873ed236efeb1 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l5-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"independent_set": [6, 18, 28, 32, 34, 36, 55, 59, 65, 68, 72, 77, 81, 82, 87, 88]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-independent-set-l5-s7/tests/check.py b/tasks/construct-mc-max-independent-set-l5-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..adce413e8578d996549583b990e4ff559f38ed41 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l5-s7/tests/check.py @@ -0,0 +1,18 @@ +"""Independent set of size >= k in a given graph (MathConstraint max_independent_set, CC-BY-4.0).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("independent_set"), None, 0, n - 1, "independent_set") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) < k: + raise Invalid(f"set has {len(S)} vertices, need at least {k}") + E = {(u, v) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(S), 2): + if (u, v) in E: + raise Invalid(f"vertices {u} and {v} are adjacent") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-max-independent-set-l5-s7/tests/instance.json b/tasks/construct-mc-max-independent-set-l5-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..23219ad99970eb71e4978838fc7c158083a6fb01 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l5-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 90, "k": 16, "edges": [[0, 6], [0, 12], [0, 14], [0, 15], [0, 17], [0, 19], [0, 21], [0, 23], [0, 26], [0, 27], [0, 32], [0, 35], [0, 38], [0, 45], [0, 48], [0, 58], [0, 60], [0, 64], [0, 66], [0, 68], [0, 70], [0, 77], [0, 78], [0, 84], [0, 86], [0, 88], [0, 89], [1, 4], [1, 7], [1, 8], [1, 13], [1, 20], [1, 23], [1, 28], [1, 38], [1, 40], [1, 41], [1, 48], [1, 51], [1, 60], [1, 62], [1, 69], [1, 72], [1, 73], [1, 76], [1, 81], [1, 82], [1, 85], [1, 88], [2, 7], [2, 14], [2, 15], [2, 17], [2, 18], [2, 25], [2, 31], [2, 32], [2, 34], [2, 37], [2, 41], [2, 43], [2, 44], [2, 46], [2, 47], [2, 49], [2, 51], [2, 53], [2, 59], [2, 60], [2, 62], [2, 64], [2, 67], [2, 69], [2, 76], [2, 81], [2, 84], [2, 87], [3, 9], [3, 11], [3, 12], [3, 15], [3, 19], [3, 24], [3, 31], [3, 32], [3, 33], [3, 40], [3, 42], [3, 44], [3, 46], [3, 47], [3, 51], [3, 52], [3, 54], [3, 55], [3, 56], [3, 57], [3, 61], [3, 62], [3, 64], [3, 65], [3, 66], [3, 67], [3, 68], [3, 70], [3, 72], [3, 73], [3, 74], [3, 75], [3, 77], [3, 79], [3, 83], [4, 6], [4, 7], [4, 8], [4, 10], [4, 11], [4, 12], [4, 13], [4, 14], [4, 15], [4, 19], [4, 22], [4, 25], [4, 26], [4, 28], [4, 32], [4, 34], [4, 36], [4, 38], [4, 39], [4, 41], [4, 44], [4, 45], [4, 46], [4, 48], [4, 52], [4, 54], [4, 56], [4, 57], [4, 62], [4, 73], [4, 74], [4, 78], [4, 79], [4, 80], [4, 81], [4, 86], [4, 89], [5, 8], [5, 9], [5, 10], [5, 11], [5, 13], [5, 14], [5, 16], [5, 18], [5, 22], [5, 23], [5, 29], [5, 31], [5, 32], [5, 38], [5, 42], [5, 49], [5, 53], [5, 57], [5, 59], [5, 62], [5, 70], [5, 72], [5, 74], [5, 76], [5, 81], [5, 87], [5, 88], [5, 89], [6, 8], [6, 11], [6, 16], [6, 23], [6, 26], [6, 30], [6, 37], [6, 43], [6, 45], [6, 47], [6, 49], [6, 51], [6, 52], [6, 56], [6, 57], [6, 62], [6, 67], [6, 69], [6, 73], [6, 75], [6, 83], [6, 85], [7, 10], [7, 12], [7, 13], [7, 16], [7, 20], [7, 30], [7, 32], [7, 33], [7, 35], [7, 36], [7, 37], [7, 43], [7, 47], [7, 50], [7, 54], [7, 58], [7, 61], [7, 67], [7, 68], [7, 69], [7, 70], [7, 72], [7, 73], [7, 80], [7, 82], [7, 84], [8, 12], [8, 14], [8, 16], [8, 20], [8, 37], [8, 39], [8, 42], [8, 44], [8, 50], [8, 51], [8, 52], [8, 53], [8, 54], [8, 67], [8, 70], [8, 72], [8, 79], [8, 80], [8, 84], [8, 85], [8, 86], [9, 18], [9, 19], [9, 21], [9, 29], [9, 31], [9, 39], [9, 40], [9, 42], [9, 46], [9, 48], [9, 50], [9, 52], [9, 53], [9, 60], [9, 67], [9, 69], [9, 70], [9, 71], [9, 72], [9, 74], [9, 84], [9, 87], [9, 88], [10, 18], [10, 19], [10, 27], [10, 29], [10, 34], [10, 39], [10, 40], [10, 44], [10, 58], [10, 60], [10, 61], [10, 70], [10, 75], [10, 80], [10, 83], [10, 85], [10, 88], [11, 12], [11, 13], [11, 18], [11, 19], [11, 21], [11, 28], [11, 34], [11, 35], [11, 36], [11, 37], [11, 39], [11, 40], [11, 42], [11, 43], [11, 44], [11, 49], [11, 54], [11, 57], [11, 58], [11, 63], [11, 66], [11, 67], [11, 69], [11, 71], [11, 77], [11, 83], [11, 85], [11, 88], [12, 17], [12, 21], [12, 22], [12, 23], [12, 24], [12, 32], [12, 37], [12, 39], [12, 43], [12, 45], [12, 46], [12, 52], [12, 54], [12, 58], [12, 61], [12, 64], [12, 69], [12, 70], [12, 72], [12, 81], [12, 87], [13, 18], [13, 19], [13, 22], [13, 24], [13, 25], [13, 27], [13, 28], [13, 30], [13, 32], [13, 33], [13, 37], [13, 41], [13, 42], [13, 55], [13, 62], [13, 65], [13, 67], [13, 68], [13, 71], [13, 75], [13, 77], [13, 78], [13, 86], [13, 88], [13, 89], [14, 17], [14, 21], [14, 22], [14, 34], [14, 42], [14, 43], [14, 48], [14, 54], [14, 58], [14, 60], [14, 64], [14, 65], [14, 67], [14, 68], [14, 72], [14, 73], [14, 76], [14, 77], [14, 87], [14, 88], [15, 18], [15, 22], [15, 23], [15, 24], [15, 33], [15, 36], [15, 45], [15, 46], [15, 50], [15, 51], [15, 54], [15, 60], [15, 64], [15, 67], [15, 68], [15, 70], [15, 73], [15, 78], [15, 79], [15, 84], [16, 19], [16, 21], [16, 22], [16, 23], [16, 26], [16, 33], [16, 36], [16, 39], [16, 41], [16, 48], [16, 54], [16, 55], [16, 56], [16, 60], [16, 62], [16, 63], [16, 64], [16, 68], [16, 70], [16, 71], [16, 80], [16, 82], [16, 84], [16, 86], [16, 87], [17, 18], [17, 25], [17, 26], [17, 29], [17, 31], [17, 32], [17, 33], [17, 34], [17, 39], [17, 50], [17, 54], [17, 55], [17, 56], [17, 58], [17, 66], [17, 67], [17, 70], [17, 72], [17, 74], [17, 79], [17, 81], [17, 82], [17, 83], [18, 20], [18, 22], [18, 23], [18, 24], [18, 26], [18, 33], [18, 35], [18, 39], [18, 43], [18, 44], [18, 48], [18, 50], [18, 61], [18, 63], [18, 67], [18, 70], [18, 71], [18, 73], [18, 75], [18, 76], [18, 84], [19, 24], [19, 28], [19, 29], [19, 30], [19, 33], [19, 37], [19, 46], [19, 47], [19, 53], [19, 54], [19, 55], [19, 57], [19, 62], [19, 66], [19, 67], [19, 68], [19, 69], [19, 70], [19, 73], [19, 76], [19, 79], [19, 81], [19, 88], [20, 21], [20, 27], [20, 31], [20, 32], [20, 36], [20, 45], [20, 53], [20, 60], [20, 64], [20, 68], [20, 70], [20, 74], [20, 75], [20, 77], [20, 78], [20, 80], [20, 82], [20, 83], [20, 85], [20, 88], [21, 25], [21, 27], [21, 32], [21, 33], [21, 35], [21, 43], [21, 45], [21, 47], [21, 48], [21, 55], [21, 57], [21, 61], [21, 66], [21, 67], [21, 70], [21, 82], [21, 83], [21, 86], [21, 87], [21, 89], [22, 23], [22, 28], [22, 30], [22, 34], [22, 36], [22, 39], [22, 40], [22, 41], [22, 44], [22, 45], [22, 50], [22, 51], [22, 53], [22, 55], [22, 56], [22, 57], [22, 60], [22, 62], [22, 67], [22, 69], [22, 72], [22, 77], [22, 81], [22, 84], [22, 89], [23, 25], [23, 31], [23, 34], [23, 40], [23, 42], [23, 52], [23, 53], [23, 54], [23, 55], [23, 56], [23, 57], [23, 59], [23, 65], [23, 70], [23, 72], [23, 73], [23, 83], [23, 85], [23, 86], [23, 89], [24, 30], [24, 32], [24, 34], [24, 37], [24, 40], [24, 42], [24, 49], [24, 51], [24, 53], [24, 55], [24, 56], [24, 60], [24, 61], [24, 62], [24, 71], [24, 72], [24, 74], [24, 84], [24, 87], [25, 31], [25, 34], [25, 36], [25, 37], [25, 38], [25, 43], [25, 46], [25, 52], [25, 57], [25, 58], [25, 59], [25, 63], [25, 78], [25, 83], [25, 85], [25, 86], [25, 89], [26, 31], [26, 33], [26, 35], [26, 45], [26, 47], [26, 48], [26, 49], [26, 50], [26, 54], [26, 55], [26, 56], [26, 62], [26, 64], [26, 65], [26, 67], [26, 73], [26, 82], [26, 86], [26, 88], [27, 30], [27, 35], [27, 37], [27, 38], [27, 40], [27, 44], [27, 49], [27, 50], [27, 53], [27, 57], [27, 61], [27, 62], [27, 67], [27, 71], [27, 74], [27, 85], [27, 88], [27, 89], [28, 30], [28, 37], [28, 43], [28, 45], [28, 47], [28, 50], [28, 58], [28, 62], [28, 73], [28, 74], [28, 83], [28, 85], [29, 35], [29, 38], [29, 42], [29, 43], [29, 44], [29, 45], [29, 46], [29, 57], [29, 58], [29, 63], [29, 66], [29, 68], [29, 70], [29, 73], [29, 78], [29, 85], [29, 88], [29, 89], [30, 39], [30, 41], [30, 42], [30, 46], [30, 49], [30, 52], [30, 56], [30, 61], [30, 65], [30, 66], [30, 67], [30, 68], [30, 69], [30, 71], [30, 76], [30, 89], [31, 32], [31, 33], [31, 34], [31, 38], [31, 41], [31, 47], [31, 53], [31, 57], [31, 61], [31, 62], [31, 63], [31, 66], [31, 68], [31, 69], [31, 71], [31, 72], [31, 74], [31, 75], [31, 79], [31, 82], [31, 87], [31, 88], [32, 47], [32, 52], [32, 56], [32, 64], [32, 79], [33, 39], [33, 42], [33, 43], [33, 47], [33, 51], [33, 53], [33, 56], [33, 59], [33, 65], [33, 70], [33, 71], [33, 73], [33, 75], [33, 81], [33, 82], [34, 35], [34, 38], [34, 40], [34, 41], [34, 49], [34, 50], [34, 54], [34, 66], [34, 70], [34, 73], [34, 74], [34, 76], [34, 85], [34, 86], [35, 37], [35, 51], [35, 53], [35, 56], [35, 57], [35, 59], [35, 62], [35, 63], [35, 65], [35, 72], [35, 78], [35, 84], [35, 85], [35, 88], [36, 37], [36, 40], [36, 41], [36, 43], [36, 44], [36, 53], [36, 56], [36, 57], [36, 63], [36, 74], [36, 78], [36, 80], [36, 83], [37, 45], [37, 47], [37, 49], [37, 50], [37, 59], [37, 60], [37, 64], [37, 65], [37, 67], [37, 71], [37, 83], [37, 84], [37, 87], [37, 88], [37, 89], [38, 40], [38, 45], [38, 48], [38, 54], [38, 57], [38, 58], [38, 59], [38, 69], [38, 72], [38, 77], [38, 81], [38, 82], [38, 83], [38, 86], [39, 41], [39, 42], [39, 51], [39, 61], [39, 70], [39, 83], [39, 84], [39, 85], [39, 86], [39, 88], [40, 41], [40, 43], [40, 50], [40, 53], [40, 57], [40, 58], [40, 60], [40, 61], [40, 63], [40, 70], [40, 79], [40, 80], [41, 44], [41, 46], [41, 48], [41, 49], [41, 52], [41, 57], [41, 58], [41, 63], [41, 64], [41, 67], [41, 70], [41, 73], [41, 74], [41, 76], [41, 78], [41, 79], [41, 80], [41, 81], [41, 82], [41, 86], [42, 43], [42, 47], [42, 48], [42, 52], [42, 54], [42, 56], [42, 61], [42, 63], [42, 64], [42, 68], [42, 71], [42, 75], [42, 84], [42, 89], [43, 45], [43, 49], [43, 50], [43, 52], [43, 55], [43, 59], [43, 62], [43, 64], [43, 68], [43, 71], [43, 79], [43, 82], [43, 85], [44, 45], [44, 52], [44, 54], [44, 60], [44, 67], [44, 68], [44, 69], [44, 71], [44, 72], [44, 75], [44, 77], [44, 78], [44, 82], [44, 86], [45, 51], [45, 54], [45, 59], [45, 62], [45, 69], [45, 72], [45, 73], [45, 78], [45, 80], [45, 82], [45, 87], [46, 47], [46, 48], [46, 54], [46, 60], [46, 65], [46, 69], [46, 70], [46, 71], [46, 72], [46, 73], [46, 76], [46, 82], [46, 89], [47, 48], [47, 49], [47, 56], [47, 58], [47, 61], [47, 67], [47, 70], [47, 78], [47, 79], [47, 81], [47, 82], [47, 84], [47, 87], [47, 88], [47, 89], [48, 56], [48, 59], [48, 65], [48, 69], [48, 71], [48, 83], [48, 87], [48, 88], [48, 89], [49, 55], [49, 57], [49, 58], [49, 59], [49, 61], [49, 65], [49, 74], [49, 83], [49, 84], [49, 85], [50, 58], [50, 60], [50, 68], [50, 75], [50, 77], [50, 79], [50, 84], [51, 56], [51, 64], [51, 68], [51, 69], [51, 71], [51, 73], [51, 77], [51, 79], [51, 80], [51, 85], [52, 58], [52, 59], [52, 65], [52, 73], [52, 74], [52, 76], [52, 77], [52, 78], [52, 82], [52, 83], [52, 84], [52, 88], [53, 55], [53, 58], [53, 64], [53, 65], [53, 67], [53, 68], [53, 72], [53, 73], [53, 75], [53, 76], [53, 77], [53, 78], [53, 79], [53, 80], [53, 81], [53, 84], [53, 87], [53, 89], [54, 60], [54, 62], [54, 63], [54, 68], [54, 75], [54, 78], [54, 79], [54, 84], [55, 57], [55, 62], [55, 64], [55, 73], [55, 74], [55, 80], [55, 83], [55, 84], [56, 58], [56, 65], [56, 67], [56, 72], [56, 86], [56, 89], [57, 58], [57, 62], [57, 63], [57, 65], [57, 68], [57, 72], [57, 73], [57, 74], [57, 75], [57, 79], [57, 80], [57, 86], [57, 89], [58, 59], [58, 60], [58, 69], [58, 74], [58, 75], [58, 79], [58, 89], [59, 64], [59, 66], [59, 67], [59, 69], [59, 79], [59, 80], [59, 86], [60, 76], [60, 77], [60, 79], [60, 80], [60, 81], [60, 82], [61, 63], [61, 65], [61, 66], [61, 72], [61, 73], [61, 80], [61, 81], [61, 82], [61, 86], [61, 87], [62, 63], [62, 69], [62, 70], [62, 73], [62, 85], [62, 88], [62, 89], [63, 72], [63, 76], [63, 79], [63, 80], [63, 82], [64, 66], [64, 70], [64, 77], [64, 80], [64, 86], [65, 67], [65, 85], [65, 86], [65, 89], [66, 67], [66, 69], [66, 73], [66, 75], [66, 83], [66, 84], [66, 86], [67, 68], [67, 72], [67, 73], [67, 84], [68, 70], [68, 73], [68, 75], [68, 76], [68, 78], [68, 86], [68, 89], [69, 73], [69, 76], [69, 79], [69, 87], [70, 75], [70, 79], [70, 83], [71, 75], [71, 80], [71, 86], [72, 78], [72, 80], [73, 76], [73, 79], [73, 81], [73, 85], [73, 86], [73, 89], [74, 75], [74, 77], [74, 85], [74, 86], [74, 87], [74, 88], [75, 86], [75, 89], [76, 77], [76, 82], [76, 87], [77, 78], [77, 83], [78, 86], [78, 88], [81, 86], [81, 89], [82, 84], [82, 85], [83, 86], [85, 88], [85, 89], [86, 88], [86, 89]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l5-s7/tests/run.py b/tasks/construct-mc-max-independent-set-l5-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l5-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-independent-set-l5-s7/tests/test.sh b/tasks/construct-mc-max-independent-set-l5-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l5-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-independent-set-l5-s9/environment/Dockerfile b/tasks/construct-mc-max-independent-set-l5-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l5-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-independent-set-l5-s9/environment/instance.json b/tasks/construct-mc-max-independent-set-l5-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..97c022068f1ebefb650e3979717849f9a8d6797e --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l5-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 90, "k": 16, "edges": [[0, 6], [0, 9], [0, 19], [0, 22], [0, 26], [0, 27], [0, 29], [0, 30], [0, 33], [0, 41], [0, 45], [0, 53], [0, 55], [0, 57], [0, 65], [0, 67], [0, 70], [0, 77], [0, 80], [0, 83], [0, 84], [0, 89], [1, 7], [1, 12], [1, 15], [1, 17], [1, 18], [1, 19], [1, 23], [1, 25], [1, 27], [1, 32], [1, 33], [1, 34], [1, 43], [1, 45], [1, 46], [1, 51], [1, 54], [1, 56], [1, 57], [1, 58], [1, 59], [1, 61], [1, 65], [1, 67], [1, 68], [1, 69], [1, 74], [1, 81], [1, 84], [1, 87], [2, 6], [2, 7], [2, 8], [2, 9], [2, 13], [2, 15], [2, 17], [2, 19], [2, 22], [2, 23], [2, 24], [2, 29], [2, 30], [2, 33], [2, 37], [2, 44], [2, 47], [2, 50], [2, 54], [2, 59], [2, 64], [2, 65], [2, 75], [2, 88], [3, 5], [3, 10], [3, 13], [3, 17], [3, 18], [3, 20], [3, 25], [3, 32], [3, 41], [3, 42], [3, 43], [3, 47], [3, 49], [3, 51], [3, 59], [3, 66], [3, 75], [3, 80], [3, 86], [4, 7], [4, 8], [4, 11], [4, 16], [4, 17], [4, 18], [4, 25], [4, 34], [4, 39], [4, 41], [4, 46], [4, 52], [4, 53], [4, 60], [4, 68], [4, 69], [4, 70], [4, 76], [4, 77], [4, 78], [4, 79], [4, 82], [4, 85], [5, 6], [5, 7], [5, 10], [5, 14], [5, 19], [5, 25], [5, 32], [5, 33], [5, 45], [5, 47], [5, 52], [5, 53], [5, 57], [5, 60], [5, 62], [5, 67], [5, 72], [5, 73], [5, 74], [5, 75], [5, 77], [5, 78], [5, 79], [5, 85], [6, 9], [6, 16], [6, 20], [6, 25], [6, 26], [6, 27], [6, 29], [6, 30], [6, 35], [6, 38], [6, 42], [6, 45], [6, 47], [6, 52], [6, 54], [6, 57], [6, 59], [6, 60], [6, 61], [6, 66], [6, 68], [6, 69], [6, 71], [6, 74], [6, 78], [6, 80], [6, 81], [6, 83], [6, 86], [7, 11], [7, 12], [7, 21], [7, 31], [7, 34], [7, 36], [7, 37], [7, 38], [7, 40], [7, 48], [7, 49], [7, 50], [7, 52], [7, 53], [7, 57], [7, 58], [7, 63], [7, 67], [7, 72], [7, 75], [7, 76], [7, 78], [7, 81], [7, 82], [7, 84], [7, 85], [7, 89], [8, 9], [8, 15], [8, 16], [8, 17], [8, 19], [8, 28], [8, 29], [8, 33], [8, 34], [8, 49], [8, 55], [8, 58], [8, 60], [8, 62], [8, 64], [8, 65], [8, 69], [8, 72], [8, 82], [8, 87], [8, 89], [9, 13], [9, 16], [9, 17], [9, 18], [9, 20], [9, 23], [9, 26], [9, 27], [9, 29], [9, 34], [9, 38], [9, 51], [9, 53], [9, 54], [9, 56], [9, 60], [9, 68], [9, 77], [9, 78], [9, 84], [9, 85], [9, 89], [10, 11], [10, 14], [10, 18], [10, 22], [10, 23], [10, 27], [10, 30], [10, 31], [10, 33], [10, 40], [10, 42], [10, 43], [10, 45], [10, 46], [10, 47], [10, 48], [10, 49], [10, 50], [10, 55], [10, 58], [10, 59], [10, 60], [10, 61], [10, 68], [10, 69], [10, 70], [10, 78], [10, 80], [10, 84], [10, 85], [10, 86], [10, 87], [10, 89], [11, 21], [11, 22], [11, 24], [11, 29], [11, 42], [11, 43], [11, 44], [11, 45], [11, 48], [11, 60], [11, 69], [11, 70], [11, 72], [11, 74], [11, 75], [11, 76], [11, 79], [11, 81], [11, 82], [11, 84], [11, 85], [11, 87], [12, 13], [12, 14], [12, 19], [12, 21], [12, 26], [12, 29], [12, 34], [12, 36], [12, 39], [12, 40], [12, 43], [12, 45], [12, 47], [12, 49], [12, 54], [12, 65], [12, 68], [12, 71], [12, 72], [12, 73], [12, 75], [12, 79], [12, 84], [12, 86], [13, 16], [13, 17], [13, 19], [13, 24], [13, 25], [13, 27], [13, 30], [13, 35], [13, 41], [13, 42], [13, 45], [13, 59], [13, 62], [13, 63], [13, 66], [13, 69], [13, 70], [13, 73], [13, 74], [13, 79], [13, 85], [13, 87], [13, 89], [14, 18], [14, 23], [14, 28], [14, 33], [14, 39], [14, 48], [14, 49], [14, 51], [14, 56], [14, 59], [14, 66], [14, 67], [14, 68], [14, 69], [14, 72], [14, 77], [14, 80], [14, 81], [14, 84], [14, 85], [14, 86], [15, 17], [15, 19], [15, 24], [15, 25], [15, 28], [15, 32], [15, 38], [15, 44], [15, 45], [15, 63], [15, 70], [15, 73], [15, 79], [15, 80], [15, 82], [15, 84], [15, 87], [15, 88], [16, 20], [16, 23], [16, 25], [16, 27], [16, 28], [16, 29], [16, 31], [16, 32], [16, 36], [16, 38], [16, 39], [16, 41], [16, 45], [16, 47], [16, 48], [16, 53], [16, 60], [16, 65], [16, 70], [16, 72], [16, 77], [16, 79], [16, 89], [17, 21], [17, 26], [17, 28], [17, 30], [17, 32], [17, 33], [17, 34], [17, 35], [17, 36], [17, 37], [17, 38], [17, 39], [17, 48], [17, 49], [17, 50], [17, 56], [17, 60], [17, 61], [17, 63], [17, 64], [17, 65], [17, 66], [17, 67], [17, 68], [17, 69], [17, 78], [17, 82], [17, 83], [17, 87], [17, 89], [18, 21], [18, 24], [18, 29], [18, 31], [18, 35], [18, 43], [18, 46], [18, 56], [18, 62], [18, 64], [18, 69], [18, 71], [18, 78], [18, 79], [18, 80], [18, 83], [18, 86], [19, 27], [19, 34], [19, 38], [19, 45], [19, 48], [19, 53], [19, 55], [19, 58], [19, 59], [19, 63], [19, 64], [19, 68], [19, 69], [19, 74], [19, 75], [19, 79], [19, 89], [20, 21], [20, 23], [20, 26], [20, 29], [20, 38], [20, 41], [20, 44], [20, 50], [20, 52], [20, 54], [20, 55], [20, 62], [20, 63], [20, 65], [20, 66], [20, 69], [20, 70], [20, 76], [20, 80], [20, 81], [20, 85], [20, 87], [20, 89], [21, 25], [21, 26], [21, 28], [21, 32], [21, 33], [21, 35], [21, 38], [21, 39], [21, 40], [21, 43], [21, 44], [21, 47], [21, 48], [21, 49], [21, 50], [21, 54], [21, 55], [21, 60], [21, 66], [21, 70], [21, 75], [21, 76], [21, 77], [21, 78], [21, 81], [21, 83], [21, 84], [21, 85], [21, 88], [22, 25], [22, 33], [22, 35], [22, 40], [22, 44], [22, 45], [22, 47], [22, 48], [22, 49], [22, 50], [22, 52], [22, 54], [22, 55], [22, 60], [22, 64], [22, 68], [22, 70], [22, 74], [22, 75], [22, 76], [22, 77], [22, 86], [22, 88], [23, 27], [23, 28], [23, 36], [23, 41], [23, 44], [23, 53], [23, 54], [23, 56], [23, 58], [23, 59], [23, 60], [23, 63], [23, 65], [23, 67], [23, 68], [23, 78], [23, 82], [24, 34], [24, 39], [24, 44], [24, 46], [24, 48], [24, 51], [24, 52], [24, 55], [24, 58], [24, 60], [24, 61], [24, 65], [24, 72], [24, 73], [24, 77], [24, 79], [24, 80], [24, 85], [25, 26], [25, 27], [25, 28], [25, 30], [25, 31], [25, 32], [25, 36], [25, 37], [25, 46], [25, 47], [25, 52], [25, 56], [25, 57], [25, 61], [25, 62], [25, 66], [25, 70], [25, 75], [25, 78], [25, 81], [26, 41], [26, 48], [26, 62], [26, 63], [26, 72], [26, 76], [26, 78], [26, 79], [26, 89], [27, 29], [27, 34], [27, 36], [27, 39], [27, 40], [27, 44], [27, 45], [27, 46], [27, 47], [27, 50], [27, 53], [27, 60], [27, 63], [27, 69], [27, 72], [27, 73], [27, 84], [27, 85], [27, 86], [27, 87], [28, 30], [28, 31], [28, 33], [28, 38], [28, 39], [28, 45], [28, 50], [28, 60], [28, 75], [28, 76], [28, 82], [28, 83], [28, 84], [28, 86], [28, 87], [29, 31], [29, 32], [29, 39], [29, 42], [29, 43], [29, 44], [29, 56], [29, 58], [29, 59], [29, 60], [29, 64], [29, 67], [29, 72], [29, 73], [29, 75], [29, 78], [29, 79], [29, 81], [29, 83], [29, 84], [29, 85], [29, 88], [30, 31], [30, 34], [30, 38], [30, 39], [30, 42], [30, 53], [30, 59], [30, 64], [30, 65], [30, 67], [30, 68], [30, 79], [30, 80], [30, 83], [30, 86], [31, 32], [31, 40], [31, 43], [31, 47], [31, 51], [31, 53], [31, 55], [31, 56], [31, 63], [31, 65], [31, 68], [31, 70], [31, 72], [31, 73], [31, 78], [31, 80], [31, 82], [31, 89], [32, 35], [32, 41], [32, 45], [32, 54], [32, 59], [32, 60], [32, 61], [32, 65], [32, 66], [32, 71], [32, 72], [32, 81], [32, 88], [32, 89], [33, 40], [33, 44], [33, 48], [33, 52], [33, 57], [33, 58], [33, 61], [33, 63], [33, 67], [33, 68], [33, 71], [33, 73], [33, 75], [33, 79], [33, 84], [33, 88], [34, 35], [34, 38], [34, 40], [34, 42], [34, 44], [34, 45], [34, 49], [34, 51], [34, 59], [34, 60], [34, 65], [34, 73], [34, 74], [34, 78], [34, 79], [34, 81], [34, 84], [34, 86], [34, 87], [34, 89], [35, 36], [35, 38], [35, 39], [35, 41], [35, 45], [35, 47], [35, 52], [35, 57], [35, 58], [35, 60], [35, 65], [35, 67], [35, 69], [35, 76], [35, 77], [35, 78], [35, 85], [35, 86], [35, 88], [36, 46], [36, 47], [36, 48], [36, 49], [36, 52], [36, 53], [36, 55], [36, 56], [36, 59], [36, 62], [36, 64], [36, 65], [36, 67], [36, 68], [36, 70], [36, 71], [36, 75], [36, 78], [36, 79], [36, 80], [36, 81], [36, 85], [36, 86], [36, 87], [37, 41], [37, 54], [37, 56], [37, 59], [37, 60], [37, 61], [37, 62], [37, 65], [37, 66], [37, 73], [37, 76], [37, 78], [37, 82], [37, 83], [37, 84], [37, 86], [37, 88], [38, 48], [38, 55], [38, 57], [38, 62], [38, 73], [38, 75], [38, 76], [38, 77], [38, 81], [38, 83], [38, 84], [38, 87], [38, 88], [39, 40], [39, 41], [39, 42], [39, 43], [39, 44], [39, 45], [39, 46], [39, 47], [39, 48], [39, 51], [39, 53], [39, 54], [39, 56], [39, 60], [39, 61], [39, 63], [39, 65], [39, 66], [39, 68], [39, 69], [39, 71], [39, 75], [39, 83], [39, 85], [39, 87], [40, 41], [40, 51], [40, 53], [40, 55], [40, 59], [40, 61], [40, 63], [40, 73], [40, 76], [40, 89], [41, 42], [41, 45], [41, 48], [41, 52], [41, 53], [41, 55], [41, 61], [41, 65], [41, 68], [41, 70], [41, 75], [41, 78], [41, 82], [41, 84], [41, 85], [41, 86], [42, 44], [42, 45], [42, 48], [42, 51], [42, 53], [42, 56], [42, 60], [42, 61], [42, 63], [42, 65], [42, 67], [42, 68], [42, 69], [42, 71], [42, 76], [42, 77], [42, 82], [42, 87], [42, 88], [42, 89], [43, 50], [43, 51], [43, 57], [43, 58], [43, 60], [43, 62], [43, 66], [43, 71], [43, 73], [43, 77], [43, 83], [43, 86], [43, 89], [44, 45], [44, 53], [44, 61], [44, 62], [44, 73], [44, 76], [45, 46], [45, 48], [45, 51], [45, 54], [45, 60], [45, 61], [45, 68], [45, 69], [45, 76], [45, 80], [45, 81], [45, 83], [45, 84], [46, 48], [46, 50], [46, 59], [46, 62], [46, 64], [46, 66], [46, 68], [46, 69], [46, 72], [46, 73], [46, 75], [46, 78], [46, 79], [46, 80], [46, 84], [47, 49], [47, 52], [47, 53], [47, 55], [47, 60], [47, 75], [47, 78], [47, 79], [47, 82], [47, 84], [48, 49], [48, 52], [48, 53], [48, 57], [48, 58], [48, 63], [48, 66], [48, 67], [48, 69], [48, 75], [48, 78], [48, 84], [48, 85], [48, 89], [49, 53], [49, 54], [49, 55], [49, 57], [49, 58], [49, 62], [49, 63], [49, 65], [49, 71], [49, 72], [49, 75], [49, 77], [49, 83], [49, 84], [49, 87], [49, 89], [50, 54], [50, 63], [50, 65], [50, 72], [50, 74], [50, 76], [50, 77], [50, 78], [50, 79], [50, 83], [50, 84], [50, 85], [50, 86], [50, 89], [51, 53], [51, 67], [51, 70], [51, 73], [51, 81], [51, 83], [51, 85], [52, 53], [52, 54], [52, 58], [52, 59], [52, 61], [52, 65], [52, 67], [52, 68], [52, 73], [52, 80], [52, 84], [53, 63], [53, 64], [53, 65], [53, 66], [53, 67], [53, 69], [53, 70], [53, 71], [53, 72], [53, 74], [53, 75], [53, 79], [53, 82], [54, 58], [54, 62], [54, 66], [54, 73], [54, 77], [54, 80], [54, 83], [54, 85], [54, 88], [55, 58], [55, 59], [55, 64], [55, 65], [55, 66], [55, 71], [55, 73], [55, 77], [55, 78], [55, 80], [55, 83], [55, 84], [55, 87], [56, 61], [56, 70], [56, 76], [56, 78], [56, 79], [56, 80], [56, 86], [57, 63], [57, 65], [57, 67], [57, 74], [57, 75], [57, 78], [57, 89], [58, 62], [58, 65], [58, 67], [58, 69], [58, 71], [58, 77], [58, 80], [58, 83], [58, 84], [58, 88], [58, 89], [59, 61], [59, 66], [59, 67], [59, 68], [59, 77], [59, 78], [59, 79], [59, 83], [59, 85], [60, 73], [60, 80], [60, 83], [60, 85], [60, 86], [61, 68], [61, 71], [61, 75], [61, 76], [61, 78], [61, 87], [61, 89], [62, 67], [62, 69], [62, 70], [62, 71], [62, 72], [62, 74], [62, 79], [62, 80], [62, 81], [63, 65], [63, 67], [63, 76], [63, 77], [63, 79], [64, 67], [64, 70], [64, 73], [64, 75], [64, 76], [64, 82], [64, 84], [64, 86], [65, 67], [65, 69], [65, 72], [65, 74], [65, 84], [66, 68], [66, 72], [66, 82], [66, 83], [66, 88], [66, 89], [67, 72], [67, 74], [67, 78], [67, 80], [67, 87], [67, 88], [67, 89], [68, 70], [68, 74], [68, 76], [68, 77], [68, 84], [68, 86], [69, 71], [69, 77], [69, 80], [69, 83], [69, 86], [70, 71], [70, 74], [70, 75], [70, 77], [70, 84], [70, 85], [70, 86], [70, 88], [71, 75], [71, 77], [71, 79], [73, 74], [73, 75], [73, 76], [73, 78], [73, 81], [73, 82], [73, 84], [73, 85], [73, 88], [74, 78], [74, 79], [74, 80], [74, 89], [75, 77], [75, 78], [75, 79], [75, 81], [75, 89], [76, 79], [76, 85], [76, 86], [76, 89], [77, 78], [77, 79], [77, 86], [77, 88], [78, 81], [78, 83], [78, 86], [78, 88], [79, 82], [80, 86], [81, 83], [84, 86], [85, 89], [86, 89]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l5-s9/solution/solve.sh b/tasks/construct-mc-max-independent-set-l5-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..85cb42c41add61830c807c292ed345c1f5396e00 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l5-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"independent_set": [16, 19, 26, 30, 40, 44, 46, 52, 56, 57, 71, 81, 82, 85, 87, 88]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-independent-set-l5-s9/tests/check.py b/tasks/construct-mc-max-independent-set-l5-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..adce413e8578d996549583b990e4ff559f38ed41 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l5-s9/tests/check.py @@ -0,0 +1,18 @@ +"""Independent set of size >= k in a given graph (MathConstraint max_independent_set, CC-BY-4.0).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("independent_set"), None, 0, n - 1, "independent_set") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) < k: + raise Invalid(f"set has {len(S)} vertices, need at least {k}") + E = {(u, v) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(S), 2): + if (u, v) in E: + raise Invalid(f"vertices {u} and {v} are adjacent") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-max-independent-set-l5-s9/tests/instance.json b/tasks/construct-mc-max-independent-set-l5-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..97c022068f1ebefb650e3979717849f9a8d6797e --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l5-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 90, "k": 16, "edges": [[0, 6], [0, 9], [0, 19], [0, 22], [0, 26], [0, 27], [0, 29], [0, 30], [0, 33], [0, 41], [0, 45], [0, 53], [0, 55], [0, 57], [0, 65], [0, 67], [0, 70], [0, 77], [0, 80], [0, 83], [0, 84], [0, 89], [1, 7], [1, 12], [1, 15], [1, 17], [1, 18], [1, 19], [1, 23], [1, 25], [1, 27], [1, 32], [1, 33], [1, 34], [1, 43], [1, 45], [1, 46], [1, 51], [1, 54], [1, 56], [1, 57], [1, 58], [1, 59], [1, 61], [1, 65], [1, 67], [1, 68], [1, 69], [1, 74], [1, 81], [1, 84], [1, 87], [2, 6], [2, 7], [2, 8], [2, 9], [2, 13], [2, 15], [2, 17], [2, 19], [2, 22], [2, 23], [2, 24], [2, 29], [2, 30], [2, 33], [2, 37], [2, 44], [2, 47], [2, 50], [2, 54], [2, 59], [2, 64], [2, 65], [2, 75], [2, 88], [3, 5], [3, 10], [3, 13], [3, 17], [3, 18], [3, 20], [3, 25], [3, 32], [3, 41], [3, 42], [3, 43], [3, 47], [3, 49], [3, 51], [3, 59], [3, 66], [3, 75], [3, 80], [3, 86], [4, 7], [4, 8], [4, 11], [4, 16], [4, 17], [4, 18], [4, 25], [4, 34], [4, 39], [4, 41], [4, 46], [4, 52], [4, 53], [4, 60], [4, 68], [4, 69], [4, 70], [4, 76], [4, 77], [4, 78], [4, 79], [4, 82], [4, 85], [5, 6], [5, 7], [5, 10], [5, 14], [5, 19], [5, 25], [5, 32], [5, 33], [5, 45], [5, 47], [5, 52], [5, 53], [5, 57], [5, 60], [5, 62], [5, 67], [5, 72], [5, 73], [5, 74], [5, 75], [5, 77], [5, 78], [5, 79], [5, 85], [6, 9], [6, 16], [6, 20], [6, 25], [6, 26], [6, 27], [6, 29], [6, 30], [6, 35], [6, 38], [6, 42], [6, 45], [6, 47], [6, 52], [6, 54], [6, 57], [6, 59], [6, 60], [6, 61], [6, 66], [6, 68], [6, 69], [6, 71], [6, 74], [6, 78], [6, 80], [6, 81], [6, 83], [6, 86], [7, 11], [7, 12], [7, 21], [7, 31], [7, 34], [7, 36], [7, 37], [7, 38], [7, 40], [7, 48], [7, 49], [7, 50], [7, 52], [7, 53], [7, 57], [7, 58], [7, 63], [7, 67], [7, 72], [7, 75], [7, 76], [7, 78], [7, 81], [7, 82], [7, 84], [7, 85], [7, 89], [8, 9], [8, 15], [8, 16], [8, 17], [8, 19], [8, 28], [8, 29], [8, 33], [8, 34], [8, 49], [8, 55], [8, 58], [8, 60], [8, 62], [8, 64], [8, 65], [8, 69], [8, 72], [8, 82], [8, 87], [8, 89], [9, 13], [9, 16], [9, 17], [9, 18], [9, 20], [9, 23], [9, 26], [9, 27], [9, 29], [9, 34], [9, 38], [9, 51], [9, 53], [9, 54], [9, 56], [9, 60], [9, 68], [9, 77], [9, 78], [9, 84], [9, 85], [9, 89], [10, 11], [10, 14], [10, 18], [10, 22], [10, 23], [10, 27], [10, 30], [10, 31], [10, 33], [10, 40], [10, 42], [10, 43], [10, 45], [10, 46], [10, 47], [10, 48], [10, 49], [10, 50], [10, 55], [10, 58], [10, 59], [10, 60], [10, 61], [10, 68], [10, 69], [10, 70], [10, 78], [10, 80], [10, 84], [10, 85], [10, 86], [10, 87], [10, 89], [11, 21], [11, 22], [11, 24], [11, 29], [11, 42], [11, 43], [11, 44], [11, 45], [11, 48], [11, 60], [11, 69], [11, 70], [11, 72], [11, 74], [11, 75], [11, 76], [11, 79], [11, 81], [11, 82], [11, 84], [11, 85], [11, 87], [12, 13], [12, 14], [12, 19], [12, 21], [12, 26], [12, 29], [12, 34], [12, 36], [12, 39], [12, 40], [12, 43], [12, 45], [12, 47], [12, 49], [12, 54], [12, 65], [12, 68], [12, 71], [12, 72], [12, 73], [12, 75], [12, 79], [12, 84], [12, 86], [13, 16], [13, 17], [13, 19], [13, 24], [13, 25], [13, 27], [13, 30], [13, 35], [13, 41], [13, 42], [13, 45], [13, 59], [13, 62], [13, 63], [13, 66], [13, 69], [13, 70], [13, 73], [13, 74], [13, 79], [13, 85], [13, 87], [13, 89], [14, 18], [14, 23], [14, 28], [14, 33], [14, 39], [14, 48], [14, 49], [14, 51], [14, 56], [14, 59], [14, 66], [14, 67], [14, 68], [14, 69], [14, 72], [14, 77], [14, 80], [14, 81], [14, 84], [14, 85], [14, 86], [15, 17], [15, 19], [15, 24], [15, 25], [15, 28], [15, 32], [15, 38], [15, 44], [15, 45], [15, 63], [15, 70], [15, 73], [15, 79], [15, 80], [15, 82], [15, 84], [15, 87], [15, 88], [16, 20], [16, 23], [16, 25], [16, 27], [16, 28], [16, 29], [16, 31], [16, 32], [16, 36], [16, 38], [16, 39], [16, 41], [16, 45], [16, 47], [16, 48], [16, 53], [16, 60], [16, 65], [16, 70], [16, 72], [16, 77], [16, 79], [16, 89], [17, 21], [17, 26], [17, 28], [17, 30], [17, 32], [17, 33], [17, 34], [17, 35], [17, 36], [17, 37], [17, 38], [17, 39], [17, 48], [17, 49], [17, 50], [17, 56], [17, 60], [17, 61], [17, 63], [17, 64], [17, 65], [17, 66], [17, 67], [17, 68], [17, 69], [17, 78], [17, 82], [17, 83], [17, 87], [17, 89], [18, 21], [18, 24], [18, 29], [18, 31], [18, 35], [18, 43], [18, 46], [18, 56], [18, 62], [18, 64], [18, 69], [18, 71], [18, 78], [18, 79], [18, 80], [18, 83], [18, 86], [19, 27], [19, 34], [19, 38], [19, 45], [19, 48], [19, 53], [19, 55], [19, 58], [19, 59], [19, 63], [19, 64], [19, 68], [19, 69], [19, 74], [19, 75], [19, 79], [19, 89], [20, 21], [20, 23], [20, 26], [20, 29], [20, 38], [20, 41], [20, 44], [20, 50], [20, 52], [20, 54], [20, 55], [20, 62], [20, 63], [20, 65], [20, 66], [20, 69], [20, 70], [20, 76], [20, 80], [20, 81], [20, 85], [20, 87], [20, 89], [21, 25], [21, 26], [21, 28], [21, 32], [21, 33], [21, 35], [21, 38], [21, 39], [21, 40], [21, 43], [21, 44], [21, 47], [21, 48], [21, 49], [21, 50], [21, 54], [21, 55], [21, 60], [21, 66], [21, 70], [21, 75], [21, 76], [21, 77], [21, 78], [21, 81], [21, 83], [21, 84], [21, 85], [21, 88], [22, 25], [22, 33], [22, 35], [22, 40], [22, 44], [22, 45], [22, 47], [22, 48], [22, 49], [22, 50], [22, 52], [22, 54], [22, 55], [22, 60], [22, 64], [22, 68], [22, 70], [22, 74], [22, 75], [22, 76], [22, 77], [22, 86], [22, 88], [23, 27], [23, 28], [23, 36], [23, 41], [23, 44], [23, 53], [23, 54], [23, 56], [23, 58], [23, 59], [23, 60], [23, 63], [23, 65], [23, 67], [23, 68], [23, 78], [23, 82], [24, 34], [24, 39], [24, 44], [24, 46], [24, 48], [24, 51], [24, 52], [24, 55], [24, 58], [24, 60], [24, 61], [24, 65], [24, 72], [24, 73], [24, 77], [24, 79], [24, 80], [24, 85], [25, 26], [25, 27], [25, 28], [25, 30], [25, 31], [25, 32], [25, 36], [25, 37], [25, 46], [25, 47], [25, 52], [25, 56], [25, 57], [25, 61], [25, 62], [25, 66], [25, 70], [25, 75], [25, 78], [25, 81], [26, 41], [26, 48], [26, 62], [26, 63], [26, 72], [26, 76], [26, 78], [26, 79], [26, 89], [27, 29], [27, 34], [27, 36], [27, 39], [27, 40], [27, 44], [27, 45], [27, 46], [27, 47], [27, 50], [27, 53], [27, 60], [27, 63], [27, 69], [27, 72], [27, 73], [27, 84], [27, 85], [27, 86], [27, 87], [28, 30], [28, 31], [28, 33], [28, 38], [28, 39], [28, 45], [28, 50], [28, 60], [28, 75], [28, 76], [28, 82], [28, 83], [28, 84], [28, 86], [28, 87], [29, 31], [29, 32], [29, 39], [29, 42], [29, 43], [29, 44], [29, 56], [29, 58], [29, 59], [29, 60], [29, 64], [29, 67], [29, 72], [29, 73], [29, 75], [29, 78], [29, 79], [29, 81], [29, 83], [29, 84], [29, 85], [29, 88], [30, 31], [30, 34], [30, 38], [30, 39], [30, 42], [30, 53], [30, 59], [30, 64], [30, 65], [30, 67], [30, 68], [30, 79], [30, 80], [30, 83], [30, 86], [31, 32], [31, 40], [31, 43], [31, 47], [31, 51], [31, 53], [31, 55], [31, 56], [31, 63], [31, 65], [31, 68], [31, 70], [31, 72], [31, 73], [31, 78], [31, 80], [31, 82], [31, 89], [32, 35], [32, 41], [32, 45], [32, 54], [32, 59], [32, 60], [32, 61], [32, 65], [32, 66], [32, 71], [32, 72], [32, 81], [32, 88], [32, 89], [33, 40], [33, 44], [33, 48], [33, 52], [33, 57], [33, 58], [33, 61], [33, 63], [33, 67], [33, 68], [33, 71], [33, 73], [33, 75], [33, 79], [33, 84], [33, 88], [34, 35], [34, 38], [34, 40], [34, 42], [34, 44], [34, 45], [34, 49], [34, 51], [34, 59], [34, 60], [34, 65], [34, 73], [34, 74], [34, 78], [34, 79], [34, 81], [34, 84], [34, 86], [34, 87], [34, 89], [35, 36], [35, 38], [35, 39], [35, 41], [35, 45], [35, 47], [35, 52], [35, 57], [35, 58], [35, 60], [35, 65], [35, 67], [35, 69], [35, 76], [35, 77], [35, 78], [35, 85], [35, 86], [35, 88], [36, 46], [36, 47], [36, 48], [36, 49], [36, 52], [36, 53], [36, 55], [36, 56], [36, 59], [36, 62], [36, 64], [36, 65], [36, 67], [36, 68], [36, 70], [36, 71], [36, 75], [36, 78], [36, 79], [36, 80], [36, 81], [36, 85], [36, 86], [36, 87], [37, 41], [37, 54], [37, 56], [37, 59], [37, 60], [37, 61], [37, 62], [37, 65], [37, 66], [37, 73], [37, 76], [37, 78], [37, 82], [37, 83], [37, 84], [37, 86], [37, 88], [38, 48], [38, 55], [38, 57], [38, 62], [38, 73], [38, 75], [38, 76], [38, 77], [38, 81], [38, 83], [38, 84], [38, 87], [38, 88], [39, 40], [39, 41], [39, 42], [39, 43], [39, 44], [39, 45], [39, 46], [39, 47], [39, 48], [39, 51], [39, 53], [39, 54], [39, 56], [39, 60], [39, 61], [39, 63], [39, 65], [39, 66], [39, 68], [39, 69], [39, 71], [39, 75], [39, 83], [39, 85], [39, 87], [40, 41], [40, 51], [40, 53], [40, 55], [40, 59], [40, 61], [40, 63], [40, 73], [40, 76], [40, 89], [41, 42], [41, 45], [41, 48], [41, 52], [41, 53], [41, 55], [41, 61], [41, 65], [41, 68], [41, 70], [41, 75], [41, 78], [41, 82], [41, 84], [41, 85], [41, 86], [42, 44], [42, 45], [42, 48], [42, 51], [42, 53], [42, 56], [42, 60], [42, 61], [42, 63], [42, 65], [42, 67], [42, 68], [42, 69], [42, 71], [42, 76], [42, 77], [42, 82], [42, 87], [42, 88], [42, 89], [43, 50], [43, 51], [43, 57], [43, 58], [43, 60], [43, 62], [43, 66], [43, 71], [43, 73], [43, 77], [43, 83], [43, 86], [43, 89], [44, 45], [44, 53], [44, 61], [44, 62], [44, 73], [44, 76], [45, 46], [45, 48], [45, 51], [45, 54], [45, 60], [45, 61], [45, 68], [45, 69], [45, 76], [45, 80], [45, 81], [45, 83], [45, 84], [46, 48], [46, 50], [46, 59], [46, 62], [46, 64], [46, 66], [46, 68], [46, 69], [46, 72], [46, 73], [46, 75], [46, 78], [46, 79], [46, 80], [46, 84], [47, 49], [47, 52], [47, 53], [47, 55], [47, 60], [47, 75], [47, 78], [47, 79], [47, 82], [47, 84], [48, 49], [48, 52], [48, 53], [48, 57], [48, 58], [48, 63], [48, 66], [48, 67], [48, 69], [48, 75], [48, 78], [48, 84], [48, 85], [48, 89], [49, 53], [49, 54], [49, 55], [49, 57], [49, 58], [49, 62], [49, 63], [49, 65], [49, 71], [49, 72], [49, 75], [49, 77], [49, 83], [49, 84], [49, 87], [49, 89], [50, 54], [50, 63], [50, 65], [50, 72], [50, 74], [50, 76], [50, 77], [50, 78], [50, 79], [50, 83], [50, 84], [50, 85], [50, 86], [50, 89], [51, 53], [51, 67], [51, 70], [51, 73], [51, 81], [51, 83], [51, 85], [52, 53], [52, 54], [52, 58], [52, 59], [52, 61], [52, 65], [52, 67], [52, 68], [52, 73], [52, 80], [52, 84], [53, 63], [53, 64], [53, 65], [53, 66], [53, 67], [53, 69], [53, 70], [53, 71], [53, 72], [53, 74], [53, 75], [53, 79], [53, 82], [54, 58], [54, 62], [54, 66], [54, 73], [54, 77], [54, 80], [54, 83], [54, 85], [54, 88], [55, 58], [55, 59], [55, 64], [55, 65], [55, 66], [55, 71], [55, 73], [55, 77], [55, 78], [55, 80], [55, 83], [55, 84], [55, 87], [56, 61], [56, 70], [56, 76], [56, 78], [56, 79], [56, 80], [56, 86], [57, 63], [57, 65], [57, 67], [57, 74], [57, 75], [57, 78], [57, 89], [58, 62], [58, 65], [58, 67], [58, 69], [58, 71], [58, 77], [58, 80], [58, 83], [58, 84], [58, 88], [58, 89], [59, 61], [59, 66], [59, 67], [59, 68], [59, 77], [59, 78], [59, 79], [59, 83], [59, 85], [60, 73], [60, 80], [60, 83], [60, 85], [60, 86], [61, 68], [61, 71], [61, 75], [61, 76], [61, 78], [61, 87], [61, 89], [62, 67], [62, 69], [62, 70], [62, 71], [62, 72], [62, 74], [62, 79], [62, 80], [62, 81], [63, 65], [63, 67], [63, 76], [63, 77], [63, 79], [64, 67], [64, 70], [64, 73], [64, 75], [64, 76], [64, 82], [64, 84], [64, 86], [65, 67], [65, 69], [65, 72], [65, 74], [65, 84], [66, 68], [66, 72], [66, 82], [66, 83], [66, 88], [66, 89], [67, 72], [67, 74], [67, 78], [67, 80], [67, 87], [67, 88], [67, 89], [68, 70], [68, 74], [68, 76], [68, 77], [68, 84], [68, 86], [69, 71], [69, 77], [69, 80], [69, 83], [69, 86], [70, 71], [70, 74], [70, 75], [70, 77], [70, 84], [70, 85], [70, 86], [70, 88], [71, 75], [71, 77], [71, 79], [73, 74], [73, 75], [73, 76], [73, 78], [73, 81], [73, 82], [73, 84], [73, 85], [73, 88], [74, 78], [74, 79], [74, 80], [74, 89], [75, 77], [75, 78], [75, 79], [75, 81], [75, 89], [76, 79], [76, 85], [76, 86], [76, 89], [77, 78], [77, 79], [77, 86], [77, 88], [78, 81], [78, 83], [78, 86], [78, 88], [79, 82], [80, 86], [81, 83], [84, 86], [85, 89], [86, 89]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l5-s9/tests/run.py b/tasks/construct-mc-max-independent-set-l5-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l5-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-independent-set-l5-s9/tests/test.sh b/tasks/construct-mc-max-independent-set-l5-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l5-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-non-transitive-dice-l5-s0/environment/Dockerfile b/tasks/construct-mc-non-transitive-dice-l5-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l5-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-non-transitive-dice-l5-s0/environment/instance.json b/tasks/construct-mc-non-transitive-dice-l5-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2479058517cdbd85a61aa4e73dcc47e5b261f52f --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l5-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 6, "m": 7, "family": "mc_non_transitive_dice", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-non-transitive-dice-l5-s0/solution/solve.sh b/tasks/construct-mc-non-transitive-dice-l5-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d90d85d94ba569300b93cfefb2db5394e17745af --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l5-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"dice": [[1, 3, 4, 5, 5, 11, 12], [0, 2, 4, 4, 7, 8, 11], [0, 3, 5, 5, 6, 6, 7], [2, 3, 3, 4, 4, 12, 13], [0, 0, 3, 3, 10, 11, 13], [1, 2, 6, 7, 7, 8, 9]]} +RLMATH_EOF diff --git a/tasks/construct-mc-non-transitive-dice-l5-s0/tests/check.py b/tasks/construct-mc-non-transitive-dice-l5-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3d5c04fa6e2819bf32f34fafe13a383437dc62a --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l5-s0/tests/check.py @@ -0,0 +1,18 @@ +"""Cyclically intransitive dice (MathConstraint non_transitive_dice, CC-BY-4.0): n dice with m faces in +0..2m-1; die i beats die (i+1) mod n, i.e. #{(a, b): face_i(a) > face_{i+1}(b)} > floor(m^2 / 2). +Face order is irrelevant (upstream additionally demanded sorted faces as a symmetry break; not required).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, m = inst["n"], inst["m"] + D = ans.get("dice") + if not isinstance(D, list) or len(D) != n: + raise Invalid(f"dice must be a list of {n} dice") + D = [int_list(d, m, 0, 2 * m - 1, "die") for d in D] + for i in range(n): + A, B = D[i], D[(i + 1) % n] + w = sum(1 for a in A for b in B if a > b) + if w <= m * m // 2: + raise Invalid(f"die {i} wins only {w} of {m * m} face pairs against die {(i + 1) % n}") + return None, {} diff --git a/tasks/construct-mc-non-transitive-dice-l5-s0/tests/instance.json b/tasks/construct-mc-non-transitive-dice-l5-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2479058517cdbd85a61aa4e73dcc47e5b261f52f --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l5-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 6, "m": 7, "family": "mc_non_transitive_dice", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-non-transitive-dice-l5-s0/tests/run.py b/tasks/construct-mc-non-transitive-dice-l5-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l5-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-non-transitive-dice-l5-s0/tests/test.sh b/tasks/construct-mc-non-transitive-dice-l5-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l5-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-number-partitioning-l5-s4/environment/Dockerfile b/tasks/construct-mc-number-partitioning-l5-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l5-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-number-partitioning-l5-s4/environment/instance.json b/tasks/construct-mc-number-partitioning-l5-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7bc4277cdc952b43a62c97153f49a605be853c4b --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l5-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 44, "k": 3, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l5-s4/solution/solve.sh b/tasks/construct-mc-number-partitioning-l5-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..93b7d6c5fb14aa0715c3f50abefb785c4f5eb6f4 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l5-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [2, 1, 1, 0, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-number-partitioning-l5-s4/tests/check.py b/tasks/construct-mc-number-partitioning-l5-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..67793721db8ba7d3c3979ea0e1e07091491ffa7e --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l5-s4/tests/check.py @@ -0,0 +1,14 @@ +"""Partition {1..n} into k subsets of equal sum (MathConstraint number_partitioning, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + x = int_list(ans.get("x"), n, 0, k - 1, "x") + target = n * (n + 1) // 2 // k + sums = [0] * k + for i, s in enumerate(x): + sums[s] += i + 1 + if any(t != target for t in sums): + raise Invalid(f"subset sums {sums} are not all {target}") + return None, {} diff --git a/tasks/construct-mc-number-partitioning-l5-s4/tests/instance.json b/tasks/construct-mc-number-partitioning-l5-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7bc4277cdc952b43a62c97153f49a605be853c4b --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l5-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 44, "k": 3, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l5-s4/tests/run.py b/tasks/construct-mc-number-partitioning-l5-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l5-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-number-partitioning-l5-s4/tests/test.sh b/tasks/construct-mc-number-partitioning-l5-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l5-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-pysms-clique-coloring-l4-s1/environment/Dockerfile b/tasks/construct-mc-pysms-clique-coloring-l4-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-l4-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-pysms-clique-coloring-l4-s1/environment/instance.json b/tasks/construct-mc-pysms-clique-coloring-l4-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8c795d03f6b6c6fc92df9733e7477dec716ae8a5 --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-l4-s1/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 15, "required_edges": [], "max_chromatic_number": 4, "max_clique": 4, "min_degree": 5, "family": "mc_pysms_clique_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-clique-coloring-l4-s1/solution/solve.sh b/tasks/construct-mc-pysms-clique-coloring-l4-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e6e0532cf8c3721d2a7d5589c935a08b0e5f6493 --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-l4-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"edges": [[0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [0, 14], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [3, 14], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [4, 13], [4, 14]], "coloring": [2, 2, 2, 0, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-clique-coloring-l4-s1/tests/check.py b/tasks/construct-mc-pysms-clique-coloring-l4-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-l4-s1/tests/check.py @@ -0,0 +1,151 @@ +"""Graph-existence constraints (MathConstraint pysms_* problem types, CC-BY-4.0). The answer is a graph on +the stated vertex set, plus a proper colouring when a chromatic-number upper bound is asked for. Every +constraint present in the instance is checked exactly (no stored answer is compared). + +Upstream note: upstream verifies by fixing the edge variables in the pysms CNF and calling CaDiCaL; the +min-chromatic-number bound of pysms_graph_builder is only a raw smsg solver parameter, not a clause, so the +upstream verifier ignored it. It is enforced here. Edge endpoints are also type-checked (upstream accepted +floats/bools that compare in range).""" +import itertools + +from run import Invalid, int_list + + +def _has_clique(adj, n, k): + def rec(cand, size): + if size == k: + return True + while cand: + if size + bin(cand).count("1") < k: + return False + v = cand.bit_length() - 1 + cand &= ~(1 << v) + if rec(cand & adj[v], size + 1): + return True + return False + return rec((1 << n) - 1, 0) + + +def _connected(adj, n, removed): + alive = [v for v in range(n) if not removed >> v & 1] + if len(alive) <= 1: + return True + mask = sum(1 << v for v in alive) + seen = 1 << alive[0] + stack = [alive[0]] + while stack: + v = stack.pop() + new = adj[v] & mask & ~seen + seen |= new + while new: + u = new.bit_length() - 1 + new &= ~(1 << u) + stack.append(u) + return seen == mask + + +def _girth(adj, n): + best = None + for r in range(n): + dist, par, q = {r: 0}, {r: -1}, [r] + for v in q: + nb = adj[v] + while nb: + u = nb.bit_length() - 1 + nb &= ~(1 << u) + if u not in dist: + dist[u], par[u] = dist[v] + 1, v + q.append(u) + elif par[v] != u: + c = dist[u] + dist[v] + 1 + best = c if best is None else min(best, c) + return best # None = acyclic + + +def _colourable(adj, n, k): + col = [-1] * n + order = sorted(range(n), key=lambda v: -bin(adj[v]).count("1")) + + def rec(i): + if i == n: + return True + v = order[i] + used = {col[u] for u in range(n) if adj[v] >> u & 1 and col[u] >= 0} + for c in range(k): + if c not in used: + col[v] = c + if rec(i + 1): + return True + col[v] = -1 + return False + return rec(0) + + +def check(inst, ans): + n = inst["vertices"] + E = ans.get("edges") + if not isinstance(E, list): + raise Invalid("edges must be a list of [u, v] pairs") + edges = set() + for e in E: + u, v = int_list(e, 2, 0, n - 1, "edge") + if u == v: + raise Invalid(f"self-loop at {u}") + e2 = (min(u, v), max(u, v)) + if e2 in edges: + raise Invalid(f"duplicate edge {e2}") + edges.add(e2) + adj = [0] * n + for u, v in edges: + adj[u] |= 1 << v + adj[v] |= 1 << u + deg = [bin(a).count("1") for a in adj] + for u, v in inst.get("required_edges", []): + if (min(u, v), max(u, v)) not in edges: + raise Invalid(f"required edge ({u},{v}) is missing") + c = inst.get + if c("min_degree") is not None and min(deg) < c("min_degree"): + raise Invalid(f"minimum degree {min(deg)} < {c('min_degree')}") + if c("max_degree") is not None and max(deg) > c("max_degree"): + raise Invalid(f"maximum degree {max(deg)} > {c('max_degree')}") + if c("min_edges") is not None and len(edges) < c("min_edges"): + raise Invalid(f"{len(edges)} edges < {c('min_edges')}") + if c("max_edges") is not None and len(edges) > c("max_edges"): + raise Invalid(f"{len(edges)} edges > {c('max_edges')}") + if c("max_clique") is not None and _has_clique(adj, n, c("max_clique") + 1): + raise Invalid(f"graph contains a clique of size {c('max_clique') + 1}") + if c("max_independent_set") is not None: + full = (1 << n) - 1 + comp = [full & ~adj[v] & ~(1 << v) for v in range(n)] + if _has_clique(comp, n, c("max_independent_set") + 1): + raise Invalid(f"graph contains an independent set of size {c('max_independent_set') + 1}") + if c("min_girth") is not None: + g = _girth(adj, n) + if g is not None and g < c("min_girth"): + raise Invalid(f"graph has a cycle of length {g} < {c('min_girth')}") + if c("min_connectivity") is not None: + k = c("min_connectivity") + if n <= k: + raise Invalid("too few vertices for this connectivity") + for s in range(k): + for I in itertools.combinations(range(n), s): + if not _connected(adj, n, sum(1 << v for v in I)): + raise Invalid(f"deleting vertices {list(I)} disconnects the graph") + if c("mtf"): + for u, v in itertools.combinations(range(n), 2): + if adj[u] >> v & 1: + if adj[u] & adj[v]: + raise Invalid(f"triangle on edge ({u},{v})") + elif not adj[u] & adj[v]: + raise Invalid(f"non-adjacent {u}, {v} have no common neighbour (edge could be added)") + if c("max_chromatic_number") is not None: + k = c("max_chromatic_number") + col = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in edges: + if col[u] == col[v]: + raise Invalid(f"coloring: edge ({u},{v}) is monochromatic") + if c("min_chromatic_number") is not None and c("min_chromatic_number") >= 2: + m = c("min_chromatic_number") + if not edges or _colourable(adj, n, m - 1): + raise Invalid(f"graph is {m - 1}-colourable, chromatic number must be at least {m}") + return None, {"num_edges": len(edges)} diff --git a/tasks/construct-mc-pysms-clique-coloring-l4-s1/tests/instance.json b/tasks/construct-mc-pysms-clique-coloring-l4-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8c795d03f6b6c6fc92df9733e7477dec716ae8a5 --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-l4-s1/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 15, "required_edges": [], "max_chromatic_number": 4, "max_clique": 4, "min_degree": 5, "family": "mc_pysms_clique_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-clique-coloring-l4-s1/tests/run.py b/tasks/construct-mc-pysms-clique-coloring-l4-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-l4-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-pysms-clique-coloring-l4-s1/tests/test.sh b/tasks/construct-mc-pysms-clique-coloring-l4-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-l4-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-pysms-graph-builder-l4-s0/environment/Dockerfile b/tasks/construct-mc-pysms-graph-builder-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-graph-builder-l4-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-pysms-graph-builder-l4-s0/environment/instance.json b/tasks/construct-mc-pysms-graph-builder-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..953b86c6c17dd1f159bb78f307aae13d5c269871 --- /dev/null +++ b/tasks/construct-mc-pysms-graph-builder-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 14, "required_edges": [], "max_degree": 7, "min_degree": 5, "max_chromatic_number": 5, "min_chromatic_number": 3, "min_edges": 21, "max_edges": 36, "family": "mc_pysms_graph_builder", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-graph-builder-l4-s0/solution/solve.sh b/tasks/construct-mc-pysms-graph-builder-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f6eac8517fc65c1e44964364aa386cf981fc76e1 --- /dev/null +++ b/tasks/construct-mc-pysms-graph-builder-l4-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"edges": [[0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [1, 8], [1, 10], [1, 11], [1, 12], [1, 13], [2, 6], [2, 7], [2, 9], [2, 12], [2, 13], [3, 5], [3, 7], [3, 8], [3, 9], [3, 11], [4, 5], [4, 6], [4, 7], [4, 10], [4, 13], [5, 8], [5, 9], [5, 10], [6, 8], [6, 10], [6, 11], [6, 12], [7, 9], [7, 13], [8, 12], [11, 13]], "coloring": [1, 1, 1, 0, 1, 2, 0, 2, 3, 3, 3, 2, 2, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-graph-builder-l4-s0/tests/check.py b/tasks/construct-mc-pysms-graph-builder-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-graph-builder-l4-s0/tests/check.py @@ -0,0 +1,151 @@ +"""Graph-existence constraints (MathConstraint pysms_* problem types, CC-BY-4.0). The answer is a graph on +the stated vertex set, plus a proper colouring when a chromatic-number upper bound is asked for. Every +constraint present in the instance is checked exactly (no stored answer is compared). + +Upstream note: upstream verifies by fixing the edge variables in the pysms CNF and calling CaDiCaL; the +min-chromatic-number bound of pysms_graph_builder is only a raw smsg solver parameter, not a clause, so the +upstream verifier ignored it. It is enforced here. Edge endpoints are also type-checked (upstream accepted +floats/bools that compare in range).""" +import itertools + +from run import Invalid, int_list + + +def _has_clique(adj, n, k): + def rec(cand, size): + if size == k: + return True + while cand: + if size + bin(cand).count("1") < k: + return False + v = cand.bit_length() - 1 + cand &= ~(1 << v) + if rec(cand & adj[v], size + 1): + return True + return False + return rec((1 << n) - 1, 0) + + +def _connected(adj, n, removed): + alive = [v for v in range(n) if not removed >> v & 1] + if len(alive) <= 1: + return True + mask = sum(1 << v for v in alive) + seen = 1 << alive[0] + stack = [alive[0]] + while stack: + v = stack.pop() + new = adj[v] & mask & ~seen + seen |= new + while new: + u = new.bit_length() - 1 + new &= ~(1 << u) + stack.append(u) + return seen == mask + + +def _girth(adj, n): + best = None + for r in range(n): + dist, par, q = {r: 0}, {r: -1}, [r] + for v in q: + nb = adj[v] + while nb: + u = nb.bit_length() - 1 + nb &= ~(1 << u) + if u not in dist: + dist[u], par[u] = dist[v] + 1, v + q.append(u) + elif par[v] != u: + c = dist[u] + dist[v] + 1 + best = c if best is None else min(best, c) + return best # None = acyclic + + +def _colourable(adj, n, k): + col = [-1] * n + order = sorted(range(n), key=lambda v: -bin(adj[v]).count("1")) + + def rec(i): + if i == n: + return True + v = order[i] + used = {col[u] for u in range(n) if adj[v] >> u & 1 and col[u] >= 0} + for c in range(k): + if c not in used: + col[v] = c + if rec(i + 1): + return True + col[v] = -1 + return False + return rec(0) + + +def check(inst, ans): + n = inst["vertices"] + E = ans.get("edges") + if not isinstance(E, list): + raise Invalid("edges must be a list of [u, v] pairs") + edges = set() + for e in E: + u, v = int_list(e, 2, 0, n - 1, "edge") + if u == v: + raise Invalid(f"self-loop at {u}") + e2 = (min(u, v), max(u, v)) + if e2 in edges: + raise Invalid(f"duplicate edge {e2}") + edges.add(e2) + adj = [0] * n + for u, v in edges: + adj[u] |= 1 << v + adj[v] |= 1 << u + deg = [bin(a).count("1") for a in adj] + for u, v in inst.get("required_edges", []): + if (min(u, v), max(u, v)) not in edges: + raise Invalid(f"required edge ({u},{v}) is missing") + c = inst.get + if c("min_degree") is not None and min(deg) < c("min_degree"): + raise Invalid(f"minimum degree {min(deg)} < {c('min_degree')}") + if c("max_degree") is not None and max(deg) > c("max_degree"): + raise Invalid(f"maximum degree {max(deg)} > {c('max_degree')}") + if c("min_edges") is not None and len(edges) < c("min_edges"): + raise Invalid(f"{len(edges)} edges < {c('min_edges')}") + if c("max_edges") is not None and len(edges) > c("max_edges"): + raise Invalid(f"{len(edges)} edges > {c('max_edges')}") + if c("max_clique") is not None and _has_clique(adj, n, c("max_clique") + 1): + raise Invalid(f"graph contains a clique of size {c('max_clique') + 1}") + if c("max_independent_set") is not None: + full = (1 << n) - 1 + comp = [full & ~adj[v] & ~(1 << v) for v in range(n)] + if _has_clique(comp, n, c("max_independent_set") + 1): + raise Invalid(f"graph contains an independent set of size {c('max_independent_set') + 1}") + if c("min_girth") is not None: + g = _girth(adj, n) + if g is not None and g < c("min_girth"): + raise Invalid(f"graph has a cycle of length {g} < {c('min_girth')}") + if c("min_connectivity") is not None: + k = c("min_connectivity") + if n <= k: + raise Invalid("too few vertices for this connectivity") + for s in range(k): + for I in itertools.combinations(range(n), s): + if not _connected(adj, n, sum(1 << v for v in I)): + raise Invalid(f"deleting vertices {list(I)} disconnects the graph") + if c("mtf"): + for u, v in itertools.combinations(range(n), 2): + if adj[u] >> v & 1: + if adj[u] & adj[v]: + raise Invalid(f"triangle on edge ({u},{v})") + elif not adj[u] & adj[v]: + raise Invalid(f"non-adjacent {u}, {v} have no common neighbour (edge could be added)") + if c("max_chromatic_number") is not None: + k = c("max_chromatic_number") + col = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in edges: + if col[u] == col[v]: + raise Invalid(f"coloring: edge ({u},{v}) is monochromatic") + if c("min_chromatic_number") is not None and c("min_chromatic_number") >= 2: + m = c("min_chromatic_number") + if not edges or _colourable(adj, n, m - 1): + raise Invalid(f"graph is {m - 1}-colourable, chromatic number must be at least {m}") + return None, {"num_edges": len(edges)} diff --git a/tasks/construct-mc-pysms-graph-builder-l4-s0/tests/instance.json b/tasks/construct-mc-pysms-graph-builder-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..953b86c6c17dd1f159bb78f307aae13d5c269871 --- /dev/null +++ b/tasks/construct-mc-pysms-graph-builder-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 14, "required_edges": [], "max_degree": 7, "min_degree": 5, "max_chromatic_number": 5, "min_chromatic_number": 3, "min_edges": 21, "max_edges": 36, "family": "mc_pysms_graph_builder", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-graph-builder-l4-s0/tests/run.py b/tasks/construct-mc-pysms-graph-builder-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-graph-builder-l4-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-pysms-graph-builder-l4-s0/tests/test.sh b/tasks/construct-mc-pysms-graph-builder-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-graph-builder-l4-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-pysms-independent-connectivity-l1-s0/environment/Dockerfile b/tasks/construct-mc-pysms-independent-connectivity-l1-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l1-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-pysms-independent-connectivity-l1-s0/environment/instance.json b/tasks/construct-mc-pysms-independent-connectivity-l1-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7a2496994aa181e61587b8f95802937fec9cb17d --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l1-s0/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 9, "required_edges": [], "max_independent_set": 4, "min_connectivity": 1, "family": "mc_pysms_independent_connectivity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-independent-connectivity-l1-s0/solution/solve.sh b/tasks/construct-mc-pysms-independent-connectivity-l1-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..266b10696d549d81ec1db10a95e1067a0f575ccd --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l1-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [4, 5], [4, 6], [4, 7], [4, 8], [5, 6], [5, 7], [5, 8], [6, 7], [6, 8], [7, 8]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-independent-connectivity-l1-s0/tests/check.py b/tasks/construct-mc-pysms-independent-connectivity-l1-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l1-s0/tests/check.py @@ -0,0 +1,151 @@ +"""Graph-existence constraints (MathConstraint pysms_* problem types, CC-BY-4.0). The answer is a graph on +the stated vertex set, plus a proper colouring when a chromatic-number upper bound is asked for. Every +constraint present in the instance is checked exactly (no stored answer is compared). + +Upstream note: upstream verifies by fixing the edge variables in the pysms CNF and calling CaDiCaL; the +min-chromatic-number bound of pysms_graph_builder is only a raw smsg solver parameter, not a clause, so the +upstream verifier ignored it. It is enforced here. Edge endpoints are also type-checked (upstream accepted +floats/bools that compare in range).""" +import itertools + +from run import Invalid, int_list + + +def _has_clique(adj, n, k): + def rec(cand, size): + if size == k: + return True + while cand: + if size + bin(cand).count("1") < k: + return False + v = cand.bit_length() - 1 + cand &= ~(1 << v) + if rec(cand & adj[v], size + 1): + return True + return False + return rec((1 << n) - 1, 0) + + +def _connected(adj, n, removed): + alive = [v for v in range(n) if not removed >> v & 1] + if len(alive) <= 1: + return True + mask = sum(1 << v for v in alive) + seen = 1 << alive[0] + stack = [alive[0]] + while stack: + v = stack.pop() + new = adj[v] & mask & ~seen + seen |= new + while new: + u = new.bit_length() - 1 + new &= ~(1 << u) + stack.append(u) + return seen == mask + + +def _girth(adj, n): + best = None + for r in range(n): + dist, par, q = {r: 0}, {r: -1}, [r] + for v in q: + nb = adj[v] + while nb: + u = nb.bit_length() - 1 + nb &= ~(1 << u) + if u not in dist: + dist[u], par[u] = dist[v] + 1, v + q.append(u) + elif par[v] != u: + c = dist[u] + dist[v] + 1 + best = c if best is None else min(best, c) + return best # None = acyclic + + +def _colourable(adj, n, k): + col = [-1] * n + order = sorted(range(n), key=lambda v: -bin(adj[v]).count("1")) + + def rec(i): + if i == n: + return True + v = order[i] + used = {col[u] for u in range(n) if adj[v] >> u & 1 and col[u] >= 0} + for c in range(k): + if c not in used: + col[v] = c + if rec(i + 1): + return True + col[v] = -1 + return False + return rec(0) + + +def check(inst, ans): + n = inst["vertices"] + E = ans.get("edges") + if not isinstance(E, list): + raise Invalid("edges must be a list of [u, v] pairs") + edges = set() + for e in E: + u, v = int_list(e, 2, 0, n - 1, "edge") + if u == v: + raise Invalid(f"self-loop at {u}") + e2 = (min(u, v), max(u, v)) + if e2 in edges: + raise Invalid(f"duplicate edge {e2}") + edges.add(e2) + adj = [0] * n + for u, v in edges: + adj[u] |= 1 << v + adj[v] |= 1 << u + deg = [bin(a).count("1") for a in adj] + for u, v in inst.get("required_edges", []): + if (min(u, v), max(u, v)) not in edges: + raise Invalid(f"required edge ({u},{v}) is missing") + c = inst.get + if c("min_degree") is not None and min(deg) < c("min_degree"): + raise Invalid(f"minimum degree {min(deg)} < {c('min_degree')}") + if c("max_degree") is not None and max(deg) > c("max_degree"): + raise Invalid(f"maximum degree {max(deg)} > {c('max_degree')}") + if c("min_edges") is not None and len(edges) < c("min_edges"): + raise Invalid(f"{len(edges)} edges < {c('min_edges')}") + if c("max_edges") is not None and len(edges) > c("max_edges"): + raise Invalid(f"{len(edges)} edges > {c('max_edges')}") + if c("max_clique") is not None and _has_clique(adj, n, c("max_clique") + 1): + raise Invalid(f"graph contains a clique of size {c('max_clique') + 1}") + if c("max_independent_set") is not None: + full = (1 << n) - 1 + comp = [full & ~adj[v] & ~(1 << v) for v in range(n)] + if _has_clique(comp, n, c("max_independent_set") + 1): + raise Invalid(f"graph contains an independent set of size {c('max_independent_set') + 1}") + if c("min_girth") is not None: + g = _girth(adj, n) + if g is not None and g < c("min_girth"): + raise Invalid(f"graph has a cycle of length {g} < {c('min_girth')}") + if c("min_connectivity") is not None: + k = c("min_connectivity") + if n <= k: + raise Invalid("too few vertices for this connectivity") + for s in range(k): + for I in itertools.combinations(range(n), s): + if not _connected(adj, n, sum(1 << v for v in I)): + raise Invalid(f"deleting vertices {list(I)} disconnects the graph") + if c("mtf"): + for u, v in itertools.combinations(range(n), 2): + if adj[u] >> v & 1: + if adj[u] & adj[v]: + raise Invalid(f"triangle on edge ({u},{v})") + elif not adj[u] & adj[v]: + raise Invalid(f"non-adjacent {u}, {v} have no common neighbour (edge could be added)") + if c("max_chromatic_number") is not None: + k = c("max_chromatic_number") + col = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in edges: + if col[u] == col[v]: + raise Invalid(f"coloring: edge ({u},{v}) is monochromatic") + if c("min_chromatic_number") is not None and c("min_chromatic_number") >= 2: + m = c("min_chromatic_number") + if not edges or _colourable(adj, n, m - 1): + raise Invalid(f"graph is {m - 1}-colourable, chromatic number must be at least {m}") + return None, {"num_edges": len(edges)} diff --git a/tasks/construct-mc-pysms-independent-connectivity-l1-s0/tests/instance.json b/tasks/construct-mc-pysms-independent-connectivity-l1-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7a2496994aa181e61587b8f95802937fec9cb17d --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l1-s0/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 9, "required_edges": [], "max_independent_set": 4, "min_connectivity": 1, "family": "mc_pysms_independent_connectivity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-independent-connectivity-l1-s0/tests/run.py b/tasks/construct-mc-pysms-independent-connectivity-l1-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l1-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-pysms-independent-connectivity-l1-s0/tests/test.sh b/tasks/construct-mc-pysms-independent-connectivity-l1-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l1-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-pysms-independent-connectivity-l5-s1/environment/Dockerfile b/tasks/construct-mc-pysms-independent-connectivity-l5-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l5-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-pysms-independent-connectivity-l5-s1/environment/instance.json b/tasks/construct-mc-pysms-independent-connectivity-l5-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6b6e2f1be59ea6979e7f9a0f4eab101e24624212 --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l5-s1/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 21, "required_edges": [], "max_independent_set": 4, "min_connectivity": 4, "family": "mc_pysms_independent_connectivity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-independent-connectivity-l5-s1/solution/solve.sh b/tasks/construct-mc-pysms-independent-connectivity-l5-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..42eaa361fbd18e556f860876e257ca5b3cd5001f --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l5-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [0, 14], [0, 15], [0, 16], [0, 17], [0, 18], [0, 19], [0, 20], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 20], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [3, 14], [3, 15], [3, 16], [3, 17], [3, 18], [3, 19], [3, 20], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [4, 13], [4, 14], [4, 15], [4, 16], [4, 17], [4, 18], [4, 19], [4, 20], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 13], [5, 14], [5, 15], [5, 16], [5, 17], [5, 18], [5, 19], [5, 20], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [6, 14], [6, 15], [6, 16], [6, 17], [6, 18], [6, 19], [6, 20], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [7, 13], [7, 14], [7, 15], [7, 16], [7, 17], [7, 18], [7, 19], [7, 20], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [8, 14], [8, 15], [8, 16], [8, 17], [8, 18], [8, 19], [8, 20], [9, 10], [9, 11], [9, 12], [9, 13], [9, 14], [9, 15], [9, 16], [9, 17], [9, 18], [9, 19], [9, 20], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [10, 16], [10, 17], [10, 18], [10, 19], [10, 20], [11, 12], [11, 13], [11, 14], [11, 15], [11, 16], [11, 17], [11, 18], [11, 19], [11, 20], [12, 13], [12, 14], [12, 15], [12, 16], [12, 17], [12, 18], [12, 19], [12, 20], [13, 14], [13, 15], [13, 16], [13, 17], [13, 18], [13, 19], [13, 20], [14, 15], [14, 16], [14, 17], [14, 18], [14, 19], [14, 20], [15, 16], [15, 17], [15, 18], [15, 19], [15, 20], [16, 17], [16, 18], [16, 19], [16, 20], [17, 18], [17, 19], [17, 20], [18, 19], [18, 20], [19, 20]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-independent-connectivity-l5-s1/tests/check.py b/tasks/construct-mc-pysms-independent-connectivity-l5-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l5-s1/tests/check.py @@ -0,0 +1,151 @@ +"""Graph-existence constraints (MathConstraint pysms_* problem types, CC-BY-4.0). The answer is a graph on +the stated vertex set, plus a proper colouring when a chromatic-number upper bound is asked for. Every +constraint present in the instance is checked exactly (no stored answer is compared). + +Upstream note: upstream verifies by fixing the edge variables in the pysms CNF and calling CaDiCaL; the +min-chromatic-number bound of pysms_graph_builder is only a raw smsg solver parameter, not a clause, so the +upstream verifier ignored it. It is enforced here. Edge endpoints are also type-checked (upstream accepted +floats/bools that compare in range).""" +import itertools + +from run import Invalid, int_list + + +def _has_clique(adj, n, k): + def rec(cand, size): + if size == k: + return True + while cand: + if size + bin(cand).count("1") < k: + return False + v = cand.bit_length() - 1 + cand &= ~(1 << v) + if rec(cand & adj[v], size + 1): + return True + return False + return rec((1 << n) - 1, 0) + + +def _connected(adj, n, removed): + alive = [v for v in range(n) if not removed >> v & 1] + if len(alive) <= 1: + return True + mask = sum(1 << v for v in alive) + seen = 1 << alive[0] + stack = [alive[0]] + while stack: + v = stack.pop() + new = adj[v] & mask & ~seen + seen |= new + while new: + u = new.bit_length() - 1 + new &= ~(1 << u) + stack.append(u) + return seen == mask + + +def _girth(adj, n): + best = None + for r in range(n): + dist, par, q = {r: 0}, {r: -1}, [r] + for v in q: + nb = adj[v] + while nb: + u = nb.bit_length() - 1 + nb &= ~(1 << u) + if u not in dist: + dist[u], par[u] = dist[v] + 1, v + q.append(u) + elif par[v] != u: + c = dist[u] + dist[v] + 1 + best = c if best is None else min(best, c) + return best # None = acyclic + + +def _colourable(adj, n, k): + col = [-1] * n + order = sorted(range(n), key=lambda v: -bin(adj[v]).count("1")) + + def rec(i): + if i == n: + return True + v = order[i] + used = {col[u] for u in range(n) if adj[v] >> u & 1 and col[u] >= 0} + for c in range(k): + if c not in used: + col[v] = c + if rec(i + 1): + return True + col[v] = -1 + return False + return rec(0) + + +def check(inst, ans): + n = inst["vertices"] + E = ans.get("edges") + if not isinstance(E, list): + raise Invalid("edges must be a list of [u, v] pairs") + edges = set() + for e in E: + u, v = int_list(e, 2, 0, n - 1, "edge") + if u == v: + raise Invalid(f"self-loop at {u}") + e2 = (min(u, v), max(u, v)) + if e2 in edges: + raise Invalid(f"duplicate edge {e2}") + edges.add(e2) + adj = [0] * n + for u, v in edges: + adj[u] |= 1 << v + adj[v] |= 1 << u + deg = [bin(a).count("1") for a in adj] + for u, v in inst.get("required_edges", []): + if (min(u, v), max(u, v)) not in edges: + raise Invalid(f"required edge ({u},{v}) is missing") + c = inst.get + if c("min_degree") is not None and min(deg) < c("min_degree"): + raise Invalid(f"minimum degree {min(deg)} < {c('min_degree')}") + if c("max_degree") is not None and max(deg) > c("max_degree"): + raise Invalid(f"maximum degree {max(deg)} > {c('max_degree')}") + if c("min_edges") is not None and len(edges) < c("min_edges"): + raise Invalid(f"{len(edges)} edges < {c('min_edges')}") + if c("max_edges") is not None and len(edges) > c("max_edges"): + raise Invalid(f"{len(edges)} edges > {c('max_edges')}") + if c("max_clique") is not None and _has_clique(adj, n, c("max_clique") + 1): + raise Invalid(f"graph contains a clique of size {c('max_clique') + 1}") + if c("max_independent_set") is not None: + full = (1 << n) - 1 + comp = [full & ~adj[v] & ~(1 << v) for v in range(n)] + if _has_clique(comp, n, c("max_independent_set") + 1): + raise Invalid(f"graph contains an independent set of size {c('max_independent_set') + 1}") + if c("min_girth") is not None: + g = _girth(adj, n) + if g is not None and g < c("min_girth"): + raise Invalid(f"graph has a cycle of length {g} < {c('min_girth')}") + if c("min_connectivity") is not None: + k = c("min_connectivity") + if n <= k: + raise Invalid("too few vertices for this connectivity") + for s in range(k): + for I in itertools.combinations(range(n), s): + if not _connected(adj, n, sum(1 << v for v in I)): + raise Invalid(f"deleting vertices {list(I)} disconnects the graph") + if c("mtf"): + for u, v in itertools.combinations(range(n), 2): + if adj[u] >> v & 1: + if adj[u] & adj[v]: + raise Invalid(f"triangle on edge ({u},{v})") + elif not adj[u] & adj[v]: + raise Invalid(f"non-adjacent {u}, {v} have no common neighbour (edge could be added)") + if c("max_chromatic_number") is not None: + k = c("max_chromatic_number") + col = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in edges: + if col[u] == col[v]: + raise Invalid(f"coloring: edge ({u},{v}) is monochromatic") + if c("min_chromatic_number") is not None and c("min_chromatic_number") >= 2: + m = c("min_chromatic_number") + if not edges or _colourable(adj, n, m - 1): + raise Invalid(f"graph is {m - 1}-colourable, chromatic number must be at least {m}") + return None, {"num_edges": len(edges)} diff --git a/tasks/construct-mc-pysms-independent-connectivity-l5-s1/tests/instance.json b/tasks/construct-mc-pysms-independent-connectivity-l5-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6b6e2f1be59ea6979e7f9a0f4eab101e24624212 --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l5-s1/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 21, "required_edges": [], "max_independent_set": 4, "min_connectivity": 4, "family": "mc_pysms_independent_connectivity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-independent-connectivity-l5-s1/tests/run.py b/tasks/construct-mc-pysms-independent-connectivity-l5-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l5-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-pysms-independent-connectivity-l5-s1/tests/test.sh b/tasks/construct-mc-pysms-independent-connectivity-l5-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l5-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-pysms-min-connectivity-l3-s1/environment/Dockerfile b/tasks/construct-mc-pysms-min-connectivity-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-l3-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-pysms-min-connectivity-l3-s1/environment/instance.json b/tasks/construct-mc-pysms-min-connectivity-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7be54563c6df62b1ec37756236b95cedfd5e50c6 --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 16, "required_edges": [[5, 13], [8, 15], [1, 4], [0, 4], [8, 10], [0, 15], [3, 10], [7, 12], [10, 15], [3, 7], [4, 5], [2, 9], [0, 9], [3, 15], [0, 10], [6, 9], [3, 5], [3, 4], [1, 14], [6, 8], [10, 11], [3, 14], [4, 6], [7, 9]], "min_connectivity": 2, "family": "mc_pysms_min_connectivity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-min-connectivity-l3-s1/solution/solve.sh b/tasks/construct-mc-pysms-min-connectivity-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4b8141dfb1b77c83fdaab714902ed360207c54d0 --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-l3-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [0, 14], [0, 15], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 15], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 15], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [3, 14], [3, 15], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [4, 13], [4, 14], [4, 15], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 13], [5, 14], [5, 15], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [6, 14], [6, 15], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [7, 13], [7, 14], [7, 15], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [8, 14], [8, 15], [9, 10], [9, 11], [9, 12], [9, 13], [9, 14], [9, 15], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [11, 12], [11, 13], [11, 14], [11, 15], [12, 13], [12, 14], [12, 15], [13, 14], [13, 15], [14, 15]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-min-connectivity-l3-s1/tests/check.py b/tasks/construct-mc-pysms-min-connectivity-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-l3-s1/tests/check.py @@ -0,0 +1,151 @@ +"""Graph-existence constraints (MathConstraint pysms_* problem types, CC-BY-4.0). The answer is a graph on +the stated vertex set, plus a proper colouring when a chromatic-number upper bound is asked for. Every +constraint present in the instance is checked exactly (no stored answer is compared). + +Upstream note: upstream verifies by fixing the edge variables in the pysms CNF and calling CaDiCaL; the +min-chromatic-number bound of pysms_graph_builder is only a raw smsg solver parameter, not a clause, so the +upstream verifier ignored it. It is enforced here. Edge endpoints are also type-checked (upstream accepted +floats/bools that compare in range).""" +import itertools + +from run import Invalid, int_list + + +def _has_clique(adj, n, k): + def rec(cand, size): + if size == k: + return True + while cand: + if size + bin(cand).count("1") < k: + return False + v = cand.bit_length() - 1 + cand &= ~(1 << v) + if rec(cand & adj[v], size + 1): + return True + return False + return rec((1 << n) - 1, 0) + + +def _connected(adj, n, removed): + alive = [v for v in range(n) if not removed >> v & 1] + if len(alive) <= 1: + return True + mask = sum(1 << v for v in alive) + seen = 1 << alive[0] + stack = [alive[0]] + while stack: + v = stack.pop() + new = adj[v] & mask & ~seen + seen |= new + while new: + u = new.bit_length() - 1 + new &= ~(1 << u) + stack.append(u) + return seen == mask + + +def _girth(adj, n): + best = None + for r in range(n): + dist, par, q = {r: 0}, {r: -1}, [r] + for v in q: + nb = adj[v] + while nb: + u = nb.bit_length() - 1 + nb &= ~(1 << u) + if u not in dist: + dist[u], par[u] = dist[v] + 1, v + q.append(u) + elif par[v] != u: + c = dist[u] + dist[v] + 1 + best = c if best is None else min(best, c) + return best # None = acyclic + + +def _colourable(adj, n, k): + col = [-1] * n + order = sorted(range(n), key=lambda v: -bin(adj[v]).count("1")) + + def rec(i): + if i == n: + return True + v = order[i] + used = {col[u] for u in range(n) if adj[v] >> u & 1 and col[u] >= 0} + for c in range(k): + if c not in used: + col[v] = c + if rec(i + 1): + return True + col[v] = -1 + return False + return rec(0) + + +def check(inst, ans): + n = inst["vertices"] + E = ans.get("edges") + if not isinstance(E, list): + raise Invalid("edges must be a list of [u, v] pairs") + edges = set() + for e in E: + u, v = int_list(e, 2, 0, n - 1, "edge") + if u == v: + raise Invalid(f"self-loop at {u}") + e2 = (min(u, v), max(u, v)) + if e2 in edges: + raise Invalid(f"duplicate edge {e2}") + edges.add(e2) + adj = [0] * n + for u, v in edges: + adj[u] |= 1 << v + adj[v] |= 1 << u + deg = [bin(a).count("1") for a in adj] + for u, v in inst.get("required_edges", []): + if (min(u, v), max(u, v)) not in edges: + raise Invalid(f"required edge ({u},{v}) is missing") + c = inst.get + if c("min_degree") is not None and min(deg) < c("min_degree"): + raise Invalid(f"minimum degree {min(deg)} < {c('min_degree')}") + if c("max_degree") is not None and max(deg) > c("max_degree"): + raise Invalid(f"maximum degree {max(deg)} > {c('max_degree')}") + if c("min_edges") is not None and len(edges) < c("min_edges"): + raise Invalid(f"{len(edges)} edges < {c('min_edges')}") + if c("max_edges") is not None and len(edges) > c("max_edges"): + raise Invalid(f"{len(edges)} edges > {c('max_edges')}") + if c("max_clique") is not None and _has_clique(adj, n, c("max_clique") + 1): + raise Invalid(f"graph contains a clique of size {c('max_clique') + 1}") + if c("max_independent_set") is not None: + full = (1 << n) - 1 + comp = [full & ~adj[v] & ~(1 << v) for v in range(n)] + if _has_clique(comp, n, c("max_independent_set") + 1): + raise Invalid(f"graph contains an independent set of size {c('max_independent_set') + 1}") + if c("min_girth") is not None: + g = _girth(adj, n) + if g is not None and g < c("min_girth"): + raise Invalid(f"graph has a cycle of length {g} < {c('min_girth')}") + if c("min_connectivity") is not None: + k = c("min_connectivity") + if n <= k: + raise Invalid("too few vertices for this connectivity") + for s in range(k): + for I in itertools.combinations(range(n), s): + if not _connected(adj, n, sum(1 << v for v in I)): + raise Invalid(f"deleting vertices {list(I)} disconnects the graph") + if c("mtf"): + for u, v in itertools.combinations(range(n), 2): + if adj[u] >> v & 1: + if adj[u] & adj[v]: + raise Invalid(f"triangle on edge ({u},{v})") + elif not adj[u] & adj[v]: + raise Invalid(f"non-adjacent {u}, {v} have no common neighbour (edge could be added)") + if c("max_chromatic_number") is not None: + k = c("max_chromatic_number") + col = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in edges: + if col[u] == col[v]: + raise Invalid(f"coloring: edge ({u},{v}) is monochromatic") + if c("min_chromatic_number") is not None and c("min_chromatic_number") >= 2: + m = c("min_chromatic_number") + if not edges or _colourable(adj, n, m - 1): + raise Invalid(f"graph is {m - 1}-colourable, chromatic number must be at least {m}") + return None, {"num_edges": len(edges)} diff --git a/tasks/construct-mc-pysms-min-connectivity-l3-s1/tests/instance.json b/tasks/construct-mc-pysms-min-connectivity-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7be54563c6df62b1ec37756236b95cedfd5e50c6 --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 16, "required_edges": [[5, 13], [8, 15], [1, 4], [0, 4], [8, 10], [0, 15], [3, 10], [7, 12], [10, 15], [3, 7], [4, 5], [2, 9], [0, 9], [3, 15], [0, 10], [6, 9], [3, 5], [3, 4], [1, 14], [6, 8], [10, 11], [3, 14], [4, 6], [7, 9]], "min_connectivity": 2, "family": "mc_pysms_min_connectivity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-min-connectivity-l3-s1/tests/run.py b/tasks/construct-mc-pysms-min-connectivity-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-l3-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-pysms-min-connectivity-l3-s1/tests/test.sh b/tasks/construct-mc-pysms-min-connectivity-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-l3-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-pysms-min-girth-l1-s1/environment/Dockerfile b/tasks/construct-mc-pysms-min-girth-l1-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-min-girth-l1-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-pysms-min-girth-l1-s1/environment/instance.json b/tasks/construct-mc-pysms-min-girth-l1-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4057b3035b1ae79733aef8259099cc969772151e --- /dev/null +++ b/tasks/construct-mc-pysms-min-girth-l1-s1/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 9, "required_edges": [], "min_girth": 8, "family": "mc_pysms_min_girth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-min-girth-l1-s1/solution/solve.sh b/tasks/construct-mc-pysms-min-girth-l1-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7854c4849fdde8137da179990ebadc32b25950c0 --- /dev/null +++ b/tasks/construct-mc-pysms-min-girth-l1-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"edges": [[0, 8], [1, 8], [2, 8], [3, 8], [4, 8], [5, 8], [6, 8], [7, 8]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-min-girth-l1-s1/tests/check.py b/tasks/construct-mc-pysms-min-girth-l1-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-min-girth-l1-s1/tests/check.py @@ -0,0 +1,151 @@ +"""Graph-existence constraints (MathConstraint pysms_* problem types, CC-BY-4.0). The answer is a graph on +the stated vertex set, plus a proper colouring when a chromatic-number upper bound is asked for. Every +constraint present in the instance is checked exactly (no stored answer is compared). + +Upstream note: upstream verifies by fixing the edge variables in the pysms CNF and calling CaDiCaL; the +min-chromatic-number bound of pysms_graph_builder is only a raw smsg solver parameter, not a clause, so the +upstream verifier ignored it. It is enforced here. Edge endpoints are also type-checked (upstream accepted +floats/bools that compare in range).""" +import itertools + +from run import Invalid, int_list + + +def _has_clique(adj, n, k): + def rec(cand, size): + if size == k: + return True + while cand: + if size + bin(cand).count("1") < k: + return False + v = cand.bit_length() - 1 + cand &= ~(1 << v) + if rec(cand & adj[v], size + 1): + return True + return False + return rec((1 << n) - 1, 0) + + +def _connected(adj, n, removed): + alive = [v for v in range(n) if not removed >> v & 1] + if len(alive) <= 1: + return True + mask = sum(1 << v for v in alive) + seen = 1 << alive[0] + stack = [alive[0]] + while stack: + v = stack.pop() + new = adj[v] & mask & ~seen + seen |= new + while new: + u = new.bit_length() - 1 + new &= ~(1 << u) + stack.append(u) + return seen == mask + + +def _girth(adj, n): + best = None + for r in range(n): + dist, par, q = {r: 0}, {r: -1}, [r] + for v in q: + nb = adj[v] + while nb: + u = nb.bit_length() - 1 + nb &= ~(1 << u) + if u not in dist: + dist[u], par[u] = dist[v] + 1, v + q.append(u) + elif par[v] != u: + c = dist[u] + dist[v] + 1 + best = c if best is None else min(best, c) + return best # None = acyclic + + +def _colourable(adj, n, k): + col = [-1] * n + order = sorted(range(n), key=lambda v: -bin(adj[v]).count("1")) + + def rec(i): + if i == n: + return True + v = order[i] + used = {col[u] for u in range(n) if adj[v] >> u & 1 and col[u] >= 0} + for c in range(k): + if c not in used: + col[v] = c + if rec(i + 1): + return True + col[v] = -1 + return False + return rec(0) + + +def check(inst, ans): + n = inst["vertices"] + E = ans.get("edges") + if not isinstance(E, list): + raise Invalid("edges must be a list of [u, v] pairs") + edges = set() + for e in E: + u, v = int_list(e, 2, 0, n - 1, "edge") + if u == v: + raise Invalid(f"self-loop at {u}") + e2 = (min(u, v), max(u, v)) + if e2 in edges: + raise Invalid(f"duplicate edge {e2}") + edges.add(e2) + adj = [0] * n + for u, v in edges: + adj[u] |= 1 << v + adj[v] |= 1 << u + deg = [bin(a).count("1") for a in adj] + for u, v in inst.get("required_edges", []): + if (min(u, v), max(u, v)) not in edges: + raise Invalid(f"required edge ({u},{v}) is missing") + c = inst.get + if c("min_degree") is not None and min(deg) < c("min_degree"): + raise Invalid(f"minimum degree {min(deg)} < {c('min_degree')}") + if c("max_degree") is not None and max(deg) > c("max_degree"): + raise Invalid(f"maximum degree {max(deg)} > {c('max_degree')}") + if c("min_edges") is not None and len(edges) < c("min_edges"): + raise Invalid(f"{len(edges)} edges < {c('min_edges')}") + if c("max_edges") is not None and len(edges) > c("max_edges"): + raise Invalid(f"{len(edges)} edges > {c('max_edges')}") + if c("max_clique") is not None and _has_clique(adj, n, c("max_clique") + 1): + raise Invalid(f"graph contains a clique of size {c('max_clique') + 1}") + if c("max_independent_set") is not None: + full = (1 << n) - 1 + comp = [full & ~adj[v] & ~(1 << v) for v in range(n)] + if _has_clique(comp, n, c("max_independent_set") + 1): + raise Invalid(f"graph contains an independent set of size {c('max_independent_set') + 1}") + if c("min_girth") is not None: + g = _girth(adj, n) + if g is not None and g < c("min_girth"): + raise Invalid(f"graph has a cycle of length {g} < {c('min_girth')}") + if c("min_connectivity") is not None: + k = c("min_connectivity") + if n <= k: + raise Invalid("too few vertices for this connectivity") + for s in range(k): + for I in itertools.combinations(range(n), s): + if not _connected(adj, n, sum(1 << v for v in I)): + raise Invalid(f"deleting vertices {list(I)} disconnects the graph") + if c("mtf"): + for u, v in itertools.combinations(range(n), 2): + if adj[u] >> v & 1: + if adj[u] & adj[v]: + raise Invalid(f"triangle on edge ({u},{v})") + elif not adj[u] & adj[v]: + raise Invalid(f"non-adjacent {u}, {v} have no common neighbour (edge could be added)") + if c("max_chromatic_number") is not None: + k = c("max_chromatic_number") + col = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in edges: + if col[u] == col[v]: + raise Invalid(f"coloring: edge ({u},{v}) is monochromatic") + if c("min_chromatic_number") is not None and c("min_chromatic_number") >= 2: + m = c("min_chromatic_number") + if not edges or _colourable(adj, n, m - 1): + raise Invalid(f"graph is {m - 1}-colourable, chromatic number must be at least {m}") + return None, {"num_edges": len(edges)} diff --git a/tasks/construct-mc-pysms-min-girth-l1-s1/tests/instance.json b/tasks/construct-mc-pysms-min-girth-l1-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4057b3035b1ae79733aef8259099cc969772151e --- /dev/null +++ b/tasks/construct-mc-pysms-min-girth-l1-s1/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 9, "required_edges": [], "min_girth": 8, "family": "mc_pysms_min_girth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-min-girth-l1-s1/tests/run.py b/tasks/construct-mc-pysms-min-girth-l1-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-min-girth-l1-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-pysms-min-girth-l1-s1/tests/test.sh b/tasks/construct-mc-pysms-min-girth-l1-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-min-girth-l1-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-pysms-min-girth-l5-s0/environment/Dockerfile b/tasks/construct-mc-pysms-min-girth-l5-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-min-girth-l5-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-pysms-min-girth-l5-s0/environment/instance.json b/tasks/construct-mc-pysms-min-girth-l5-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..372b79ab1331ab08f68fb9dd30f38b32ad366f51 --- /dev/null +++ b/tasks/construct-mc-pysms-min-girth-l5-s0/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 14, "required_edges": [], "min_girth": 8, "family": "mc_pysms_min_girth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-min-girth-l5-s0/solution/solve.sh b/tasks/construct-mc-pysms-min-girth-l5-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1c4371614072d14124a1ea07a224f5e6ac83f8d9 --- /dev/null +++ b/tasks/construct-mc-pysms-min-girth-l5-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"edges": [[0, 13], [1, 13], [2, 13], [3, 13], [4, 13], [5, 13], [6, 13], [7, 13], [8, 13], [9, 13], [10, 13], [11, 13], [12, 13]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-min-girth-l5-s0/tests/check.py b/tasks/construct-mc-pysms-min-girth-l5-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-min-girth-l5-s0/tests/check.py @@ -0,0 +1,151 @@ +"""Graph-existence constraints (MathConstraint pysms_* problem types, CC-BY-4.0). The answer is a graph on +the stated vertex set, plus a proper colouring when a chromatic-number upper bound is asked for. Every +constraint present in the instance is checked exactly (no stored answer is compared). + +Upstream note: upstream verifies by fixing the edge variables in the pysms CNF and calling CaDiCaL; the +min-chromatic-number bound of pysms_graph_builder is only a raw smsg solver parameter, not a clause, so the +upstream verifier ignored it. It is enforced here. Edge endpoints are also type-checked (upstream accepted +floats/bools that compare in range).""" +import itertools + +from run import Invalid, int_list + + +def _has_clique(adj, n, k): + def rec(cand, size): + if size == k: + return True + while cand: + if size + bin(cand).count("1") < k: + return False + v = cand.bit_length() - 1 + cand &= ~(1 << v) + if rec(cand & adj[v], size + 1): + return True + return False + return rec((1 << n) - 1, 0) + + +def _connected(adj, n, removed): + alive = [v for v in range(n) if not removed >> v & 1] + if len(alive) <= 1: + return True + mask = sum(1 << v for v in alive) + seen = 1 << alive[0] + stack = [alive[0]] + while stack: + v = stack.pop() + new = adj[v] & mask & ~seen + seen |= new + while new: + u = new.bit_length() - 1 + new &= ~(1 << u) + stack.append(u) + return seen == mask + + +def _girth(adj, n): + best = None + for r in range(n): + dist, par, q = {r: 0}, {r: -1}, [r] + for v in q: + nb = adj[v] + while nb: + u = nb.bit_length() - 1 + nb &= ~(1 << u) + if u not in dist: + dist[u], par[u] = dist[v] + 1, v + q.append(u) + elif par[v] != u: + c = dist[u] + dist[v] + 1 + best = c if best is None else min(best, c) + return best # None = acyclic + + +def _colourable(adj, n, k): + col = [-1] * n + order = sorted(range(n), key=lambda v: -bin(adj[v]).count("1")) + + def rec(i): + if i == n: + return True + v = order[i] + used = {col[u] for u in range(n) if adj[v] >> u & 1 and col[u] >= 0} + for c in range(k): + if c not in used: + col[v] = c + if rec(i + 1): + return True + col[v] = -1 + return False + return rec(0) + + +def check(inst, ans): + n = inst["vertices"] + E = ans.get("edges") + if not isinstance(E, list): + raise Invalid("edges must be a list of [u, v] pairs") + edges = set() + for e in E: + u, v = int_list(e, 2, 0, n - 1, "edge") + if u == v: + raise Invalid(f"self-loop at {u}") + e2 = (min(u, v), max(u, v)) + if e2 in edges: + raise Invalid(f"duplicate edge {e2}") + edges.add(e2) + adj = [0] * n + for u, v in edges: + adj[u] |= 1 << v + adj[v] |= 1 << u + deg = [bin(a).count("1") for a in adj] + for u, v in inst.get("required_edges", []): + if (min(u, v), max(u, v)) not in edges: + raise Invalid(f"required edge ({u},{v}) is missing") + c = inst.get + if c("min_degree") is not None and min(deg) < c("min_degree"): + raise Invalid(f"minimum degree {min(deg)} < {c('min_degree')}") + if c("max_degree") is not None and max(deg) > c("max_degree"): + raise Invalid(f"maximum degree {max(deg)} > {c('max_degree')}") + if c("min_edges") is not None and len(edges) < c("min_edges"): + raise Invalid(f"{len(edges)} edges < {c('min_edges')}") + if c("max_edges") is not None and len(edges) > c("max_edges"): + raise Invalid(f"{len(edges)} edges > {c('max_edges')}") + if c("max_clique") is not None and _has_clique(adj, n, c("max_clique") + 1): + raise Invalid(f"graph contains a clique of size {c('max_clique') + 1}") + if c("max_independent_set") is not None: + full = (1 << n) - 1 + comp = [full & ~adj[v] & ~(1 << v) for v in range(n)] + if _has_clique(comp, n, c("max_independent_set") + 1): + raise Invalid(f"graph contains an independent set of size {c('max_independent_set') + 1}") + if c("min_girth") is not None: + g = _girth(adj, n) + if g is not None and g < c("min_girth"): + raise Invalid(f"graph has a cycle of length {g} < {c('min_girth')}") + if c("min_connectivity") is not None: + k = c("min_connectivity") + if n <= k: + raise Invalid("too few vertices for this connectivity") + for s in range(k): + for I in itertools.combinations(range(n), s): + if not _connected(adj, n, sum(1 << v for v in I)): + raise Invalid(f"deleting vertices {list(I)} disconnects the graph") + if c("mtf"): + for u, v in itertools.combinations(range(n), 2): + if adj[u] >> v & 1: + if adj[u] & adj[v]: + raise Invalid(f"triangle on edge ({u},{v})") + elif not adj[u] & adj[v]: + raise Invalid(f"non-adjacent {u}, {v} have no common neighbour (edge could be added)") + if c("max_chromatic_number") is not None: + k = c("max_chromatic_number") + col = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in edges: + if col[u] == col[v]: + raise Invalid(f"coloring: edge ({u},{v}) is monochromatic") + if c("min_chromatic_number") is not None and c("min_chromatic_number") >= 2: + m = c("min_chromatic_number") + if not edges or _colourable(adj, n, m - 1): + raise Invalid(f"graph is {m - 1}-colourable, chromatic number must be at least {m}") + return None, {"num_edges": len(edges)} diff --git a/tasks/construct-mc-pysms-min-girth-l5-s0/tests/instance.json b/tasks/construct-mc-pysms-min-girth-l5-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..372b79ab1331ab08f68fb9dd30f38b32ad366f51 --- /dev/null +++ b/tasks/construct-mc-pysms-min-girth-l5-s0/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 14, "required_edges": [], "min_girth": 8, "family": "mc_pysms_min_girth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-min-girth-l5-s0/tests/run.py b/tasks/construct-mc-pysms-min-girth-l5-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-min-girth-l5-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-pysms-min-girth-l5-s0/tests/test.sh b/tasks/construct-mc-pysms-min-girth-l5-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-min-girth-l5-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-pysms-num-edges-bounds-l3-s0/environment/Dockerfile b/tasks/construct-mc-pysms-num-edges-bounds-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-num-edges-bounds-l3-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-pysms-num-edges-bounds-l3-s0/environment/instance.json b/tasks/construct-mc-pysms-num-edges-bounds-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..72d4fd3e8dd499028bd2c48f78d028306f855f02 --- /dev/null +++ b/tasks/construct-mc-pysms-num-edges-bounds-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 11, "required_edges": [], "max_edges": 36, "min_edges": 30, "family": "mc_pysms_num_edges_bounds", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-num-edges-bounds-l3-s0/solution/solve.sh b/tasks/construct-mc-pysms-num-edges-bounds-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2da9b6f99704082f573e361e18c95a5efbdb7c51 --- /dev/null +++ b/tasks/construct-mc-pysms-num-edges-bounds-l3-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"edges": [[0, 7], [0, 8], [0, 9], [0, 10], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [3, 4], [3, 5], [3, 6], [4, 5], [4, 6], [4, 9], [4, 10], [5, 6], [5, 8], [5, 9], [5, 10], [6, 8], [6, 9], [6, 10], [7, 8], [7, 10]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-num-edges-bounds-l3-s0/tests/check.py b/tasks/construct-mc-pysms-num-edges-bounds-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-num-edges-bounds-l3-s0/tests/check.py @@ -0,0 +1,151 @@ +"""Graph-existence constraints (MathConstraint pysms_* problem types, CC-BY-4.0). The answer is a graph on +the stated vertex set, plus a proper colouring when a chromatic-number upper bound is asked for. Every +constraint present in the instance is checked exactly (no stored answer is compared). + +Upstream note: upstream verifies by fixing the edge variables in the pysms CNF and calling CaDiCaL; the +min-chromatic-number bound of pysms_graph_builder is only a raw smsg solver parameter, not a clause, so the +upstream verifier ignored it. It is enforced here. Edge endpoints are also type-checked (upstream accepted +floats/bools that compare in range).""" +import itertools + +from run import Invalid, int_list + + +def _has_clique(adj, n, k): + def rec(cand, size): + if size == k: + return True + while cand: + if size + bin(cand).count("1") < k: + return False + v = cand.bit_length() - 1 + cand &= ~(1 << v) + if rec(cand & adj[v], size + 1): + return True + return False + return rec((1 << n) - 1, 0) + + +def _connected(adj, n, removed): + alive = [v for v in range(n) if not removed >> v & 1] + if len(alive) <= 1: + return True + mask = sum(1 << v for v in alive) + seen = 1 << alive[0] + stack = [alive[0]] + while stack: + v = stack.pop() + new = adj[v] & mask & ~seen + seen |= new + while new: + u = new.bit_length() - 1 + new &= ~(1 << u) + stack.append(u) + return seen == mask + + +def _girth(adj, n): + best = None + for r in range(n): + dist, par, q = {r: 0}, {r: -1}, [r] + for v in q: + nb = adj[v] + while nb: + u = nb.bit_length() - 1 + nb &= ~(1 << u) + if u not in dist: + dist[u], par[u] = dist[v] + 1, v + q.append(u) + elif par[v] != u: + c = dist[u] + dist[v] + 1 + best = c if best is None else min(best, c) + return best # None = acyclic + + +def _colourable(adj, n, k): + col = [-1] * n + order = sorted(range(n), key=lambda v: -bin(adj[v]).count("1")) + + def rec(i): + if i == n: + return True + v = order[i] + used = {col[u] for u in range(n) if adj[v] >> u & 1 and col[u] >= 0} + for c in range(k): + if c not in used: + col[v] = c + if rec(i + 1): + return True + col[v] = -1 + return False + return rec(0) + + +def check(inst, ans): + n = inst["vertices"] + E = ans.get("edges") + if not isinstance(E, list): + raise Invalid("edges must be a list of [u, v] pairs") + edges = set() + for e in E: + u, v = int_list(e, 2, 0, n - 1, "edge") + if u == v: + raise Invalid(f"self-loop at {u}") + e2 = (min(u, v), max(u, v)) + if e2 in edges: + raise Invalid(f"duplicate edge {e2}") + edges.add(e2) + adj = [0] * n + for u, v in edges: + adj[u] |= 1 << v + adj[v] |= 1 << u + deg = [bin(a).count("1") for a in adj] + for u, v in inst.get("required_edges", []): + if (min(u, v), max(u, v)) not in edges: + raise Invalid(f"required edge ({u},{v}) is missing") + c = inst.get + if c("min_degree") is not None and min(deg) < c("min_degree"): + raise Invalid(f"minimum degree {min(deg)} < {c('min_degree')}") + if c("max_degree") is not None and max(deg) > c("max_degree"): + raise Invalid(f"maximum degree {max(deg)} > {c('max_degree')}") + if c("min_edges") is not None and len(edges) < c("min_edges"): + raise Invalid(f"{len(edges)} edges < {c('min_edges')}") + if c("max_edges") is not None and len(edges) > c("max_edges"): + raise Invalid(f"{len(edges)} edges > {c('max_edges')}") + if c("max_clique") is not None and _has_clique(adj, n, c("max_clique") + 1): + raise Invalid(f"graph contains a clique of size {c('max_clique') + 1}") + if c("max_independent_set") is not None: + full = (1 << n) - 1 + comp = [full & ~adj[v] & ~(1 << v) for v in range(n)] + if _has_clique(comp, n, c("max_independent_set") + 1): + raise Invalid(f"graph contains an independent set of size {c('max_independent_set') + 1}") + if c("min_girth") is not None: + g = _girth(adj, n) + if g is not None and g < c("min_girth"): + raise Invalid(f"graph has a cycle of length {g} < {c('min_girth')}") + if c("min_connectivity") is not None: + k = c("min_connectivity") + if n <= k: + raise Invalid("too few vertices for this connectivity") + for s in range(k): + for I in itertools.combinations(range(n), s): + if not _connected(adj, n, sum(1 << v for v in I)): + raise Invalid(f"deleting vertices {list(I)} disconnects the graph") + if c("mtf"): + for u, v in itertools.combinations(range(n), 2): + if adj[u] >> v & 1: + if adj[u] & adj[v]: + raise Invalid(f"triangle on edge ({u},{v})") + elif not adj[u] & adj[v]: + raise Invalid(f"non-adjacent {u}, {v} have no common neighbour (edge could be added)") + if c("max_chromatic_number") is not None: + k = c("max_chromatic_number") + col = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in edges: + if col[u] == col[v]: + raise Invalid(f"coloring: edge ({u},{v}) is monochromatic") + if c("min_chromatic_number") is not None and c("min_chromatic_number") >= 2: + m = c("min_chromatic_number") + if not edges or _colourable(adj, n, m - 1): + raise Invalid(f"graph is {m - 1}-colourable, chromatic number must be at least {m}") + return None, {"num_edges": len(edges)} diff --git a/tasks/construct-mc-pysms-num-edges-bounds-l3-s0/tests/instance.json b/tasks/construct-mc-pysms-num-edges-bounds-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..72d4fd3e8dd499028bd2c48f78d028306f855f02 --- /dev/null +++ b/tasks/construct-mc-pysms-num-edges-bounds-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 11, "required_edges": [], "max_edges": 36, "min_edges": 30, "family": "mc_pysms_num_edges_bounds", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-num-edges-bounds-l3-s0/tests/run.py b/tasks/construct-mc-pysms-num-edges-bounds-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-num-edges-bounds-l3-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-pysms-num-edges-bounds-l3-s0/tests/test.sh b/tasks/construct-mc-pysms-num-edges-bounds-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-num-edges-bounds-l3-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-ramsey-l1-s1/environment/Dockerfile b/tasks/construct-mc-ramsey-l1-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-ramsey-l1-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-ramsey-l1-s1/environment/instance.json b/tasks/construct-mc-ramsey-l1-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f530c653ba75289a3485f30f08187d737a012c0d --- /dev/null +++ b/tasks/construct-mc-ramsey-l1-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 6, "r": 4, "s": 3, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l1-s1/solution/solve.sh b/tasks/construct-mc-ramsey-l1-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..54ad8d31419a40c695c8dbafa4b9686e16b17fcc --- /dev/null +++ b/tasks/construct-mc-ramsey-l1-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-ramsey-l1-s1/tests/check.py b/tasks/construct-mc-ramsey-l1-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..53526c0bc87af6298219d3e1eac5f95f01b57541 --- /dev/null +++ b/tasks/construct-mc-ramsey-l1-s1/tests/check.py @@ -0,0 +1,31 @@ +"""Two-colouring of the edges of K_n with no colour-0 K_r and no colour-1 K_s (MathConstraint ramsey, +CC-BY-4.0). Adapted from pilot/grader.py check_ramsey; adds the optional fixed edge colours.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, r, s = inst["n"], inst["r"], inst["s"] + edges = list(itertools.combinations(range(n), 2)) + col = int_list(ans.get("colors"), len(edges), 0, 1, "colors") + for name, i, v in inst.get("fixed", []): + if col[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + c = {e: col[i] for i, e in enumerate(edges)} + for k, colour in ((r, 0), (s, 1)): + adj = {v: {u for u in range(n) if u != v and c[(min(u, v), max(u, v))] == colour} for v in range(n)} + + def grow(size, cand): + if size == k: + return True + if size + len(cand) < k: + return False + for v in sorted(cand): + if grow(size + 1, {u for u in cand if u > v} & adj[v]): + return True + return False + + if grow(0, set(range(n))): + raise Invalid(f"monochromatic K_{k} in colour {colour}") + return None, {} diff --git a/tasks/construct-mc-ramsey-l1-s1/tests/instance.json b/tasks/construct-mc-ramsey-l1-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f530c653ba75289a3485f30f08187d737a012c0d --- /dev/null +++ b/tasks/construct-mc-ramsey-l1-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 6, "r": 4, "s": 3, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l1-s1/tests/run.py b/tasks/construct-mc-ramsey-l1-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-ramsey-l1-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-ramsey-l1-s1/tests/test.sh b/tasks/construct-mc-ramsey-l1-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-ramsey-l1-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-ramsey-l1-s6/environment/Dockerfile b/tasks/construct-mc-ramsey-l1-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-ramsey-l1-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-ramsey-l1-s6/environment/instance.json b/tasks/construct-mc-ramsey-l1-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..06c74121cd6d8815e966653e5159fb3e74108855 --- /dev/null +++ b/tasks/construct-mc-ramsey-l1-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 7, "r": 4, "s": 3, "fixed": [["colors", 3, 0], ["colors", 7, 0], ["colors", 12, 0], ["colors", 18, 0]], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l1-s6/solution/solve.sh b/tasks/construct-mc-ramsey-l1-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ae18cc1d6985bc9d7542801275f11ee433d2c470 --- /dev/null +++ b/tasks/construct-mc-ramsey-l1-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-ramsey-l1-s6/tests/check.py b/tasks/construct-mc-ramsey-l1-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..53526c0bc87af6298219d3e1eac5f95f01b57541 --- /dev/null +++ b/tasks/construct-mc-ramsey-l1-s6/tests/check.py @@ -0,0 +1,31 @@ +"""Two-colouring of the edges of K_n with no colour-0 K_r and no colour-1 K_s (MathConstraint ramsey, +CC-BY-4.0). Adapted from pilot/grader.py check_ramsey; adds the optional fixed edge colours.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, r, s = inst["n"], inst["r"], inst["s"] + edges = list(itertools.combinations(range(n), 2)) + col = int_list(ans.get("colors"), len(edges), 0, 1, "colors") + for name, i, v in inst.get("fixed", []): + if col[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + c = {e: col[i] for i, e in enumerate(edges)} + for k, colour in ((r, 0), (s, 1)): + adj = {v: {u for u in range(n) if u != v and c[(min(u, v), max(u, v))] == colour} for v in range(n)} + + def grow(size, cand): + if size == k: + return True + if size + len(cand) < k: + return False + for v in sorted(cand): + if grow(size + 1, {u for u in cand if u > v} & adj[v]): + return True + return False + + if grow(0, set(range(n))): + raise Invalid(f"monochromatic K_{k} in colour {colour}") + return None, {} diff --git a/tasks/construct-mc-ramsey-l1-s6/tests/instance.json b/tasks/construct-mc-ramsey-l1-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..06c74121cd6d8815e966653e5159fb3e74108855 --- /dev/null +++ b/tasks/construct-mc-ramsey-l1-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 7, "r": 4, "s": 3, "fixed": [["colors", 3, 0], ["colors", 7, 0], ["colors", 12, 0], ["colors", 18, 0]], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l1-s6/tests/run.py b/tasks/construct-mc-ramsey-l1-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-ramsey-l1-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-ramsey-l1-s6/tests/test.sh b/tasks/construct-mc-ramsey-l1-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-ramsey-l1-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-ramsey-l5-s0/environment/Dockerfile b/tasks/construct-mc-ramsey-l5-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-ramsey-l5-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-ramsey-l5-s0/environment/instance.json b/tasks/construct-mc-ramsey-l5-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0bcd471fb2f904c301651805aeed20b2a4635333 --- /dev/null +++ b/tasks/construct-mc-ramsey-l5-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 25, "r": 8, "s": 3, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l5-s0/solution/solve.sh b/tasks/construct-mc-ramsey-l5-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1e0b3f96fb51aff0abdf8c099dd478341eaa08e3 --- /dev/null +++ b/tasks/construct-mc-ramsey-l5-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-ramsey-l5-s0/tests/check.py b/tasks/construct-mc-ramsey-l5-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..53526c0bc87af6298219d3e1eac5f95f01b57541 --- /dev/null +++ b/tasks/construct-mc-ramsey-l5-s0/tests/check.py @@ -0,0 +1,31 @@ +"""Two-colouring of the edges of K_n with no colour-0 K_r and no colour-1 K_s (MathConstraint ramsey, +CC-BY-4.0). Adapted from pilot/grader.py check_ramsey; adds the optional fixed edge colours.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, r, s = inst["n"], inst["r"], inst["s"] + edges = list(itertools.combinations(range(n), 2)) + col = int_list(ans.get("colors"), len(edges), 0, 1, "colors") + for name, i, v in inst.get("fixed", []): + if col[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + c = {e: col[i] for i, e in enumerate(edges)} + for k, colour in ((r, 0), (s, 1)): + adj = {v: {u for u in range(n) if u != v and c[(min(u, v), max(u, v))] == colour} for v in range(n)} + + def grow(size, cand): + if size == k: + return True + if size + len(cand) < k: + return False + for v in sorted(cand): + if grow(size + 1, {u for u in cand if u > v} & adj[v]): + return True + return False + + if grow(0, set(range(n))): + raise Invalid(f"monochromatic K_{k} in colour {colour}") + return None, {} diff --git a/tasks/construct-mc-ramsey-l5-s0/tests/instance.json b/tasks/construct-mc-ramsey-l5-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0bcd471fb2f904c301651805aeed20b2a4635333 --- /dev/null +++ b/tasks/construct-mc-ramsey-l5-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 25, "r": 8, "s": 3, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l5-s0/tests/run.py b/tasks/construct-mc-ramsey-l5-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-ramsey-l5-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-ramsey-l5-s0/tests/test.sh b/tasks/construct-mc-ramsey-l5-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-ramsey-l5-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-ramsey-l5-s7/environment/Dockerfile b/tasks/construct-mc-ramsey-l5-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-ramsey-l5-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-ramsey-l5-s7/environment/instance.json b/tasks/construct-mc-ramsey-l5-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..592656cd01795a3c36a3f081983b7cdc946904ef --- /dev/null +++ b/tasks/construct-mc-ramsey-l5-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 23, "r": 3, "s": 8, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l5-s7/solution/solve.sh b/tasks/construct-mc-ramsey-l5-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c7b4c87c48c8a29249f456af69e4e335df831713 --- /dev/null +++ b/tasks/construct-mc-ramsey-l5-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-ramsey-l5-s7/tests/check.py b/tasks/construct-mc-ramsey-l5-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..53526c0bc87af6298219d3e1eac5f95f01b57541 --- /dev/null +++ b/tasks/construct-mc-ramsey-l5-s7/tests/check.py @@ -0,0 +1,31 @@ +"""Two-colouring of the edges of K_n with no colour-0 K_r and no colour-1 K_s (MathConstraint ramsey, +CC-BY-4.0). Adapted from pilot/grader.py check_ramsey; adds the optional fixed edge colours.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, r, s = inst["n"], inst["r"], inst["s"] + edges = list(itertools.combinations(range(n), 2)) + col = int_list(ans.get("colors"), len(edges), 0, 1, "colors") + for name, i, v in inst.get("fixed", []): + if col[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + c = {e: col[i] for i, e in enumerate(edges)} + for k, colour in ((r, 0), (s, 1)): + adj = {v: {u for u in range(n) if u != v and c[(min(u, v), max(u, v))] == colour} for v in range(n)} + + def grow(size, cand): + if size == k: + return True + if size + len(cand) < k: + return False + for v in sorted(cand): + if grow(size + 1, {u for u in cand if u > v} & adj[v]): + return True + return False + + if grow(0, set(range(n))): + raise Invalid(f"monochromatic K_{k} in colour {colour}") + return None, {} diff --git a/tasks/construct-mc-ramsey-l5-s7/tests/instance.json b/tasks/construct-mc-ramsey-l5-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..592656cd01795a3c36a3f081983b7cdc946904ef --- /dev/null +++ b/tasks/construct-mc-ramsey-l5-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 23, "r": 3, "s": 8, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l5-s7/tests/run.py b/tasks/construct-mc-ramsey-l5-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-ramsey-l5-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-ramsey-l5-s7/tests/test.sh b/tasks/construct-mc-ramsey-l5-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-ramsey-l5-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-ramsey-l5-s9/environment/Dockerfile b/tasks/construct-mc-ramsey-l5-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-ramsey-l5-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-ramsey-l5-s9/environment/instance.json b/tasks/construct-mc-ramsey-l5-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..49ac9c3f437d1df7b5287b6fe1e7f8636f51edda --- /dev/null +++ b/tasks/construct-mc-ramsey-l5-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 24, "r": 8, "s": 3, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l5-s9/solution/solve.sh b/tasks/construct-mc-ramsey-l5-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..edd6345145343d1ee5319579563c903855e0ad2b --- /dev/null +++ b/tasks/construct-mc-ramsey-l5-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-ramsey-l5-s9/tests/check.py b/tasks/construct-mc-ramsey-l5-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..53526c0bc87af6298219d3e1eac5f95f01b57541 --- /dev/null +++ b/tasks/construct-mc-ramsey-l5-s9/tests/check.py @@ -0,0 +1,31 @@ +"""Two-colouring of the edges of K_n with no colour-0 K_r and no colour-1 K_s (MathConstraint ramsey, +CC-BY-4.0). Adapted from pilot/grader.py check_ramsey; adds the optional fixed edge colours.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, r, s = inst["n"], inst["r"], inst["s"] + edges = list(itertools.combinations(range(n), 2)) + col = int_list(ans.get("colors"), len(edges), 0, 1, "colors") + for name, i, v in inst.get("fixed", []): + if col[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + c = {e: col[i] for i, e in enumerate(edges)} + for k, colour in ((r, 0), (s, 1)): + adj = {v: {u for u in range(n) if u != v and c[(min(u, v), max(u, v))] == colour} for v in range(n)} + + def grow(size, cand): + if size == k: + return True + if size + len(cand) < k: + return False + for v in sorted(cand): + if grow(size + 1, {u for u in cand if u > v} & adj[v]): + return True + return False + + if grow(0, set(range(n))): + raise Invalid(f"monochromatic K_{k} in colour {colour}") + return None, {} diff --git a/tasks/construct-mc-ramsey-l5-s9/tests/instance.json b/tasks/construct-mc-ramsey-l5-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..49ac9c3f437d1df7b5287b6fe1e7f8636f51edda --- /dev/null +++ b/tasks/construct-mc-ramsey-l5-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 24, "r": 8, "s": 3, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l5-s9/tests/run.py b/tasks/construct-mc-ramsey-l5-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-ramsey-l5-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-ramsey-l5-s9/tests/test.sh b/tasks/construct-mc-ramsey-l5-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-ramsey-l5-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-social-golfers-l4-s3/environment/Dockerfile b/tasks/construct-mc-social-golfers-l4-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-social-golfers-l4-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-social-golfers-l4-s3/environment/instance.json b/tasks/construct-mc-social-golfers-l4-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a2af0e67e730d6d152983e910ff313bd24dac3d4 --- /dev/null +++ b/tasks/construct-mc-social-golfers-l4-s3/environment/instance.json @@ -0,0 +1 @@ +{"n_groups": 10, "group_size": 4, "n_weeks": 5, "family": "mc_social_golfers", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-social-golfers-l4-s3/solution/solve.sh b/tasks/construct-mc-social-golfers-l4-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..be21f533fb8ef10a4c2ee6959ff17da7fac5a31b --- /dev/null +++ b/tasks/construct-mc-social-golfers-l4-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"schedule": [[0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9], [5, 8, 2, 3, 9, 7, 0, 1, 7, 6, 1, 0, 9, 4, 3, 5, 3, 2, 1, 4, 3, 4, 8, 7, 4, 6, 0, 1, 8, 9, 5, 2, 8, 6, 2, 0, 9, 5, 6, 7], [5, 2, 0, 7, 7, 4, 6, 3, 2, 5, 1, 3, 5, 6, 9, 7, 6, 8, 7, 4, 2, 5, 3, 0, 9, 6, 4, 8, 1, 2, 3, 4, 9, 0, 1, 8, 8, 0, 9, 1], [0, 3, 2, 1, 5, 2, 1, 7, 1, 6, 5, 4, 2, 0, 4, 3, 9, 0, 8, 6, 0, 1, 2, 9, 7, 3, 5, 6, 7, 9, 6, 8, 9, 8, 4, 7, 8, 4, 5, 3], [0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 4, 3, 1, 0, 2, 4, 3, 5, 6, 5, 4, 6, 7, 5, 6, 8, 9, 4, 9, 8, 7, 8, 9, 6, 7, 8, 5, 7, 9]]} +RLMATH_EOF diff --git a/tasks/construct-mc-social-golfers-l4-s3/tests/check.py b/tasks/construct-mc-social-golfers-l4-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..73977815b7b6094a8491075b6dc2ae1293e44930 --- /dev/null +++ b/tasks/construct-mc-social-golfers-l4-s3/tests/check.py @@ -0,0 +1,25 @@ +"""Social golfer problem (MathConstraint social_golfers, CSPLib prob010, CC-BY-4.0): each week partition +the g*s players into g groups of size s; no two players share a group in more than one week.""" +from run import Invalid, int_list + + +def check(inst, ans): + g, s, w = inst["n_groups"], inst["group_size"], inst["n_weeks"] + P = g * s + sched = ans.get("schedule") + if not isinstance(sched, list) or len(sched) != w: + raise Invalid(f"schedule must be a list of {w} weeks") + met = set() + for wk, row in enumerate(sched): + row = int_list(row, P, 0, g - 1, f"week {wk}") + groups = [[p for p in range(P) if row[p] == grp] for grp in range(g)] + for grp, mem in enumerate(groups): + if len(mem) != s: + raise Invalid(f"week {wk}: group {grp} has {len(mem)} players, need {s}") + for i in range(s): + for j in range(i + 1, s): + pr = (mem[i], mem[j]) + if pr in met: + raise Invalid(f"players {pr} play together in more than one week") + met.add(pr) + return None, {} diff --git a/tasks/construct-mc-social-golfers-l4-s3/tests/instance.json b/tasks/construct-mc-social-golfers-l4-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a2af0e67e730d6d152983e910ff313bd24dac3d4 --- /dev/null +++ b/tasks/construct-mc-social-golfers-l4-s3/tests/instance.json @@ -0,0 +1 @@ +{"n_groups": 10, "group_size": 4, "n_weeks": 5, "family": "mc_social_golfers", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-social-golfers-l4-s3/tests/run.py b/tasks/construct-mc-social-golfers-l4-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-social-golfers-l4-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-social-golfers-l4-s3/tests/test.sh b/tasks/construct-mc-social-golfers-l4-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-social-golfers-l4-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-van-der-waerden-l5-s2/environment/Dockerfile b/tasks/construct-mc-van-der-waerden-l5-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l5-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-van-der-waerden-l5-s2/environment/instance.json b/tasks/construct-mc-van-der-waerden-l5-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8489f48cb9518d1d09b111547e741a2a46e574ff --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l5-s2/environment/instance.json @@ -0,0 +1 @@ +{"k": 4, "L": 3, "n": 60, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l5-s2/solution/solve.sh b/tasks/construct-mc-van-der-waerden-l5-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f486c37c0824a75c710691eb4ea636bef3eb9540 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l5-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 1, 1, 3, 1, 3, 3, 0, 0, 2, 1, 0, 0, 3, 1, 1, 2, 2, 0, 2, 0, 0, 1, 0, 2, 3, 3, 0, 2, 3, 2, 3, 1, 2, 2, 3, 1, 0, 1, 1, 3, 1, 3, 3, 0, 0, 2, 1, 0, 0, 3, 1, 1, 2, 2, 0, 2, 0, 0, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-van-der-waerden-l5-s2/tests/check.py b/tasks/construct-mc-van-der-waerden-l5-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9853b089b6ac1773d80eac8e9e02ceb4019ad41f --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l5-s2/tests/check.py @@ -0,0 +1,15 @@ +"""k-colouring of {1..n} with no monochromatic L-term arithmetic progression (MathConstraint +van_der_waerden, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k, L = inst["n"], inst["k"], inst["L"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + for a in range(n): + for d in range(1, n): + if a + (L - 1) * d >= n: + break + if all(c[a + j * d] == c[a] for j in range(1, L)): + raise Invalid(f"monochromatic progression {[a + 1 + j * d for j in range(L)]}") + return None, {} diff --git a/tasks/construct-mc-van-der-waerden-l5-s2/tests/instance.json b/tasks/construct-mc-van-der-waerden-l5-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8489f48cb9518d1d09b111547e741a2a46e574ff --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l5-s2/tests/instance.json @@ -0,0 +1 @@ +{"k": 4, "L": 3, "n": 60, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l5-s2/tests/run.py b/tasks/construct-mc-van-der-waerden-l5-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l5-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-van-der-waerden-l5-s2/tests/test.sh b/tasks/construct-mc-van-der-waerden-l5-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l5-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-van-der-waerden-l5-s5/environment/Dockerfile b/tasks/construct-mc-van-der-waerden-l5-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l5-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-van-der-waerden-l5-s5/environment/instance.json b/tasks/construct-mc-van-der-waerden-l5-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..62106bfe24ab14260dae8daaa835ac22b5731f62 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l5-s5/environment/instance.json @@ -0,0 +1 @@ +{"k": 3, "L": 4, "n": 100, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l5-s5/solution/solve.sh b/tasks/construct-mc-van-der-waerden-l5-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e321ff093c73b0048a1af4d09ec7a583d9cb272e --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l5-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 1, 2, 2, 1, 0, 0, 0, 1, 0, 1, 2, 1, 0, 2, 0, 0, 1, 1, 1, 2, 2, 1, 0, 2, 1, 0, 0, 0, 1, 1, 1, 2, 1, 1, 2, 1, 0, 1, 2, 0, 2, 0, 2, 2, 0, 0, 1, 2, 0, 2, 2, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 2, 1, 1, 2, 1, 1, 2, 2, 2, 0, 2, 2, 0, 0, 0, 1, 1, 1, 2, 1, 2, 2, 2, 0, 1, 1, 1, 2, 2, 2, 1, 2, 2, 1, 2, 2, 2]} +RLMATH_EOF diff --git a/tasks/construct-mc-van-der-waerden-l5-s5/tests/check.py b/tasks/construct-mc-van-der-waerden-l5-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9853b089b6ac1773d80eac8e9e02ceb4019ad41f --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l5-s5/tests/check.py @@ -0,0 +1,15 @@ +"""k-colouring of {1..n} with no monochromatic L-term arithmetic progression (MathConstraint +van_der_waerden, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k, L = inst["n"], inst["k"], inst["L"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + for a in range(n): + for d in range(1, n): + if a + (L - 1) * d >= n: + break + if all(c[a + j * d] == c[a] for j in range(1, L)): + raise Invalid(f"monochromatic progression {[a + 1 + j * d for j in range(L)]}") + return None, {} diff --git a/tasks/construct-mc-van-der-waerden-l5-s5/tests/instance.json b/tasks/construct-mc-van-der-waerden-l5-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..62106bfe24ab14260dae8daaa835ac22b5731f62 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l5-s5/tests/instance.json @@ -0,0 +1 @@ +{"k": 3, "L": 4, "n": 100, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l5-s5/tests/run.py b/tasks/construct-mc-van-der-waerden-l5-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l5-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-van-der-waerden-l5-s5/tests/test.sh b/tasks/construct-mc-van-der-waerden-l5-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l5-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-vertex-cover-l4-s2/environment/Dockerfile b/tasks/construct-mc-vertex-cover-l4-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l4-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-vertex-cover-l4-s2/environment/instance.json b/tasks/construct-mc-vertex-cover-l4-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..23da08e0ff05f7cbeb21483f84c661fea2b93ed8 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l4-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 60, "k": 41, "edges": [[0, 1], [0, 3], [0, 19], [0, 25], [0, 28], [0, 41], [0, 44], [0, 56], [1, 4], [1, 17], [1, 20], [1, 26], [1, 27], [1, 31], [1, 38], [1, 49], [1, 50], [1, 51], [1, 54], [1, 58], [2, 11], [2, 12], [2, 14], [2, 16], [2, 38], [2, 39], [2, 40], [2, 48], [2, 53], [2, 55], [2, 57], [3, 7], [3, 17], [3, 24], [3, 36], [3, 44], [3, 58], [4, 5], [4, 6], [4, 14], [4, 25], [4, 31], [4, 43], [4, 51], [4, 55], [4, 57], [5, 7], [5, 20], [5, 23], [5, 41], [5, 43], [5, 44], [6, 11], [6, 17], [6, 21], [6, 56], [6, 58], [7, 13], [7, 20], [7, 26], [7, 31], [7, 34], [7, 35], [7, 40], [7, 45], [7, 48], [7, 53], [7, 54], [7, 55], [7, 58], [8, 9], [8, 14], [8, 18], [8, 19], [8, 23], [8, 32], [8, 43], [8, 46], [8, 48], [8, 50], [8, 59], [9, 13], [9, 17], [9, 19], [9, 23], [9, 33], [9, 39], [9, 41], [9, 43], [9, 45], [9, 47], [9, 56], [9, 58], [10, 12], [10, 22], [10, 24], [10, 27], [10, 35], [10, 39], [10, 42], [10, 44], [10, 50], [10, 57], [11, 13], [11, 14], [11, 17], [11, 21], [11, 25], [11, 26], [11, 31], [11, 33], [11, 35], [11, 39], [11, 54], [11, 58], [12, 27], [12, 45], [12, 56], [13, 25], [13, 29], [13, 37], [13, 41], [13, 46], [13, 50], [13, 51], [13, 54], [14, 21], [14, 25], [14, 32], [14, 40], [14, 41], [14, 44], [14, 45], [15, 16], [15, 25], [15, 31], [15, 34], [15, 38], [15, 45], [15, 46], [15, 48], [15, 49], [16, 19], [16, 28], [16, 32], [16, 53], [16, 54], [16, 57], [16, 59], [17, 20], [17, 34], [17, 37], [17, 40], [17, 44], [17, 47], [17, 58], [18, 29], [18, 44], [18, 46], [18, 47], [18, 50], [18, 51], [18, 56], [19, 21], [19, 22], [19, 23], [19, 26], [19, 27], [19, 30], [19, 47], [19, 51], [19, 56], [20, 28], [20, 29], [20, 35], [20, 36], [20, 38], [20, 39], [20, 45], [20, 46], [20, 47], [20, 58], [21, 23], [21, 26], [21, 27], [21, 32], [21, 33], [21, 35], [21, 41], [21, 43], [21, 57], [21, 58], [22, 23], [22, 35], [22, 36], [22, 39], [22, 41], [22, 45], [22, 56], [22, 57], [23, 28], [23, 34], [23, 35], [23, 37], [23, 39], [23, 41], [23, 42], [23, 43], [23, 44], [23, 47], [23, 50], [24, 26], [24, 38], [24, 45], [24, 52], [25, 28], [25, 56], [25, 58], [26, 36], [26, 48], [26, 49], [27, 31], [27, 34], [27, 47], [27, 50], [27, 51], [27, 55], [27, 58], [27, 59], [28, 29], [28, 33], [28, 35], [28, 36], [28, 37], [28, 38], [28, 39], [28, 42], [28, 43], [28, 46], [28, 49], [28, 50], [28, 58], [29, 33], [29, 40], [29, 45], [29, 58], [30, 48], [30, 53], [31, 54], [31, 57], [31, 59], [32, 34], [32, 44], [32, 45], [32, 46], [32, 53], [33, 38], [33, 40], [33, 43], [33, 45], [33, 50], [34, 45], [34, 47], [34, 48], [34, 53], [34, 58], [35, 38], [35, 40], [35, 42], [35, 54], [35, 55], [36, 40], [36, 48], [36, 50], [36, 54], [36, 57], [37, 39], [37, 43], [37, 47], [37, 59], [38, 43], [38, 44], [38, 50], [38, 53], [39, 50], [39, 52], [39, 54], [40, 43], [40, 45], [40, 46], [40, 50], [41, 43], [41, 44], [41, 56], [41, 59], [42, 50], [42, 52], [42, 58], [43, 44], [43, 48], [43, 50], [44, 55], [44, 57], [45, 53], [46, 48], [46, 57], [47, 50], [47, 59], [48, 51], [48, 52], [48, 54], [48, 58], [49, 50], [49, 56], [51, 54], [53, 54], [53, 56], [54, 58], [54, 59], [56, 57], [56, 59]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l4-s2/solution/solve.sh b/tasks/construct-mc-vertex-cover-l4-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..076f93fc8ab689db10529a2e857367a7b03dd1f1 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l4-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"cover": [0, 1, 2, 4, 6, 7, 8, 10, 11, 13, 14, 15, 17, 18, 19, 20, 23, 24, 26, 27, 28, 32, 33, 35, 36, 39, 40, 41, 43, 44, 45, 47, 48, 50, 52, 53, 54, 56, 57, 58, 59]} +RLMATH_EOF diff --git a/tasks/construct-mc-vertex-cover-l4-s2/tests/check.py b/tasks/construct-mc-vertex-cover-l4-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3accb3da1c773fd2126b8b5b0a97b099e29c83b --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l4-s2/tests/check.py @@ -0,0 +1,16 @@ +"""Vertex cover of size <= k in a given graph (MathConstraint vertex_cover, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("cover"), None, 0, n - 1, "cover") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) > k: + raise Invalid(f"cover has {len(S)} vertices, at most {k} allowed") + C = set(S) + for u, v in inst["edges"]: + if u not in C and v not in C: + raise Invalid(f"edge ({u},{v}) is not covered") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-vertex-cover-l4-s2/tests/instance.json b/tasks/construct-mc-vertex-cover-l4-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..23da08e0ff05f7cbeb21483f84c661fea2b93ed8 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l4-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 60, "k": 41, "edges": [[0, 1], [0, 3], [0, 19], [0, 25], [0, 28], [0, 41], [0, 44], [0, 56], [1, 4], [1, 17], [1, 20], [1, 26], [1, 27], [1, 31], [1, 38], [1, 49], [1, 50], [1, 51], [1, 54], [1, 58], [2, 11], [2, 12], [2, 14], [2, 16], [2, 38], [2, 39], [2, 40], [2, 48], [2, 53], [2, 55], [2, 57], [3, 7], [3, 17], [3, 24], [3, 36], [3, 44], [3, 58], [4, 5], [4, 6], [4, 14], [4, 25], [4, 31], [4, 43], [4, 51], [4, 55], [4, 57], [5, 7], [5, 20], [5, 23], [5, 41], [5, 43], [5, 44], [6, 11], [6, 17], [6, 21], [6, 56], [6, 58], [7, 13], [7, 20], [7, 26], [7, 31], [7, 34], [7, 35], [7, 40], [7, 45], [7, 48], [7, 53], [7, 54], [7, 55], [7, 58], [8, 9], [8, 14], [8, 18], [8, 19], [8, 23], [8, 32], [8, 43], [8, 46], [8, 48], [8, 50], [8, 59], [9, 13], [9, 17], [9, 19], [9, 23], [9, 33], [9, 39], [9, 41], [9, 43], [9, 45], [9, 47], [9, 56], [9, 58], [10, 12], [10, 22], [10, 24], [10, 27], [10, 35], [10, 39], [10, 42], [10, 44], [10, 50], [10, 57], [11, 13], [11, 14], [11, 17], [11, 21], [11, 25], [11, 26], [11, 31], [11, 33], [11, 35], [11, 39], [11, 54], [11, 58], [12, 27], [12, 45], [12, 56], [13, 25], [13, 29], [13, 37], [13, 41], [13, 46], [13, 50], [13, 51], [13, 54], [14, 21], [14, 25], [14, 32], [14, 40], [14, 41], [14, 44], [14, 45], [15, 16], [15, 25], [15, 31], [15, 34], [15, 38], [15, 45], [15, 46], [15, 48], [15, 49], [16, 19], [16, 28], [16, 32], [16, 53], [16, 54], [16, 57], [16, 59], [17, 20], [17, 34], [17, 37], [17, 40], [17, 44], [17, 47], [17, 58], [18, 29], [18, 44], [18, 46], [18, 47], [18, 50], [18, 51], [18, 56], [19, 21], [19, 22], [19, 23], [19, 26], [19, 27], [19, 30], [19, 47], [19, 51], [19, 56], [20, 28], [20, 29], [20, 35], [20, 36], [20, 38], [20, 39], [20, 45], [20, 46], [20, 47], [20, 58], [21, 23], [21, 26], [21, 27], [21, 32], [21, 33], [21, 35], [21, 41], [21, 43], [21, 57], [21, 58], [22, 23], [22, 35], [22, 36], [22, 39], [22, 41], [22, 45], [22, 56], [22, 57], [23, 28], [23, 34], [23, 35], [23, 37], [23, 39], [23, 41], [23, 42], [23, 43], [23, 44], [23, 47], [23, 50], [24, 26], [24, 38], [24, 45], [24, 52], [25, 28], [25, 56], [25, 58], [26, 36], [26, 48], [26, 49], [27, 31], [27, 34], [27, 47], [27, 50], [27, 51], [27, 55], [27, 58], [27, 59], [28, 29], [28, 33], [28, 35], [28, 36], [28, 37], [28, 38], [28, 39], [28, 42], [28, 43], [28, 46], [28, 49], [28, 50], [28, 58], [29, 33], [29, 40], [29, 45], [29, 58], [30, 48], [30, 53], [31, 54], [31, 57], [31, 59], [32, 34], [32, 44], [32, 45], [32, 46], [32, 53], [33, 38], [33, 40], [33, 43], [33, 45], [33, 50], [34, 45], [34, 47], [34, 48], [34, 53], [34, 58], [35, 38], [35, 40], [35, 42], [35, 54], [35, 55], [36, 40], [36, 48], [36, 50], [36, 54], [36, 57], [37, 39], [37, 43], [37, 47], [37, 59], [38, 43], [38, 44], [38, 50], [38, 53], [39, 50], [39, 52], [39, 54], [40, 43], [40, 45], [40, 46], [40, 50], [41, 43], [41, 44], [41, 56], [41, 59], [42, 50], [42, 52], [42, 58], [43, 44], [43, 48], [43, 50], [44, 55], [44, 57], [45, 53], [46, 48], [46, 57], [47, 50], [47, 59], [48, 51], [48, 52], [48, 54], [48, 58], [49, 50], [49, 56], [51, 54], [53, 54], [53, 56], [54, 58], [54, 59], [56, 57], [56, 59]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l4-s2/tests/run.py b/tasks/construct-mc-vertex-cover-l4-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l4-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-vertex-cover-l4-s2/tests/test.sh b/tasks/construct-mc-vertex-cover-l4-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l4-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-vertex-cover-l4-s5/environment/Dockerfile b/tasks/construct-mc-vertex-cover-l4-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l4-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-vertex-cover-l4-s5/environment/instance.json b/tasks/construct-mc-vertex-cover-l4-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d7f300f8999d0900b40971e550dea24d4bd1512d --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l4-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 60, "k": 41, "edges": [[0, 1], [0, 3], [0, 12], [0, 21], [0, 29], [0, 36], [0, 39], [0, 44], [0, 48], [0, 51], [0, 53], [0, 56], [1, 2], [1, 9], [1, 19], [1, 24], [1, 25], [1, 30], [1, 33], [1, 38], [1, 41], [1, 42], [1, 50], [1, 52], [1, 53], [1, 57], [2, 10], [2, 30], [2, 41], [2, 42], [2, 50], [3, 4], [3, 6], [3, 9], [3, 13], [3, 24], [3, 26], [3, 35], [3, 37], [3, 41], [3, 51], [3, 58], [4, 5], [4, 9], [4, 12], [4, 16], [4, 22], [4, 24], [4, 25], [4, 26], [4, 30], [4, 33], [4, 36], [5, 34], [5, 37], [5, 39], [5, 45], [5, 54], [5, 59], [6, 8], [6, 10], [6, 21], [6, 29], [6, 33], [6, 48], [6, 50], [6, 51], [6, 56], [7, 29], [7, 32], [7, 34], [7, 37], [7, 39], [7, 42], [7, 45], [7, 46], [7, 53], [8, 15], [8, 24], [8, 28], [8, 34], [8, 38], [8, 45], [8, 48], [8, 49], [8, 51], [9, 12], [9, 13], [9, 22], [9, 27], [9, 33], [9, 35], [9, 39], [9, 46], [9, 48], [9, 50], [9, 55], [9, 56], [10, 21], [10, 22], [10, 24], [10, 25], [10, 40], [10, 45], [10, 50], [10, 57], [10, 59], [11, 29], [11, 42], [11, 53], [11, 57], [12, 17], [12, 22], [12, 23], [12, 25], [12, 28], [12, 37], [12, 41], [12, 45], [12, 50], [13, 18], [13, 22], [13, 25], [13, 26], [13, 29], [13, 37], [13, 38], [13, 41], [13, 49], [13, 52], [13, 56], [13, 59], [14, 15], [14, 18], [14, 22], [14, 25], [14, 36], [14, 45], [14, 48], [14, 51], [14, 56], [14, 58], [15, 31], [15, 32], [15, 39], [15, 52], [15, 53], [16, 28], [16, 30], [16, 33], [16, 34], [16, 39], [16, 42], [16, 43], [16, 45], [16, 50], [16, 51], [17, 26], [17, 32], [17, 37], [17, 43], [17, 44], [17, 46], [17, 51], [17, 55], [18, 21], [18, 30], [18, 31], [18, 32], [18, 44], [18, 46], [18, 48], [18, 54], [18, 57], [18, 59], [19, 20], [19, 22], [19, 23], [19, 25], [19, 37], [19, 40], [19, 47], [19, 49], [19, 54], [19, 59], [20, 21], [20, 31], [20, 36], [20, 39], [20, 41], [20, 43], [20, 54], [21, 22], [21, 25], [21, 29], [21, 33], [21, 36], [21, 43], [21, 45], [21, 47], [21, 56], [21, 59], [22, 26], [22, 30], [22, 31], [22, 43], [22, 44], [23, 33], [23, 40], [23, 43], [23, 50], [23, 51], [23, 57], [24, 27], [24, 28], [24, 54], [24, 55], [24, 57], [25, 29], [25, 31], [25, 36], [25, 37], [25, 44], [25, 51], [25, 59], [26, 42], [26, 50], [26, 51], [26, 52], [27, 34], [27, 36], [27, 38], [27, 40], [27, 42], [27, 44], [27, 55], [27, 59], [28, 33], [28, 35], [28, 36], [28, 37], [28, 46], [28, 50], [28, 53], [29, 31], [29, 34], [29, 40], [29, 43], [29, 48], [30, 33], [30, 46], [30, 53], [30, 56], [31, 37], [31, 44], [31, 45], [31, 51], [31, 54], [31, 56], [32, 38], [32, 47], [32, 51], [32, 58], [33, 34], [33, 36], [33, 42], [33, 48], [33, 50], [34, 36], [34, 42], [34, 54], [34, 56], [35, 37], [35, 39], [35, 44], [35, 59], [36, 44], [36, 46], [36, 47], [36, 52], [37, 46], [37, 48], [37, 57], [37, 58], [38, 39], [38, 40], [38, 44], [38, 45], [38, 51], [38, 54], [39, 42], [39, 45], [39, 57], [40, 41], [40, 44], [40, 45], [40, 46], [40, 49], [40, 53], [41, 43], [41, 49], [41, 58], [42, 45], [42, 47], [42, 54], [42, 55], [42, 58], [42, 59], [43, 50], [43, 58], [44, 45], [44, 47], [44, 51], [44, 53], [44, 57], [45, 50], [45, 56], [45, 57], [46, 50], [46, 57], [47, 52], [47, 54], [48, 53], [49, 50], [49, 52], [49, 55], [49, 57], [49, 59], [50, 52], [50, 56], [51, 58], [52, 56], [53, 55], [53, 56], [53, 59], [54, 55], [55, 56], [58, 59]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l4-s5/solution/solve.sh b/tasks/construct-mc-vertex-cover-l4-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a8156e9c0bd7971667516c9536fda764eee2d56b --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l4-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"cover": [1, 3, 4, 8, 9, 10, 12, 13, 14, 19, 21, 26, 27, 28, 29, 30, 31, 32, 33, 34, 36, 37, 39, 40, 41, 42, 43, 44, 45, 46, 48, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59]} +RLMATH_EOF diff --git a/tasks/construct-mc-vertex-cover-l4-s5/tests/check.py b/tasks/construct-mc-vertex-cover-l4-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3accb3da1c773fd2126b8b5b0a97b099e29c83b --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l4-s5/tests/check.py @@ -0,0 +1,16 @@ +"""Vertex cover of size <= k in a given graph (MathConstraint vertex_cover, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("cover"), None, 0, n - 1, "cover") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) > k: + raise Invalid(f"cover has {len(S)} vertices, at most {k} allowed") + C = set(S) + for u, v in inst["edges"]: + if u not in C and v not in C: + raise Invalid(f"edge ({u},{v}) is not covered") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-vertex-cover-l4-s5/tests/instance.json b/tasks/construct-mc-vertex-cover-l4-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d7f300f8999d0900b40971e550dea24d4bd1512d --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l4-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 60, "k": 41, "edges": [[0, 1], [0, 3], [0, 12], [0, 21], [0, 29], [0, 36], [0, 39], [0, 44], [0, 48], [0, 51], [0, 53], [0, 56], [1, 2], [1, 9], [1, 19], [1, 24], [1, 25], [1, 30], [1, 33], [1, 38], [1, 41], [1, 42], [1, 50], [1, 52], [1, 53], [1, 57], [2, 10], [2, 30], [2, 41], [2, 42], [2, 50], [3, 4], [3, 6], [3, 9], [3, 13], [3, 24], [3, 26], [3, 35], [3, 37], [3, 41], [3, 51], [3, 58], [4, 5], [4, 9], [4, 12], [4, 16], [4, 22], [4, 24], [4, 25], [4, 26], [4, 30], [4, 33], [4, 36], [5, 34], [5, 37], [5, 39], [5, 45], [5, 54], [5, 59], [6, 8], [6, 10], [6, 21], [6, 29], [6, 33], [6, 48], [6, 50], [6, 51], [6, 56], [7, 29], [7, 32], [7, 34], [7, 37], [7, 39], [7, 42], [7, 45], [7, 46], [7, 53], [8, 15], [8, 24], [8, 28], [8, 34], [8, 38], [8, 45], [8, 48], [8, 49], [8, 51], [9, 12], [9, 13], [9, 22], [9, 27], [9, 33], [9, 35], [9, 39], [9, 46], [9, 48], [9, 50], [9, 55], [9, 56], [10, 21], [10, 22], [10, 24], [10, 25], [10, 40], [10, 45], [10, 50], [10, 57], [10, 59], [11, 29], [11, 42], [11, 53], [11, 57], [12, 17], [12, 22], [12, 23], [12, 25], [12, 28], [12, 37], [12, 41], [12, 45], [12, 50], [13, 18], [13, 22], [13, 25], [13, 26], [13, 29], [13, 37], [13, 38], [13, 41], [13, 49], [13, 52], [13, 56], [13, 59], [14, 15], [14, 18], [14, 22], [14, 25], [14, 36], [14, 45], [14, 48], [14, 51], [14, 56], [14, 58], [15, 31], [15, 32], [15, 39], [15, 52], [15, 53], [16, 28], [16, 30], [16, 33], [16, 34], [16, 39], [16, 42], [16, 43], [16, 45], [16, 50], [16, 51], [17, 26], [17, 32], [17, 37], [17, 43], [17, 44], [17, 46], [17, 51], [17, 55], [18, 21], [18, 30], [18, 31], [18, 32], [18, 44], [18, 46], [18, 48], [18, 54], [18, 57], [18, 59], [19, 20], [19, 22], [19, 23], [19, 25], [19, 37], [19, 40], [19, 47], [19, 49], [19, 54], [19, 59], [20, 21], [20, 31], [20, 36], [20, 39], [20, 41], [20, 43], [20, 54], [21, 22], [21, 25], [21, 29], [21, 33], [21, 36], [21, 43], [21, 45], [21, 47], [21, 56], [21, 59], [22, 26], [22, 30], [22, 31], [22, 43], [22, 44], [23, 33], [23, 40], [23, 43], [23, 50], [23, 51], [23, 57], [24, 27], [24, 28], [24, 54], [24, 55], [24, 57], [25, 29], [25, 31], [25, 36], [25, 37], [25, 44], [25, 51], [25, 59], [26, 42], [26, 50], [26, 51], [26, 52], [27, 34], [27, 36], [27, 38], [27, 40], [27, 42], [27, 44], [27, 55], [27, 59], [28, 33], [28, 35], [28, 36], [28, 37], [28, 46], [28, 50], [28, 53], [29, 31], [29, 34], [29, 40], [29, 43], [29, 48], [30, 33], [30, 46], [30, 53], [30, 56], [31, 37], [31, 44], [31, 45], [31, 51], [31, 54], [31, 56], [32, 38], [32, 47], [32, 51], [32, 58], [33, 34], [33, 36], [33, 42], [33, 48], [33, 50], [34, 36], [34, 42], [34, 54], [34, 56], [35, 37], [35, 39], [35, 44], [35, 59], [36, 44], [36, 46], [36, 47], [36, 52], [37, 46], [37, 48], [37, 57], [37, 58], [38, 39], [38, 40], [38, 44], [38, 45], [38, 51], [38, 54], [39, 42], [39, 45], [39, 57], [40, 41], [40, 44], [40, 45], [40, 46], [40, 49], [40, 53], [41, 43], [41, 49], [41, 58], [42, 45], [42, 47], [42, 54], [42, 55], [42, 58], [42, 59], [43, 50], [43, 58], [44, 45], [44, 47], [44, 51], [44, 53], [44, 57], [45, 50], [45, 56], [45, 57], [46, 50], [46, 57], [47, 52], [47, 54], [48, 53], [49, 50], [49, 52], [49, 55], [49, 57], [49, 59], [50, 52], [50, 56], [51, 58], [52, 56], [53, 55], [53, 56], [53, 59], [54, 55], [55, 56], [58, 59]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l4-s5/tests/run.py b/tasks/construct-mc-vertex-cover-l4-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l4-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-vertex-cover-l4-s5/tests/test.sh b/tasks/construct-mc-vertex-cover-l4-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l4-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-3col-l4-s2/environment/Dockerfile b/tasks/construct-nppc-3col-l4-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-3col-l4-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-3col-l4-s2/environment/instance.json b/tasks/construct-nppc-3col-l4-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9eed294c51329e09bce36b35579ec1f749d8066b --- /dev/null +++ b/tasks/construct-nppc-3col-l4-s2/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "edges": [[0, 5], [0, 8], [0, 9], [0, 11], [0, 18], [0, 20], [0, 21], [0, 24], [0, 25], [0, 26], [1, 3], [1, 10], [1, 11], [1, 12], [1, 14], [1, 16], [1, 27], [2, 4], [2, 12], [2, 18], [2, 27], [3, 5], [3, 13], [3, 18], [3, 20], [3, 21], [3, 28], [4, 8], [4, 11], [4, 17], [4, 18], [4, 25], [5, 9], [5, 12], [5, 16], [5, 20], [5, 28], [6, 8], [6, 12], [6, 16], [6, 21], [6, 22], [7, 15], [7, 19], [7, 23], [7, 28], [8, 10], [8, 19], [8, 26], [9, 19], [9, 29], [10, 15], [10, 20], [10, 25], [11, 17], [11, 23], [12, 19], [12, 25], [12, 26], [12, 29], [13, 14], [14, 28], [15, 24], [15, 26], [15, 29], [16, 17], [16, 21], [16, 23], [17, 19], [17, 26], [17, 29], [18, 23], [18, 28], [21, 24], [21, 26], [22, 25], [23, 26], [24, 27], [24, 28], [26, 28]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l4-s5/environment/Dockerfile b/tasks/construct-nppc-3col-l4-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-3col-l4-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-3col-l4-s5/environment/instance.json b/tasks/construct-nppc-3col-l4-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..66a046ca2c82a107a921f9f174c53eca6a4c79e4 --- /dev/null +++ b/tasks/construct-nppc-3col-l4-s5/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "edges": [[0, 14], [0, 19], [0, 28], [1, 3], [1, 4], [1, 11], [1, 13], [1, 14], [1, 25], [2, 18], [2, 26], [3, 12], [3, 13], [3, 18], [4, 6], [4, 12], [4, 17], [4, 21], [4, 23], [4, 26], [5, 9], [5, 15], [5, 28], [6, 20], [6, 21], [6, 22], [6, 25], [6, 29], [7, 9], [7, 10], [7, 23], [7, 25], [8, 11], [8, 12], [8, 15], [8, 18], [8, 24], [9, 12], [9, 13], [9, 18], [9, 19], [9, 21], [10, 13], [10, 22], [10, 25], [10, 27], [10, 29], [11, 13], [11, 16], [11, 19], [11, 20], [11, 21], [12, 22], [12, 23], [12, 29], [13, 17], [13, 23], [13, 25], [13, 28], [14, 25], [15, 16], [16, 19], [16, 21], [16, 22], [16, 24], [17, 27], [18, 20], [18, 25], [18, 28], [18, 29], [19, 24], [19, 25], [19, 26], [19, 27], [21, 24], [21, 29], [23, 24], [23, 25], [25, 28], [26, 29]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l4-s5/solution/solve.sh b/tasks/construct-nppc-3col-l4-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..337b136b402dd729ded631d1b908c1414c1c90ce --- /dev/null +++ b/tasks/construct-nppc-3col-l4-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [0, 1, 1, 0, 0, 2, 2, 2, 1, 0, 1, 0, 2, 2, 2, 0, 2, 1, 2, 1, 1, 1, 0, 1, 0, 0, 2, 2, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-nppc-3col-l4-s5/tests/check.py b/tasks/construct-nppc-3col-l4-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..72362ed9180250b6c53ce0c71867ca476ac2af20 --- /dev/null +++ b/tasks/construct-nppc-3col-l4-s5/tests/check.py @@ -0,0 +1,12 @@ +"""Proper 3-colouring of a given graph. Accepts any valid colouring.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["num_nodes"] + # upstream NPPC verifier skips the range/length check, so an all-distinct colouring passed it + c = int_list(ans.get("coloring"), n, 0, 2, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + return None, {} diff --git a/tasks/construct-nppc-3col-l4-s5/tests/instance.json b/tasks/construct-nppc-3col-l4-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..66a046ca2c82a107a921f9f174c53eca6a4c79e4 --- /dev/null +++ b/tasks/construct-nppc-3col-l4-s5/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "edges": [[0, 14], [0, 19], [0, 28], [1, 3], [1, 4], [1, 11], [1, 13], [1, 14], [1, 25], [2, 18], [2, 26], [3, 12], [3, 13], [3, 18], [4, 6], [4, 12], [4, 17], [4, 21], [4, 23], [4, 26], [5, 9], [5, 15], [5, 28], [6, 20], [6, 21], [6, 22], [6, 25], [6, 29], [7, 9], [7, 10], [7, 23], [7, 25], [8, 11], [8, 12], [8, 15], [8, 18], [8, 24], [9, 12], [9, 13], [9, 18], [9, 19], [9, 21], [10, 13], [10, 22], [10, 25], [10, 27], [10, 29], [11, 13], [11, 16], [11, 19], [11, 20], [11, 21], [12, 22], [12, 23], [12, 29], [13, 17], [13, 23], [13, 25], [13, 28], [14, 25], [15, 16], [16, 19], [16, 21], [16, 22], [16, 24], [17, 27], [18, 20], [18, 25], [18, 28], [18, 29], [19, 24], [19, 25], [19, 26], [19, 27], [21, 24], [21, 29], [23, 24], [23, 25], [25, 28], [26, 29]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l4-s5/tests/run.py b/tasks/construct-nppc-3col-l4-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-3col-l4-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-3col-l4-s5/tests/test.sh b/tasks/construct-nppc-3col-l4-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-3col-l4-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-bandwidth-l2-s0/environment/Dockerfile b/tasks/construct-nppc-bandwidth-l2-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l2-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-bandwidth-l2-s0/environment/instance.json b/tasks/construct-nppc-bandwidth-l2-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..278d8ac4d99ced5856649c317b729f534f0ba52e --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l2-s0/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "bandwidth": 3, "edges": [[0, 1], [1, 2], [1, 3], [2, 4], [3, 4], [3, 7], [4, 5], [5, 7]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l2-s0/solution/solve.sh b/tasks/construct-nppc-bandwidth-l2-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b0713709fc7348116ef4d9dec317685ba30ae7ea --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l2-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"layout": [0, 3, 1, 5, 4, 6, 2, 7]} +RLMATH_EOF diff --git a/tasks/construct-nppc-bandwidth-l2-s0/tests/check.py b/tasks/construct-nppc-bandwidth-l2-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0f847cded257e6c404063dfafde33fa44163afa2 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l2-s0/tests/check.py @@ -0,0 +1,14 @@ +"""Bandwidth <= b: layout must be a permutation of 0..n-1 with |p[u]-p[v]| <= b on every edge.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, b = inst["num_nodes"], inst["bandwidth"] + # upstream NPPC verifier compares sorted(layout) to range(n), which also accepts floats/bools + p = int_list(ans.get("layout"), n, 0, n - 1, "layout") + if len(set(p)) != n: + raise Invalid("layout is not a permutation of 0..n-1") + for u, v in inst["edges"]: + if abs(p[u] - p[v]) > b: + raise Invalid(f"edge ({u},{v}) has stretch {abs(p[u] - p[v])} > {b}") + return None, {} diff --git a/tasks/construct-nppc-bandwidth-l2-s0/tests/instance.json b/tasks/construct-nppc-bandwidth-l2-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..278d8ac4d99ced5856649c317b729f534f0ba52e --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l2-s0/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "bandwidth": 3, "edges": [[0, 1], [1, 2], [1, 3], [2, 4], [3, 4], [3, 7], [4, 5], [5, 7]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l2-s0/tests/run.py b/tasks/construct-nppc-bandwidth-l2-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l2-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-bandwidth-l2-s0/tests/test.sh b/tasks/construct-nppc-bandwidth-l2-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l2-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-bandwidth-l2-s7/environment/Dockerfile b/tasks/construct-nppc-bandwidth-l2-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l2-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-bandwidth-l2-s7/environment/instance.json b/tasks/construct-nppc-bandwidth-l2-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5cb97473d9c59dc2045dfdd5f75060962b1f1439 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l2-s7/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "bandwidth": 3, "edges": [[0, 1], [1, 5], [2, 3], [3, 4], [3, 5], [4, 5], [5, 7], [6, 7]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l2-s7/solution/solve.sh b/tasks/construct-nppc-bandwidth-l2-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..fe3f286081f5a3df36a93225c753c68e377f2707 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l2-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"layout": [5, 6, 0, 2, 1, 3, 7, 4]} +RLMATH_EOF diff --git a/tasks/construct-nppc-bandwidth-l2-s7/tests/check.py b/tasks/construct-nppc-bandwidth-l2-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0f847cded257e6c404063dfafde33fa44163afa2 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l2-s7/tests/check.py @@ -0,0 +1,14 @@ +"""Bandwidth <= b: layout must be a permutation of 0..n-1 with |p[u]-p[v]| <= b on every edge.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, b = inst["num_nodes"], inst["bandwidth"] + # upstream NPPC verifier compares sorted(layout) to range(n), which also accepts floats/bools + p = int_list(ans.get("layout"), n, 0, n - 1, "layout") + if len(set(p)) != n: + raise Invalid("layout is not a permutation of 0..n-1") + for u, v in inst["edges"]: + if abs(p[u] - p[v]) > b: + raise Invalid(f"edge ({u},{v}) has stretch {abs(p[u] - p[v])} > {b}") + return None, {} diff --git a/tasks/construct-nppc-bandwidth-l2-s7/tests/instance.json b/tasks/construct-nppc-bandwidth-l2-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5cb97473d9c59dc2045dfdd5f75060962b1f1439 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l2-s7/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "bandwidth": 3, "edges": [[0, 1], [1, 5], [2, 3], [3, 4], [3, 5], [4, 5], [5, 7], [6, 7]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l2-s7/tests/run.py b/tasks/construct-nppc-bandwidth-l2-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l2-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-bandwidth-l2-s7/tests/test.sh b/tasks/construct-nppc-bandwidth-l2-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l2-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-bandwidth-l2-s9/environment/Dockerfile b/tasks/construct-nppc-bandwidth-l2-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l2-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-bandwidth-l2-s9/environment/instance.json b/tasks/construct-nppc-bandwidth-l2-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fc516931761ac8334cbcdad1950f49e47a4591c1 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l2-s9/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "bandwidth": 3, "edges": [[0, 2], [0, 4], [1, 3], [2, 4], [3, 4], [3, 6], [4, 5], [5, 6]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l2-s9/solution/solve.sh b/tasks/construct-nppc-bandwidth-l2-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..16279cef9aa352c0b3230fc815d32baa3fccf288 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l2-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"layout": [2, 7, 1, 5, 4, 3, 6, 0]} +RLMATH_EOF diff --git a/tasks/construct-nppc-bandwidth-l2-s9/tests/check.py b/tasks/construct-nppc-bandwidth-l2-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0f847cded257e6c404063dfafde33fa44163afa2 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l2-s9/tests/check.py @@ -0,0 +1,14 @@ +"""Bandwidth <= b: layout must be a permutation of 0..n-1 with |p[u]-p[v]| <= b on every edge.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, b = inst["num_nodes"], inst["bandwidth"] + # upstream NPPC verifier compares sorted(layout) to range(n), which also accepts floats/bools + p = int_list(ans.get("layout"), n, 0, n - 1, "layout") + if len(set(p)) != n: + raise Invalid("layout is not a permutation of 0..n-1") + for u, v in inst["edges"]: + if abs(p[u] - p[v]) > b: + raise Invalid(f"edge ({u},{v}) has stretch {abs(p[u] - p[v])} > {b}") + return None, {} diff --git a/tasks/construct-nppc-bandwidth-l2-s9/tests/instance.json b/tasks/construct-nppc-bandwidth-l2-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fc516931761ac8334cbcdad1950f49e47a4591c1 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l2-s9/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "bandwidth": 3, "edges": [[0, 2], [0, 4], [1, 3], [2, 4], [3, 4], [3, 6], [4, 5], [5, 6]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l2-s9/tests/run.py b/tasks/construct-nppc-bandwidth-l2-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l2-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-bandwidth-l2-s9/tests/test.sh b/tasks/construct-nppc-bandwidth-l2-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l2-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-bandwidth-l6-s1/environment/Dockerfile b/tasks/construct-nppc-bandwidth-l6-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l6-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-bandwidth-l6-s1/environment/instance.json b/tasks/construct-nppc-bandwidth-l6-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..69de9e3595283bf49ef1978f79db4501cdd8aedf --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l6-s1/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 80, "bandwidth": 5, "edges": [[0, 2], [0, 33], [0, 52], [0, 75], [0, 78], [1, 4], [1, 50], [1, 64], [2, 7], [2, 19], [2, 23], [2, 38], [2, 44], [2, 75], [3, 17], [3, 26], [3, 47], [3, 69], [4, 15], [4, 20], [4, 39], [4, 67], [4, 77], [5, 17], [5, 48], [5, 74], [6, 8], [6, 14], [6, 24], [6, 25], [7, 19], [7, 23], [7, 38], [7, 44], [8, 10], [8, 14], [8, 16], [8, 24], [8, 55], [8, 71], [9, 22], [9, 36], [9, 43], [9, 46], [9, 58], [9, 68], [9, 70], [10, 11], [10, 14], [10, 55], [11, 13], [11, 16], [11, 25], [11, 35], [11, 59], [12, 15], [12, 20], [12, 39], [13, 18], [13, 51], [13, 56], [13, 59], [14, 16], [14, 38], [14, 61], [14, 71], [15, 20], [15, 32], [15, 39], [15, 50], [15, 54], [15, 77], [16, 24], [16, 35], [16, 59], [17, 26], [17, 47], [17, 48], [18, 42], [18, 45], [18, 51], [18, 56], [19, 38], [19, 44], [19, 55], [19, 76], [20, 29], [20, 39], [20, 67], [21, 23], [21, 27], [21, 28], [21, 34], [21, 44], [21, 46], [21, 52], [21, 78], [22, 27], [22, 33], [22, 46], [22, 52], [22, 58], [22, 70], [23, 27], [24, 25], [24, 41], [25, 35], [25, 66], [26, 40], [26, 47], [26, 48], [27, 28], [27, 46], [27, 52], [28, 33], [28, 36], [28, 52], [28, 58], [28, 70], [29, 30], [29, 53], [29, 60], [30, 31], [30, 32], [30, 37], [30, 39], [30, 53], [30, 72], [31, 32], [31, 37], [31, 53], [31, 72], [31, 73], [32, 39], [32, 67], [33, 34], [33, 46], [33, 52], [33, 58], [34, 44], [34, 52], [35, 45], [36, 43], [36, 58], [37, 53], [37, 73], [38, 55], [38, 61], [38, 63], [38, 75], [39, 50], [39, 77], [40, 47], [40, 69], [41, 55], [41, 61], [42, 45], [42, 54], [42, 56], [42, 77], [43, 57], [43, 70], [44, 75], [44, 76], [44, 78], [45, 51], [45, 64], [45, 66], [46, 52], [46, 58], [47, 48], [47, 69], [48, 65], [48, 74], [49, 53], [49, 60], [49, 69], [49, 73], [49, 79], [50, 54], [50, 64], [51, 56], [51, 62], [51, 66], [52, 78], [53, 60], [54, 56], [54, 64], [54, 77], [55, 61], [55, 63], [55, 71], [55, 76], [56, 62], [56, 64], [56, 66], [57, 58], [57, 68], [57, 70], [58, 70], [59, 62], [60, 72], [60, 73], [61, 63], [61, 71], [61, 75], [62, 66], [63, 71], [63, 76], [64, 66], [64, 77], [65, 69], [65, 74], [67, 77], [68, 70], [69, 74], [72, 73], [72, 79], [73, 79], [75, 76], [76, 78]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l6-s1/solution/solve.sh b/tasks/construct-nppc-bandwidth-l6-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..bbd30f625d73bfec3d7185dbd2b26ca5825e2a8a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l6-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"layout": [15, 49, 19, 70, 53, 78, 33, 21, 31, 4, 32, 37, 59, 41, 29, 55, 34, 73, 46, 23, 58, 13, 7, 16, 35, 38, 71, 11, 8, 61, 60, 62, 57, 10, 14, 39, 5, 63, 24, 56, 75, 30, 48, 2, 18, 44, 9, 72, 76, 69, 51, 42, 12, 64, 50, 27, 45, 1, 6, 36, 66, 25, 40, 26, 47, 77, 43, 54, 0, 74, 3, 28, 65, 67, 79, 20, 22, 52, 17, 68]} +RLMATH_EOF diff --git a/tasks/construct-nppc-bandwidth-l6-s1/tests/check.py b/tasks/construct-nppc-bandwidth-l6-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0f847cded257e6c404063dfafde33fa44163afa2 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l6-s1/tests/check.py @@ -0,0 +1,14 @@ +"""Bandwidth <= b: layout must be a permutation of 0..n-1 with |p[u]-p[v]| <= b on every edge.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, b = inst["num_nodes"], inst["bandwidth"] + # upstream NPPC verifier compares sorted(layout) to range(n), which also accepts floats/bools + p = int_list(ans.get("layout"), n, 0, n - 1, "layout") + if len(set(p)) != n: + raise Invalid("layout is not a permutation of 0..n-1") + for u, v in inst["edges"]: + if abs(p[u] - p[v]) > b: + raise Invalid(f"edge ({u},{v}) has stretch {abs(p[u] - p[v])} > {b}") + return None, {} diff --git a/tasks/construct-nppc-bandwidth-l6-s1/tests/instance.json b/tasks/construct-nppc-bandwidth-l6-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..69de9e3595283bf49ef1978f79db4501cdd8aedf --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l6-s1/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 80, "bandwidth": 5, "edges": [[0, 2], [0, 33], [0, 52], [0, 75], [0, 78], [1, 4], [1, 50], [1, 64], [2, 7], [2, 19], [2, 23], [2, 38], [2, 44], [2, 75], [3, 17], [3, 26], [3, 47], [3, 69], [4, 15], [4, 20], [4, 39], [4, 67], [4, 77], [5, 17], [5, 48], [5, 74], [6, 8], [6, 14], [6, 24], [6, 25], [7, 19], [7, 23], [7, 38], [7, 44], [8, 10], [8, 14], [8, 16], [8, 24], [8, 55], [8, 71], [9, 22], [9, 36], [9, 43], [9, 46], [9, 58], [9, 68], [9, 70], [10, 11], [10, 14], [10, 55], [11, 13], [11, 16], [11, 25], [11, 35], [11, 59], [12, 15], [12, 20], [12, 39], [13, 18], [13, 51], [13, 56], [13, 59], [14, 16], [14, 38], [14, 61], [14, 71], [15, 20], [15, 32], [15, 39], [15, 50], [15, 54], [15, 77], [16, 24], [16, 35], [16, 59], [17, 26], [17, 47], [17, 48], [18, 42], [18, 45], [18, 51], [18, 56], [19, 38], [19, 44], [19, 55], [19, 76], [20, 29], [20, 39], [20, 67], [21, 23], [21, 27], [21, 28], [21, 34], [21, 44], [21, 46], [21, 52], [21, 78], [22, 27], [22, 33], [22, 46], [22, 52], [22, 58], [22, 70], [23, 27], [24, 25], [24, 41], [25, 35], [25, 66], [26, 40], [26, 47], [26, 48], [27, 28], [27, 46], [27, 52], [28, 33], [28, 36], [28, 52], [28, 58], [28, 70], [29, 30], [29, 53], [29, 60], [30, 31], [30, 32], [30, 37], [30, 39], [30, 53], [30, 72], [31, 32], [31, 37], [31, 53], [31, 72], [31, 73], [32, 39], [32, 67], [33, 34], [33, 46], [33, 52], [33, 58], [34, 44], [34, 52], [35, 45], [36, 43], [36, 58], [37, 53], [37, 73], [38, 55], [38, 61], [38, 63], [38, 75], [39, 50], [39, 77], [40, 47], [40, 69], [41, 55], [41, 61], [42, 45], [42, 54], [42, 56], [42, 77], [43, 57], [43, 70], [44, 75], [44, 76], [44, 78], [45, 51], [45, 64], [45, 66], [46, 52], [46, 58], [47, 48], [47, 69], [48, 65], [48, 74], [49, 53], [49, 60], [49, 69], [49, 73], [49, 79], [50, 54], [50, 64], [51, 56], [51, 62], [51, 66], [52, 78], [53, 60], [54, 56], [54, 64], [54, 77], [55, 61], [55, 63], [55, 71], [55, 76], [56, 62], [56, 64], [56, 66], [57, 58], [57, 68], [57, 70], [58, 70], [59, 62], [60, 72], [60, 73], [61, 63], [61, 71], [61, 75], [62, 66], [63, 71], [63, 76], [64, 66], [64, 77], [65, 69], [65, 74], [67, 77], [68, 70], [69, 74], [72, 73], [72, 79], [73, 79], [75, 76], [76, 78]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l6-s1/tests/run.py b/tasks/construct-nppc-bandwidth-l6-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l6-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-bandwidth-l6-s1/tests/test.sh b/tasks/construct-nppc-bandwidth-l6-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l6-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-bandwidth-l6-s6/environment/Dockerfile b/tasks/construct-nppc-bandwidth-l6-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l6-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-bandwidth-l6-s6/environment/instance.json b/tasks/construct-nppc-bandwidth-l6-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5f1dd167a294678ce6a1c0866dc011fa577687b7 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l6-s6/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 80, "bandwidth": 5, "edges": [[0, 1], [0, 67], [0, 74], [0, 76], [1, 4], [1, 28], [1, 52], [1, 60], [2, 8], [2, 33], [2, 37], [2, 40], [2, 73], [3, 7], [3, 10], [3, 72], [4, 6], [4, 49], [4, 64], [4, 74], [4, 76], [5, 15], [5, 24], [6, 11], [6, 49], [6, 64], [7, 9], [7, 10], [7, 26], [7, 50], [7, 62], [7, 67], [7, 68], [7, 72], [7, 77], [8, 31], [8, 33], [8, 37], [8, 57], [9, 10], [9, 26], [9, 62], [9, 67], [10, 26], [10, 50], [10, 56], [10, 77], [11, 17], [11, 23], [11, 41], [11, 49], [11, 65], [11, 70], [12, 14], [12, 30], [12, 32], [12, 34], [12, 61], [13, 20], [13, 21], [13, 39], [13, 40], [13, 73], [14, 18], [14, 34], [14, 43], [14, 45], [14, 47], [15, 19], [15, 66], [15, 69], [15, 78], [16, 23], [16, 25], [16, 29], [16, 32], [16, 42], [16, 45], [16, 65], [17, 23], [17, 41], [17, 42], [17, 65], [17, 70], [18, 27], [18, 30], [18, 34], [18, 46], [18, 54], [18, 61], [19, 22], [19, 24], [19, 48], [19, 61], [19, 75], [20, 21], [20, 31], [20, 37], [20, 40], [20, 53], [20, 59], [20, 73], [21, 35], [21, 38], [21, 59], [22, 24], [22, 30], [22, 54], [22, 61], [22, 69], [22, 75], [23, 25], [23, 42], [23, 43], [23, 45], [23, 51], [23, 65], [24, 30], [24, 66], [24, 69], [24, 75], [25, 42], [25, 65], [26, 50], [26, 55], [26, 56], [26, 68], [26, 77], [27, 32], [27, 34], [27, 43], [27, 54], [27, 61], [27, 71], [28, 41], [28, 52], [28, 60], [28, 76], [29, 32], [29, 45], [29, 51], [30, 46], [30, 61], [30, 69], [30, 75], [31, 37], [31, 38], [31, 40], [31, 58], [31, 59], [32, 34], [32, 43], [32, 45], [32, 47], [32, 71], [33, 37], [33, 40], [33, 58], [34, 43], [34, 45], [34, 47], [34, 54], [34, 71], [35, 39], [35, 59], [35, 78], [36, 52], [36, 72], [36, 76], [37, 40], [37, 57], [37, 73], [38, 39], [38, 40], [38, 53], [38, 78], [39, 48], [39, 59], [39, 66], [40, 58], [41, 49], [41, 64], [41, 70], [42, 43], [42, 71], [43, 45], [43, 71], [44, 50], [44, 56], [44, 77], [45, 51], [46, 47], [46, 54], [46, 61], [46, 75], [47, 54], [47, 61], [48, 66], [48, 75], [48, 78], [49, 64], [50, 55], [50, 62], [51, 65], [51, 70], [52, 60], [52, 67], [53, 59], [53, 66], [53, 78], [54, 61], [54, 69], [55, 56], [55, 63], [55, 77], [56, 62], [56, 77], [57, 58], [59, 73], [59, 78], [60, 67], [60, 72], [60, 76], [61, 69], [62, 63], [62, 68], [63, 77], [64, 70], [64, 76], [64, 79], [65, 70], [65, 79], [66, 75], [67, 68], [67, 76], [68, 72], [69, 75], [70, 79], [74, 76]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l6-s6/solution/solve.sh b/tasks/construct-nppc-bandwidth-l6-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6d890a709c896bb68d1bfce76a6ba9f9550fe2a2 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l6-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"layout": [16, 21, 74, 12, 23, 59, 25, 9, 76, 10, 8, 30, 47, 69, 43, 58, 37, 31, 48, 55, 70, 65, 54, 35, 57, 32, 7, 45, 22, 38, 52, 72, 42, 78, 44, 62, 15, 75, 68, 64, 73, 26, 36, 40, 0, 39, 51, 46, 60, 27, 5, 34, 18, 66, 49, 2, 3, 79, 77, 67, 17, 50, 6, 1, 24, 33, 61, 14, 11, 53, 29, 41, 13, 71, 20, 56, 19, 4, 63, 28]} +RLMATH_EOF diff --git a/tasks/construct-nppc-bandwidth-l6-s6/tests/check.py b/tasks/construct-nppc-bandwidth-l6-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0f847cded257e6c404063dfafde33fa44163afa2 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l6-s6/tests/check.py @@ -0,0 +1,14 @@ +"""Bandwidth <= b: layout must be a permutation of 0..n-1 with |p[u]-p[v]| <= b on every edge.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, b = inst["num_nodes"], inst["bandwidth"] + # upstream NPPC verifier compares sorted(layout) to range(n), which also accepts floats/bools + p = int_list(ans.get("layout"), n, 0, n - 1, "layout") + if len(set(p)) != n: + raise Invalid("layout is not a permutation of 0..n-1") + for u, v in inst["edges"]: + if abs(p[u] - p[v]) > b: + raise Invalid(f"edge ({u},{v}) has stretch {abs(p[u] - p[v])} > {b}") + return None, {} diff --git a/tasks/construct-nppc-bandwidth-l6-s6/tests/instance.json b/tasks/construct-nppc-bandwidth-l6-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5f1dd167a294678ce6a1c0866dc011fa577687b7 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l6-s6/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 80, "bandwidth": 5, "edges": [[0, 1], [0, 67], [0, 74], [0, 76], [1, 4], [1, 28], [1, 52], [1, 60], [2, 8], [2, 33], [2, 37], [2, 40], [2, 73], [3, 7], [3, 10], [3, 72], [4, 6], [4, 49], [4, 64], [4, 74], [4, 76], [5, 15], [5, 24], [6, 11], [6, 49], [6, 64], [7, 9], [7, 10], [7, 26], [7, 50], [7, 62], [7, 67], [7, 68], [7, 72], [7, 77], [8, 31], [8, 33], [8, 37], [8, 57], [9, 10], [9, 26], [9, 62], [9, 67], [10, 26], [10, 50], [10, 56], [10, 77], [11, 17], [11, 23], [11, 41], [11, 49], [11, 65], [11, 70], [12, 14], [12, 30], [12, 32], [12, 34], [12, 61], [13, 20], [13, 21], [13, 39], [13, 40], [13, 73], [14, 18], [14, 34], [14, 43], [14, 45], [14, 47], [15, 19], [15, 66], [15, 69], [15, 78], [16, 23], [16, 25], [16, 29], [16, 32], [16, 42], [16, 45], [16, 65], [17, 23], [17, 41], [17, 42], [17, 65], [17, 70], [18, 27], [18, 30], [18, 34], [18, 46], [18, 54], [18, 61], [19, 22], [19, 24], [19, 48], [19, 61], [19, 75], [20, 21], [20, 31], [20, 37], [20, 40], [20, 53], [20, 59], [20, 73], [21, 35], [21, 38], [21, 59], [22, 24], [22, 30], [22, 54], [22, 61], [22, 69], [22, 75], [23, 25], [23, 42], [23, 43], [23, 45], [23, 51], [23, 65], [24, 30], [24, 66], [24, 69], [24, 75], [25, 42], [25, 65], [26, 50], [26, 55], [26, 56], [26, 68], [26, 77], [27, 32], [27, 34], [27, 43], [27, 54], [27, 61], [27, 71], [28, 41], [28, 52], [28, 60], [28, 76], [29, 32], [29, 45], [29, 51], [30, 46], [30, 61], [30, 69], [30, 75], [31, 37], [31, 38], [31, 40], [31, 58], [31, 59], [32, 34], [32, 43], [32, 45], [32, 47], [32, 71], [33, 37], [33, 40], [33, 58], [34, 43], [34, 45], [34, 47], [34, 54], [34, 71], [35, 39], [35, 59], [35, 78], [36, 52], [36, 72], [36, 76], [37, 40], [37, 57], [37, 73], [38, 39], [38, 40], [38, 53], [38, 78], [39, 48], [39, 59], [39, 66], [40, 58], [41, 49], [41, 64], [41, 70], [42, 43], [42, 71], [43, 45], [43, 71], [44, 50], [44, 56], [44, 77], [45, 51], [46, 47], [46, 54], [46, 61], [46, 75], [47, 54], [47, 61], [48, 66], [48, 75], [48, 78], [49, 64], [50, 55], [50, 62], [51, 65], [51, 70], [52, 60], [52, 67], [53, 59], [53, 66], [53, 78], [54, 61], [54, 69], [55, 56], [55, 63], [55, 77], [56, 62], [56, 77], [57, 58], [59, 73], [59, 78], [60, 67], [60, 72], [60, 76], [61, 69], [62, 63], [62, 68], [63, 77], [64, 70], [64, 76], [64, 79], [65, 70], [65, 79], [66, 75], [67, 68], [67, 76], [68, 72], [69, 75], [70, 79], [74, 76]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l6-s6/tests/run.py b/tasks/construct-nppc-bandwidth-l6-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l6-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-bandwidth-l6-s6/tests/test.sh b/tasks/construct-nppc-bandwidth-l6-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l6-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-bandwidth-l6-s8/environment/Dockerfile b/tasks/construct-nppc-bandwidth-l6-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l6-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-bandwidth-l6-s8/environment/instance.json b/tasks/construct-nppc-bandwidth-l6-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..60608eba8e227b59b377e0c2980dbc4ce5b4270d --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l6-s8/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 80, "bandwidth": 5, "edges": [[0, 13], [0, 21], [0, 26], [0, 36], [0, 48], [0, 60], [1, 5], [1, 8], [1, 47], [1, 61], [2, 13], [2, 19], [2, 26], [2, 29], [2, 35], [2, 36], [2, 46], [3, 12], [3, 17], [3, 40], [3, 43], [3, 70], [4, 23], [4, 25], [4, 32], [4, 34], [4, 44], [4, 59], [4, 66], [4, 78], [4, 79], [5, 8], [5, 58], [5, 75], [6, 11], [6, 19], [6, 29], [6, 53], [7, 16], [7, 20], [7, 25], [7, 37], [7, 38], [7, 48], [7, 56], [7, 71], [8, 18], [8, 64], [8, 65], [8, 75], [9, 14], [9, 15], [9, 22], [9, 24], [9, 45], [9, 69], [10, 30], [10, 61], [10, 63], [10, 64], [10, 65], [10, 76], [11, 19], [11, 33], [11, 53], [11, 62], [11, 67], [12, 17], [12, 40], [12, 77], [13, 21], [13, 35], [13, 36], [13, 60], [13, 72], [14, 27], [14, 28], [14, 45], [14, 58], [14, 68], [14, 69], [14, 75], [15, 22], [16, 20], [16, 37], [16, 48], [16, 51], [16, 52], [16, 56], [17, 40], [17, 41], [17, 50], [17, 54], [17, 66], [17, 70], [18, 27], [18, 42], [18, 75], [19, 29], [19, 53], [20, 25], [20, 37], [20, 38], [20, 51], [20, 56], [20, 71], [21, 26], [21, 36], [21, 52], [21, 60], [22, 24], [22, 28], [22, 57], [22, 69], [23, 32], [23, 44], [23, 50], [23, 74], [23, 78], [23, 79], [24, 28], [24, 39], [24, 45], [24, 55], [25, 37], [25, 74], [25, 79], [26, 35], [26, 36], [27, 42], [27, 49], [28, 45], [28, 57], [28, 58], [28, 68], [29, 35], [29, 46], [29, 53], [29, 63], [29, 72], [30, 33], [30, 53], [30, 62], [30, 76], [31, 37], [31, 51], [31, 52], [32, 34], [32, 44], [32, 78], [33, 47], [33, 53], [33, 76], [34, 41], [34, 44], [34, 50], [34, 66], [35, 36], [35, 46], [35, 72], [36, 46], [36, 60], [37, 38], [37, 48], [38, 51], [38, 59], [38, 71], [38, 74], [38, 78], [39, 55], [40, 41], [40, 44], [40, 77], [41, 44], [41, 66], [41, 77], [42, 47], [42, 61], [42, 65], [43, 54], [44, 50], [44, 66], [44, 74], [44, 77], [45, 49], [45, 58], [45, 69], [46, 60], [47, 61], [47, 65], [48, 51], [48, 56], [48, 73], [49, 58], [49, 68], [49, 75], [50, 66], [50, 77], [51, 52], [51, 71], [52, 56], [53, 63], [54, 70], [55, 57], [56, 71], [58, 68], [58, 75], [59, 71], [59, 74], [60, 73], [61, 62], [61, 64], [61, 65], [61, 76], [62, 63], [62, 64], [63, 76], [64, 65], [64, 76], [65, 76], [66, 77], [67, 72], [68, 69], [68, 75], [69, 75], [70, 77], [71, 78], [74, 78], [78, 79]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l6-s8/solution/solve.sh b/tasks/construct-nppc-bandwidth-l6-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8701749a370ec6dbc0688de84ad66be8872b5ed2 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l6-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"layout": [45, 19, 38, 77, 64, 15, 32, 55, 17, 6, 25, 31, 76, 41, 11, 2, 51, 74, 18, 34, 56, 46, 5, 65, 4, 59, 43, 16, 7, 35, 29, 49, 66, 28, 67, 39, 42, 54, 58, 0, 73, 71, 20, 79, 68, 8, 40, 24, 50, 13, 70, 53, 48, 33, 78, 1, 52, 3, 10, 60, 44, 23, 27, 30, 22, 21, 69, 36, 12, 9, 75, 57, 37, 47, 63, 14, 26, 72, 62, 61]} +RLMATH_EOF diff --git a/tasks/construct-nppc-bandwidth-l6-s8/tests/check.py b/tasks/construct-nppc-bandwidth-l6-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0f847cded257e6c404063dfafde33fa44163afa2 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l6-s8/tests/check.py @@ -0,0 +1,14 @@ +"""Bandwidth <= b: layout must be a permutation of 0..n-1 with |p[u]-p[v]| <= b on every edge.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, b = inst["num_nodes"], inst["bandwidth"] + # upstream NPPC verifier compares sorted(layout) to range(n), which also accepts floats/bools + p = int_list(ans.get("layout"), n, 0, n - 1, "layout") + if len(set(p)) != n: + raise Invalid("layout is not a permutation of 0..n-1") + for u, v in inst["edges"]: + if abs(p[u] - p[v]) > b: + raise Invalid(f"edge ({u},{v}) has stretch {abs(p[u] - p[v])} > {b}") + return None, {} diff --git a/tasks/construct-nppc-bandwidth-l6-s8/tests/instance.json b/tasks/construct-nppc-bandwidth-l6-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..60608eba8e227b59b377e0c2980dbc4ce5b4270d --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l6-s8/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 80, "bandwidth": 5, "edges": [[0, 13], [0, 21], [0, 26], [0, 36], [0, 48], [0, 60], [1, 5], [1, 8], [1, 47], [1, 61], [2, 13], [2, 19], [2, 26], [2, 29], [2, 35], [2, 36], [2, 46], [3, 12], [3, 17], [3, 40], [3, 43], [3, 70], [4, 23], [4, 25], [4, 32], [4, 34], [4, 44], [4, 59], [4, 66], [4, 78], [4, 79], [5, 8], [5, 58], [5, 75], [6, 11], [6, 19], [6, 29], [6, 53], [7, 16], [7, 20], [7, 25], [7, 37], [7, 38], [7, 48], [7, 56], [7, 71], [8, 18], [8, 64], [8, 65], [8, 75], [9, 14], [9, 15], [9, 22], [9, 24], [9, 45], [9, 69], [10, 30], [10, 61], [10, 63], [10, 64], [10, 65], [10, 76], [11, 19], [11, 33], [11, 53], [11, 62], [11, 67], [12, 17], [12, 40], [12, 77], [13, 21], [13, 35], [13, 36], [13, 60], [13, 72], [14, 27], [14, 28], [14, 45], [14, 58], [14, 68], [14, 69], [14, 75], [15, 22], [16, 20], [16, 37], [16, 48], [16, 51], [16, 52], [16, 56], [17, 40], [17, 41], [17, 50], [17, 54], [17, 66], [17, 70], [18, 27], [18, 42], [18, 75], [19, 29], [19, 53], [20, 25], [20, 37], [20, 38], [20, 51], [20, 56], [20, 71], [21, 26], [21, 36], [21, 52], [21, 60], [22, 24], [22, 28], [22, 57], [22, 69], [23, 32], [23, 44], [23, 50], [23, 74], [23, 78], [23, 79], [24, 28], [24, 39], [24, 45], [24, 55], [25, 37], [25, 74], [25, 79], [26, 35], [26, 36], [27, 42], [27, 49], [28, 45], [28, 57], [28, 58], [28, 68], [29, 35], [29, 46], [29, 53], [29, 63], [29, 72], [30, 33], [30, 53], [30, 62], [30, 76], [31, 37], [31, 51], [31, 52], [32, 34], [32, 44], [32, 78], [33, 47], [33, 53], [33, 76], [34, 41], [34, 44], [34, 50], [34, 66], [35, 36], [35, 46], [35, 72], [36, 46], [36, 60], [37, 38], [37, 48], [38, 51], [38, 59], [38, 71], [38, 74], [38, 78], [39, 55], [40, 41], [40, 44], [40, 77], [41, 44], [41, 66], [41, 77], [42, 47], [42, 61], [42, 65], [43, 54], [44, 50], [44, 66], [44, 74], [44, 77], [45, 49], [45, 58], [45, 69], [46, 60], [47, 61], [47, 65], [48, 51], [48, 56], [48, 73], [49, 58], [49, 68], [49, 75], [50, 66], [50, 77], [51, 52], [51, 71], [52, 56], [53, 63], [54, 70], [55, 57], [56, 71], [58, 68], [58, 75], [59, 71], [59, 74], [60, 73], [61, 62], [61, 64], [61, 65], [61, 76], [62, 63], [62, 64], [63, 76], [64, 65], [64, 76], [65, 76], [66, 77], [67, 72], [68, 69], [68, 75], [69, 75], [70, 77], [71, 78], [74, 78], [78, 79]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l6-s8/tests/run.py b/tasks/construct-nppc-bandwidth-l6-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l6-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-bandwidth-l6-s8/tests/test.sh b/tasks/construct-nppc-bandwidth-l6-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l6-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-clique-l3-s0/environment/Dockerfile b/tasks/construct-nppc-clique-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-clique-l3-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-clique-l3-s0/environment/instance.json b/tasks/construct-nppc-clique-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9e7bf49b70282a5ab90cf9526c3574eb1a173b06 --- /dev/null +++ b/tasks/construct-nppc-clique-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 20, "k": 10, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 10], [0, 11], [0, 12], [0, 13], [0, 14], [0, 15], [0, 16], [0, 17], [0, 19], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 16], [1, 19], [2, 4], [2, 9], [2, 10], [2, 11], [2, 17], [2, 18], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 10], [3, 11], [3, 12], [3, 13], [3, 14], [3, 15], [3, 16], [3, 18], [3, 19], [4, 6], [4, 7], [4, 10], [4, 11], [4, 12], [4, 14], [4, 16], [4, 18], [4, 19], [5, 6], [5, 7], [5, 8], [5, 10], [5, 11], [5, 12], [5, 13], [5, 14], [5, 15], [5, 16], [5, 18], [5, 19], [6, 10], [6, 11], [6, 12], [6, 13], [6, 14], [6, 18], [7, 8], [7, 10], [7, 11], [7, 12], [7, 13], [7, 15], [7, 16], [7, 19], [8, 13], [8, 14], [8, 15], [8, 18], [8, 19], [9, 11], [9, 12], [9, 13], [9, 15], [9, 16], [9, 17], [9, 18], [9, 19], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [10, 17], [10, 18], [11, 12], [11, 13], [11, 14], [11, 15], [11, 17], [12, 13], [12, 14], [12, 15], [12, 16], [13, 14], [13, 15], [13, 18], [15, 16], [15, 18], [16, 19]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l3-s0/solution/solve.sh b/tasks/construct-nppc-clique-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c127db4188fa60d26b7c6e6e743a7f5401e8e512 --- /dev/null +++ b/tasks/construct-nppc-clique-l3-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [0, 1, 3, 5, 6, 10, 11, 12, 13, 14]} +RLMATH_EOF diff --git a/tasks/construct-nppc-clique-l3-s0/tests/check.py b/tasks/construct-nppc-clique-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..98eb4fc9097fcfa31988cf0a8b79280cec2b7980 --- /dev/null +++ b/tasks/construct-nppc-clique-l3-s0/tests/check.py @@ -0,0 +1,19 @@ +"""Clique of size >= k. Accepts any valid clique.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + c = int_list(ans.get("clique"), None, 0, n - 1, "clique") + # upstream NPPC verifier checks len(list) >= k but only tests pairs u < v, so [v, v, ..., v] passed + if len(set(c)) != len(c): + raise Invalid("clique contains duplicates") + if len(c) < k: + raise Invalid(f"clique has {len(c)} < {k} vertices") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(c), 2): + if (u, v) not in es: + raise Invalid(f"no edge between {u} and {v}") + return None, {"size": len(c)} diff --git a/tasks/construct-nppc-clique-l3-s0/tests/instance.json b/tasks/construct-nppc-clique-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9e7bf49b70282a5ab90cf9526c3574eb1a173b06 --- /dev/null +++ b/tasks/construct-nppc-clique-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 20, "k": 10, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 10], [0, 11], [0, 12], [0, 13], [0, 14], [0, 15], [0, 16], [0, 17], [0, 19], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 16], [1, 19], [2, 4], [2, 9], [2, 10], [2, 11], [2, 17], [2, 18], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 10], [3, 11], [3, 12], [3, 13], [3, 14], [3, 15], [3, 16], [3, 18], [3, 19], [4, 6], [4, 7], [4, 10], [4, 11], [4, 12], [4, 14], [4, 16], [4, 18], [4, 19], [5, 6], [5, 7], [5, 8], [5, 10], [5, 11], [5, 12], [5, 13], [5, 14], [5, 15], [5, 16], [5, 18], [5, 19], [6, 10], [6, 11], [6, 12], [6, 13], [6, 14], [6, 18], [7, 8], [7, 10], [7, 11], [7, 12], [7, 13], [7, 15], [7, 16], [7, 19], [8, 13], [8, 14], [8, 15], [8, 18], [8, 19], [9, 11], [9, 12], [9, 13], [9, 15], [9, 16], [9, 17], [9, 18], [9, 19], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [10, 17], [10, 18], [11, 12], [11, 13], [11, 14], [11, 15], [11, 17], [12, 13], [12, 14], [12, 15], [12, 16], [13, 14], [13, 15], [13, 18], [15, 16], [15, 18], [16, 19]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l3-s0/tests/run.py b/tasks/construct-nppc-clique-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-clique-l3-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-clique-l3-s0/tests/test.sh b/tasks/construct-nppc-clique-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-clique-l3-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-clique-l3-s7/environment/Dockerfile b/tasks/construct-nppc-clique-l3-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-clique-l3-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-clique-l3-s7/environment/instance.json b/tasks/construct-nppc-clique-l3-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..adfed3c00536c554e0e78881ce57fc5b32b4f6f2 --- /dev/null +++ b/tasks/construct-nppc-clique-l3-s7/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 20, "k": 10, "edges": [[0, 4], [0, 6], [0, 7], [0, 8], [0, 11], [0, 13], [0, 14], [0, 18], [0, 19], [1, 2], [1, 3], [1, 6], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 16], [1, 17], [1, 18], [2, 9], [2, 10], [2, 11], [2, 12], [2, 16], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 14], [3, 18], [3, 19], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [4, 13], [4, 14], [4, 15], [4, 16], [4, 18], [4, 19], [5, 6], [5, 19], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [6, 15], [6, 16], [6, 17], [6, 18], [6, 19], [7, 8], [7, 9], [7, 10], [7, 13], [7, 17], [7, 19], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [8, 15], [8, 17], [8, 18], [9, 10], [9, 11], [9, 12], [9, 13], [9, 15], [9, 16], [9, 17], [9, 18], [9, 19], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [10, 18], [11, 12], [11, 13], [11, 15], [11, 17], [11, 18], [12, 13], [12, 15], [12, 17], [12, 18], [12, 19], [13, 15], [13, 16], [13, 18], [13, 19], [14, 15], [14, 16], [14, 17], [14, 19], [15, 17], [15, 18], [15, 19], [16, 17], [16, 19], [17, 18], [18, 19]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l3-s7/solution/solve.sh b/tasks/construct-nppc-clique-l3-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2904c3f3c4e9ca00e96502817b67f466d20925e0 --- /dev/null +++ b/tasks/construct-nppc-clique-l3-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [4, 6, 8, 9, 10, 11, 12, 13, 15, 18]} +RLMATH_EOF diff --git a/tasks/construct-nppc-clique-l3-s7/tests/check.py b/tasks/construct-nppc-clique-l3-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..98eb4fc9097fcfa31988cf0a8b79280cec2b7980 --- /dev/null +++ b/tasks/construct-nppc-clique-l3-s7/tests/check.py @@ -0,0 +1,19 @@ +"""Clique of size >= k. Accepts any valid clique.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + c = int_list(ans.get("clique"), None, 0, n - 1, "clique") + # upstream NPPC verifier checks len(list) >= k but only tests pairs u < v, so [v, v, ..., v] passed + if len(set(c)) != len(c): + raise Invalid("clique contains duplicates") + if len(c) < k: + raise Invalid(f"clique has {len(c)} < {k} vertices") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(c), 2): + if (u, v) not in es: + raise Invalid(f"no edge between {u} and {v}") + return None, {"size": len(c)} diff --git a/tasks/construct-nppc-clique-l3-s7/tests/instance.json b/tasks/construct-nppc-clique-l3-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..adfed3c00536c554e0e78881ce57fc5b32b4f6f2 --- /dev/null +++ b/tasks/construct-nppc-clique-l3-s7/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 20, "k": 10, "edges": [[0, 4], [0, 6], [0, 7], [0, 8], [0, 11], [0, 13], [0, 14], [0, 18], [0, 19], [1, 2], [1, 3], [1, 6], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 16], [1, 17], [1, 18], [2, 9], [2, 10], [2, 11], [2, 12], [2, 16], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 14], [3, 18], [3, 19], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [4, 13], [4, 14], [4, 15], [4, 16], [4, 18], [4, 19], [5, 6], [5, 19], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [6, 15], [6, 16], [6, 17], [6, 18], [6, 19], [7, 8], [7, 9], [7, 10], [7, 13], [7, 17], [7, 19], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [8, 15], [8, 17], [8, 18], [9, 10], [9, 11], [9, 12], [9, 13], [9, 15], [9, 16], [9, 17], [9, 18], [9, 19], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [10, 18], [11, 12], [11, 13], [11, 15], [11, 17], [11, 18], [12, 13], [12, 15], [12, 17], [12, 18], [12, 19], [13, 15], [13, 16], [13, 18], [13, 19], [14, 15], [14, 16], [14, 17], [14, 19], [15, 17], [15, 18], [15, 19], [16, 17], [16, 19], [17, 18], [18, 19]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l3-s7/tests/run.py b/tasks/construct-nppc-clique-l3-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-clique-l3-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-clique-l3-s7/tests/test.sh b/tasks/construct-nppc-clique-l3-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-clique-l3-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-clique-l3-s9/environment/Dockerfile b/tasks/construct-nppc-clique-l3-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-clique-l3-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-clique-l3-s9/environment/instance.json b/tasks/construct-nppc-clique-l3-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..24984a93028f9d6d0f57ace62ed4fc397834e581 --- /dev/null +++ b/tasks/construct-nppc-clique-l3-s9/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 20, "k": 10, "edges": [[0, 1], [0, 2], [0, 3], [0, 6], [0, 9], [0, 10], [0, 11], [0, 12], [0, 15], [1, 3], [1, 4], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [2, 6], [2, 9], [2, 10], [2, 13], [2, 15], [2, 16], [2, 18], [3, 4], [3, 5], [3, 6], [3, 8], [3, 9], [3, 11], [3, 12], [3, 13], [3, 14], [3, 15], [3, 19], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 12], [4, 13], [4, 14], [4, 15], [4, 16], [4, 17], [4, 18], [4, 19], [5, 7], [5, 9], [5, 10], [5, 11], [5, 14], [5, 18], [5, 19], [6, 8], [6, 10], [6, 11], [6, 14], [7, 8], [7, 9], [7, 10], [7, 11], [7, 13], [7, 15], [7, 16], [7, 18], [7, 19], [8, 9], [8, 10], [8, 11], [8, 13], [8, 14], [8, 15], [8, 16], [8, 18], [8, 19], [9, 10], [9, 12], [9, 13], [9, 15], [9, 16], [9, 18], [9, 19], [10, 12], [10, 14], [10, 15], [10, 16], [10, 17], [10, 18], [10, 19], [11, 12], [11, 14], [11, 16], [11, 17], [11, 19], [12, 13], [12, 17], [12, 18], [12, 19], [13, 15], [13, 16], [13, 17], [14, 16], [14, 17], [14, 19], [15, 16], [15, 17], [15, 18], [15, 19], [16, 17], [16, 18], [16, 19], [18, 19]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l3-s9/solution/solve.sh b/tasks/construct-nppc-clique-l3-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a6c5887e4f8d0b68de6cc423e78878cd7bc9706d --- /dev/null +++ b/tasks/construct-nppc-clique-l3-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [1, 4, 7, 8, 9, 10, 15, 16, 18, 19]} +RLMATH_EOF diff --git a/tasks/construct-nppc-clique-l3-s9/tests/check.py b/tasks/construct-nppc-clique-l3-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..98eb4fc9097fcfa31988cf0a8b79280cec2b7980 --- /dev/null +++ b/tasks/construct-nppc-clique-l3-s9/tests/check.py @@ -0,0 +1,19 @@ +"""Clique of size >= k. Accepts any valid clique.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + c = int_list(ans.get("clique"), None, 0, n - 1, "clique") + # upstream NPPC verifier checks len(list) >= k but only tests pairs u < v, so [v, v, ..., v] passed + if len(set(c)) != len(c): + raise Invalid("clique contains duplicates") + if len(c) < k: + raise Invalid(f"clique has {len(c)} < {k} vertices") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(c), 2): + if (u, v) not in es: + raise Invalid(f"no edge between {u} and {v}") + return None, {"size": len(c)} diff --git a/tasks/construct-nppc-clique-l3-s9/tests/instance.json b/tasks/construct-nppc-clique-l3-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..24984a93028f9d6d0f57ace62ed4fc397834e581 --- /dev/null +++ b/tasks/construct-nppc-clique-l3-s9/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 20, "k": 10, "edges": [[0, 1], [0, 2], [0, 3], [0, 6], [0, 9], [0, 10], [0, 11], [0, 12], [0, 15], [1, 3], [1, 4], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [2, 6], [2, 9], [2, 10], [2, 13], [2, 15], [2, 16], [2, 18], [3, 4], [3, 5], [3, 6], [3, 8], [3, 9], [3, 11], [3, 12], [3, 13], [3, 14], [3, 15], [3, 19], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 12], [4, 13], [4, 14], [4, 15], [4, 16], [4, 17], [4, 18], [4, 19], [5, 7], [5, 9], [5, 10], [5, 11], [5, 14], [5, 18], [5, 19], [6, 8], [6, 10], [6, 11], [6, 14], [7, 8], [7, 9], [7, 10], [7, 11], [7, 13], [7, 15], [7, 16], [7, 18], [7, 19], [8, 9], [8, 10], [8, 11], [8, 13], [8, 14], [8, 15], [8, 16], [8, 18], [8, 19], [9, 10], [9, 12], [9, 13], [9, 15], [9, 16], [9, 18], [9, 19], [10, 12], [10, 14], [10, 15], [10, 16], [10, 17], [10, 18], [10, 19], [11, 12], [11, 14], [11, 16], [11, 17], [11, 19], [12, 13], [12, 17], [12, 18], [12, 19], [13, 15], [13, 16], [13, 17], [14, 16], [14, 17], [14, 19], [15, 16], [15, 17], [15, 18], [15, 19], [16, 17], [16, 18], [16, 19], [18, 19]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l3-s9/tests/run.py b/tasks/construct-nppc-clique-l3-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-clique-l3-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-clique-l3-s9/tests/test.sh b/tasks/construct-nppc-clique-l3-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-clique-l3-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-dominating-set-l3-s9/environment/Dockerfile b/tasks/construct-nppc-dominating-set-l3-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l3-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-dominating-set-l3-s9/environment/instance.json b/tasks/construct-nppc-dominating-set-l3-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..806a7d077069705b57f220a330037824f405484e --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l3-s9/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 50, "k": 20, "edges": [[0, 1], [0, 4], [0, 5], [0, 6], [0, 8], [0, 9], [0, 12], [0, 19], [0, 22], [0, 25], [0, 26], [0, 28], [0, 30], [0, 31], [0, 32], [0, 34], [0, 38], [0, 39], [0, 43], [0, 45], [0, 48], [1, 4], [1, 7], [1, 8], [1, 11], [1, 12], [1, 21], [1, 23], [1, 27], [1, 28], [1, 35], [1, 37], [1, 39], [1, 40], [1, 41], [1, 42], [1, 45], [1, 46], [1, 47], [1, 48], [1, 49], [2, 4], [2, 5], [2, 7], [2, 11], [2, 13], [2, 16], [2, 21], [2, 23], [2, 30], [2, 36], [2, 39], [2, 44], [2, 45], [2, 47], [2, 49], [3, 4], [3, 6], [3, 7], [3, 8], [3, 13], [3, 20], [3, 23], [3, 27], [3, 32], [3, 33], [3, 34], [3, 35], [3, 36], [3, 39], [3, 42], [3, 45], [4, 6], [4, 26], [4, 30], [4, 31], [4, 32], [4, 36], [4, 43], [4, 44], [4, 45], [4, 46], [4, 48], [5, 6], [5, 8], [5, 12], [5, 14], [5, 18], [5, 19], [5, 23], [5, 28], [5, 29], [5, 30], [5, 33], [5, 34], [5, 41], [5, 44], [5, 46], [5, 48], [5, 49], [6, 10], [6, 13], [6, 26], [6, 31], [6, 36], [6, 37], [6, 40], [6, 41], [6, 42], [6, 45], [6, 46], [6, 48], [6, 49], [7, 9], [7, 11], [7, 16], [7, 18], [7, 22], [7, 27], [7, 30], [7, 32], [7, 34], [7, 37], [7, 46], [8, 11], [8, 14], [8, 15], [8, 19], [8, 22], [8, 25], [8, 29], [8, 31], [8, 33], [8, 34], [8, 37], [8, 39], [8, 45], [8, 48], [9, 13], [9, 14], [9, 16], [9, 20], [9, 23], [9, 27], [9, 28], [9, 36], [9, 38], [9, 42], [10, 16], [10, 18], [10, 19], [10, 21], [10, 24], [10, 25], [10, 26], [10, 28], [10, 37], [10, 38], [10, 40], [10, 42], [10, 44], [10, 47], [11, 12], [11, 15], [11, 16], [11, 17], [11, 27], [11, 28], [11, 29], [11, 31], [11, 35], [11, 36], [11, 37], [11, 40], [11, 42], [11, 47], [12, 13], [12, 14], [12, 15], [12, 21], [12, 24], [12, 31], [12, 35], [12, 40], [12, 44], [12, 45], [12, 47], [12, 49], [13, 16], [13, 19], [13, 21], [13, 25], [13, 31], [13, 32], [13, 36], [13, 37], [13, 39], [13, 40], [14, 15], [14, 20], [14, 25], [14, 26], [14, 27], [14, 35], [14, 36], [14, 37], [14, 39], [14, 40], [14, 43], [14, 44], [14, 46], [14, 49], [15, 16], [15, 18], [15, 24], [15, 30], [15, 31], [15, 33], [15, 34], [15, 35], [15, 37], [15, 41], [15, 49], [16, 19], [16, 22], [16, 29], [16, 32], [16, 34], [16, 40], [16, 48], [16, 49], [17, 18], [17, 21], [17, 22], [17, 24], [17, 32], [17, 35], [17, 41], [17, 43], [17, 45], [17, 48], [17, 49], [18, 27], [18, 31], [18, 34], [18, 37], [18, 40], [18, 48], [18, 49], [19, 28], [19, 36], [19, 39], [19, 42], [19, 47], [19, 49], [20, 22], [20, 23], [20, 28], [20, 31], [20, 32], [20, 41], [21, 26], [21, 27], [21, 28], [21, 29], [21, 30], [21, 31], [21, 32], [21, 35], [21, 38], [21, 41], [21, 48], [22, 23], [22, 31], [22, 36], [22, 37], [22, 47], [23, 27], [23, 29], [23, 30], [23, 31], [23, 32], [23, 43], [24, 27], [24, 28], [24, 30], [24, 36], [24, 37], [24, 43], [24, 44], [24, 45], [24, 46], [24, 48], [25, 26], [25, 32], [25, 36], [25, 38], [25, 40], [25, 44], [25, 45], [26, 30], [26, 38], [26, 44], [26, 45], [26, 49], [27, 29], [27, 38], [27, 40], [27, 43], [27, 45], [27, 46], [28, 30], [28, 32], [28, 46], [29, 30], [29, 32], [29, 33], [29, 39], [29, 40], [29, 42], [29, 44], [30, 33], [30, 35], [30, 37], [30, 41], [30, 44], [30, 48], [31, 36], [31, 38], [31, 41], [31, 43], [32, 33], [32, 36], [32, 44], [32, 49], [33, 36], [33, 42], [33, 44], [33, 46], [33, 49], [34, 35], [34, 39], [34, 41], [34, 43], [34, 44], [34, 47], [35, 38], [35, 40], [35, 43], [35, 46], [36, 38], [36, 42], [36, 44], [36, 48], [37, 41], [37, 42], [38, 40], [38, 41], [38, 46], [38, 47], [38, 48], [39, 40], [39, 42], [39, 46], [39, 49], [40, 43], [40, 44], [40, 47], [41, 42], [41, 44], [41, 48], [42, 45], [43, 44], [43, 48], [43, 49], [44, 49], [45, 46], [45, 47], [46, 49]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l3-s9/solution/solve.sh b/tasks/construct-nppc-dominating-set-l3-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..eb7d75f83a37b815b3ea86f01ad70a9d75038604 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l3-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"dominating_set": [0, 1, 4, 6, 7, 9, 10, 11, 14, 15, 16, 19, 20, 21, 23, 33, 35, 36, 37, 49]} +RLMATH_EOF diff --git a/tasks/construct-nppc-dominating-set-l3-s9/tests/check.py b/tasks/construct-nppc-dominating-set-l3-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0677a7bcbccb02297d022ffa4b5dd15da6371bff --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l3-s9/tests/check.py @@ -0,0 +1,23 @@ +"""Dominating set of size <= k. Accepts any valid dominating set.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + # upstream NPPC verifier has no type/range checks (out-of-range labels and floats are silently used) + d = int_list(ans.get("dominating_set"), None, 0, n - 1, "dominating_set") + if len(set(d)) != len(d): + raise Invalid("dominating_set contains duplicates") + if not d or len(d) > k: + raise Invalid(f"dominating_set must have 1..{k} vertices, got {len(d)}") + dom = set(d) + s = set(d) + for u, v in inst["edges"]: + if u in s: + dom.add(v) + if v in s: + dom.add(u) + if len(dom) != n: + miss = min(set(range(n)) - dom) + raise Invalid(f"vertex {miss} is not dominated") + return None, {"size": len(d)} diff --git a/tasks/construct-nppc-dominating-set-l3-s9/tests/instance.json b/tasks/construct-nppc-dominating-set-l3-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..806a7d077069705b57f220a330037824f405484e --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l3-s9/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 50, "k": 20, "edges": [[0, 1], [0, 4], [0, 5], [0, 6], [0, 8], [0, 9], [0, 12], [0, 19], [0, 22], [0, 25], [0, 26], [0, 28], [0, 30], [0, 31], [0, 32], [0, 34], [0, 38], [0, 39], [0, 43], [0, 45], [0, 48], [1, 4], [1, 7], [1, 8], [1, 11], [1, 12], [1, 21], [1, 23], [1, 27], [1, 28], [1, 35], [1, 37], [1, 39], [1, 40], [1, 41], [1, 42], [1, 45], [1, 46], [1, 47], [1, 48], [1, 49], [2, 4], [2, 5], [2, 7], [2, 11], [2, 13], [2, 16], [2, 21], [2, 23], [2, 30], [2, 36], [2, 39], [2, 44], [2, 45], [2, 47], [2, 49], [3, 4], [3, 6], [3, 7], [3, 8], [3, 13], [3, 20], [3, 23], [3, 27], [3, 32], [3, 33], [3, 34], [3, 35], [3, 36], [3, 39], [3, 42], [3, 45], [4, 6], [4, 26], [4, 30], [4, 31], [4, 32], [4, 36], [4, 43], [4, 44], [4, 45], [4, 46], [4, 48], [5, 6], [5, 8], [5, 12], [5, 14], [5, 18], [5, 19], [5, 23], [5, 28], [5, 29], [5, 30], [5, 33], [5, 34], [5, 41], [5, 44], [5, 46], [5, 48], [5, 49], [6, 10], [6, 13], [6, 26], [6, 31], [6, 36], [6, 37], [6, 40], [6, 41], [6, 42], [6, 45], [6, 46], [6, 48], [6, 49], [7, 9], [7, 11], [7, 16], [7, 18], [7, 22], [7, 27], [7, 30], [7, 32], [7, 34], [7, 37], [7, 46], [8, 11], [8, 14], [8, 15], [8, 19], [8, 22], [8, 25], [8, 29], [8, 31], [8, 33], [8, 34], [8, 37], [8, 39], [8, 45], [8, 48], [9, 13], [9, 14], [9, 16], [9, 20], [9, 23], [9, 27], [9, 28], [9, 36], [9, 38], [9, 42], [10, 16], [10, 18], [10, 19], [10, 21], [10, 24], [10, 25], [10, 26], [10, 28], [10, 37], [10, 38], [10, 40], [10, 42], [10, 44], [10, 47], [11, 12], [11, 15], [11, 16], [11, 17], [11, 27], [11, 28], [11, 29], [11, 31], [11, 35], [11, 36], [11, 37], [11, 40], [11, 42], [11, 47], [12, 13], [12, 14], [12, 15], [12, 21], [12, 24], [12, 31], [12, 35], [12, 40], [12, 44], [12, 45], [12, 47], [12, 49], [13, 16], [13, 19], [13, 21], [13, 25], [13, 31], [13, 32], [13, 36], [13, 37], [13, 39], [13, 40], [14, 15], [14, 20], [14, 25], [14, 26], [14, 27], [14, 35], [14, 36], [14, 37], [14, 39], [14, 40], [14, 43], [14, 44], [14, 46], [14, 49], [15, 16], [15, 18], [15, 24], [15, 30], [15, 31], [15, 33], [15, 34], [15, 35], [15, 37], [15, 41], [15, 49], [16, 19], [16, 22], [16, 29], [16, 32], [16, 34], [16, 40], [16, 48], [16, 49], [17, 18], [17, 21], [17, 22], [17, 24], [17, 32], [17, 35], [17, 41], [17, 43], [17, 45], [17, 48], [17, 49], [18, 27], [18, 31], [18, 34], [18, 37], [18, 40], [18, 48], [18, 49], [19, 28], [19, 36], [19, 39], [19, 42], [19, 47], [19, 49], [20, 22], [20, 23], [20, 28], [20, 31], [20, 32], [20, 41], [21, 26], [21, 27], [21, 28], [21, 29], [21, 30], [21, 31], [21, 32], [21, 35], [21, 38], [21, 41], [21, 48], [22, 23], [22, 31], [22, 36], [22, 37], [22, 47], [23, 27], [23, 29], [23, 30], [23, 31], [23, 32], [23, 43], [24, 27], [24, 28], [24, 30], [24, 36], [24, 37], [24, 43], [24, 44], [24, 45], [24, 46], [24, 48], [25, 26], [25, 32], [25, 36], [25, 38], [25, 40], [25, 44], [25, 45], [26, 30], [26, 38], [26, 44], [26, 45], [26, 49], [27, 29], [27, 38], [27, 40], [27, 43], [27, 45], [27, 46], [28, 30], [28, 32], [28, 46], [29, 30], [29, 32], [29, 33], [29, 39], [29, 40], [29, 42], [29, 44], [30, 33], [30, 35], [30, 37], [30, 41], [30, 44], [30, 48], [31, 36], [31, 38], [31, 41], [31, 43], [32, 33], [32, 36], [32, 44], [32, 49], [33, 36], [33, 42], [33, 44], [33, 46], [33, 49], [34, 35], [34, 39], [34, 41], [34, 43], [34, 44], [34, 47], [35, 38], [35, 40], [35, 43], [35, 46], [36, 38], [36, 42], [36, 44], [36, 48], [37, 41], [37, 42], [38, 40], [38, 41], [38, 46], [38, 47], [38, 48], [39, 40], [39, 42], [39, 46], [39, 49], [40, 43], [40, 44], [40, 47], [41, 42], [41, 44], [41, 48], [42, 45], [43, 44], [43, 48], [43, 49], [44, 49], [45, 46], [45, 47], [46, 49]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l3-s9/tests/run.py b/tasks/construct-nppc-dominating-set-l3-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l3-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-dominating-set-l3-s9/tests/test.sh b/tasks/construct-nppc-dominating-set-l3-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l3-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-independent-set-l2-s0/environment/Dockerfile b/tasks/construct-nppc-independent-set-l2-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l2-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-independent-set-l2-s0/environment/instance.json b/tasks/construct-nppc-independent-set-l2-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c7424f76f31752b1305f71aaa88c6e83d1a075f3 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l2-s0/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 16, "k": 8, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 14], [1, 2], [1, 5], [1, 8], [1, 9], [1, 12], [1, 15], [2, 6], [3, 5], [3, 6], [3, 9], [3, 12], [3, 13], [4, 6], [4, 12], [5, 7], [5, 11], [5, 12], [5, 13], [5, 14], [6, 8], [6, 9], [6, 15], [7, 8], [7, 12], [8, 9], [8, 12], [8, 14], [8, 15], [9, 11], [9, 14], [11, 12], [12, 14], [12, 15], [13, 14], [13, 15]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l2-s0/solution/solve.sh b/tasks/construct-nppc-independent-set-l2-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..50aa02ed423c0260fa2d8fbf3c5eddf8593da2cc --- /dev/null +++ b/tasks/construct-nppc-independent-set-l2-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"independent_set": [2, 3, 4, 7, 10, 11, 14, 15]} +RLMATH_EOF diff --git a/tasks/construct-nppc-independent-set-l2-s0/tests/check.py b/tasks/construct-nppc-independent-set-l2-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..92279a931488c7f39c08a3b11162b3f54a9c662a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l2-s0/tests/check.py @@ -0,0 +1,19 @@ +"""Independent set of size >= k. Accepts any valid independent set.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + s = int_list(ans.get("independent_set"), None, 0, n - 1, "independent_set") + # upstream NPPC verifier checks len(list) >= size but only tests pairs u < v, so [v]*k passed + if len(set(s)) != len(s): + raise Invalid("independent_set contains duplicates") + if len(s) < k: + raise Invalid(f"independent_set has {len(s)} < {k} vertices") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(s), 2): + if (u, v) in es: + raise Invalid(f"edge between {u} and {v}") + return None, {"size": len(s)} diff --git a/tasks/construct-nppc-independent-set-l2-s0/tests/instance.json b/tasks/construct-nppc-independent-set-l2-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c7424f76f31752b1305f71aaa88c6e83d1a075f3 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l2-s0/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 16, "k": 8, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 14], [1, 2], [1, 5], [1, 8], [1, 9], [1, 12], [1, 15], [2, 6], [3, 5], [3, 6], [3, 9], [3, 12], [3, 13], [4, 6], [4, 12], [5, 7], [5, 11], [5, 12], [5, 13], [5, 14], [6, 8], [6, 9], [6, 15], [7, 8], [7, 12], [8, 9], [8, 12], [8, 14], [8, 15], [9, 11], [9, 14], [11, 12], [12, 14], [12, 15], [13, 14], [13, 15]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l2-s0/tests/run.py b/tasks/construct-nppc-independent-set-l2-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l2-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-independent-set-l2-s0/tests/test.sh b/tasks/construct-nppc-independent-set-l2-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l2-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-independent-set-l2-s7/environment/instance.json b/tasks/construct-nppc-independent-set-l2-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f0efd90207188e83a4f5ac2f096f3a304255578d --- /dev/null +++ b/tasks/construct-nppc-independent-set-l2-s7/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 16, "k": 8, "edges": [[0, 2], [0, 5], [0, 8], [0, 9], [0, 12], [0, 13], [0, 14], [0, 15], [1, 2], [1, 3], [1, 4], [1, 8], [1, 12], [1, 14], [1, 15], [2, 3], [2, 7], [2, 14], [3, 5], [3, 6], [3, 7], [3, 9], [3, 10], [3, 13], [3, 14], [3, 15], [4, 11], [4, 15], [5, 11], [5, 15], [6, 11], [6, 13], [6, 15], [7, 8], [7, 9], [7, 10], [7, 13], [7, 14], [7, 15], [8, 13], [8, 14], [9, 13], [9, 15], [10, 13], [10, 14], [11, 12], [11, 14], [12, 13], [12, 14], [13, 14], [13, 15]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l2-s9/environment/Dockerfile b/tasks/construct-nppc-independent-set-l2-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l2-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-independent-set-l2-s9/environment/instance.json b/tasks/construct-nppc-independent-set-l2-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ea43bbb2de1dafd96e4973dfe4716556b7f1d403 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l2-s9/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 16, "k": 8, "edges": [[0, 5], [0, 6], [0, 14], [0, 15], [1, 2], [1, 3], [1, 7], [1, 8], [2, 3], [2, 6], [2, 7], [2, 12], [2, 13], [2, 14], [2, 15], [3, 4], [3, 5], [3, 6], [3, 7], [3, 9], [3, 10], [3, 13], [3, 14], [3, 15], [4, 7], [4, 9], [4, 10], [4, 13], [4, 14], [4, 15], [5, 7], [5, 13], [6, 7], [6, 8], [6, 13], [7, 9], [7, 10], [7, 13], [8, 9], [8, 13], [8, 14], [10, 15], [11, 15], [12, 13], [12, 15], [13, 15], [14, 15]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l2-s9/solution/solve.sh b/tasks/construct-nppc-independent-set-l2-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..749a5d5ed9a503224f4ac6e5ac6c8520b53d529e --- /dev/null +++ b/tasks/construct-nppc-independent-set-l2-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"independent_set": [1, 5, 6, 9, 10, 11, 12, 14]} +RLMATH_EOF diff --git a/tasks/construct-nppc-independent-set-l2-s9/tests/check.py b/tasks/construct-nppc-independent-set-l2-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..92279a931488c7f39c08a3b11162b3f54a9c662a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l2-s9/tests/check.py @@ -0,0 +1,19 @@ +"""Independent set of size >= k. Accepts any valid independent set.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + s = int_list(ans.get("independent_set"), None, 0, n - 1, "independent_set") + # upstream NPPC verifier checks len(list) >= size but only tests pairs u < v, so [v]*k passed + if len(set(s)) != len(s): + raise Invalid("independent_set contains duplicates") + if len(s) < k: + raise Invalid(f"independent_set has {len(s)} < {k} vertices") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(s), 2): + if (u, v) in es: + raise Invalid(f"edge between {u} and {v}") + return None, {"size": len(s)} diff --git a/tasks/construct-nppc-independent-set-l2-s9/tests/instance.json b/tasks/construct-nppc-independent-set-l2-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ea43bbb2de1dafd96e4973dfe4716556b7f1d403 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l2-s9/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 16, "k": 8, "edges": [[0, 5], [0, 6], [0, 14], [0, 15], [1, 2], [1, 3], [1, 7], [1, 8], [2, 3], [2, 6], [2, 7], [2, 12], [2, 13], [2, 14], [2, 15], [3, 4], [3, 5], [3, 6], [3, 7], [3, 9], [3, 10], [3, 13], [3, 14], [3, 15], [4, 7], [4, 9], [4, 10], [4, 13], [4, 14], [4, 15], [5, 7], [5, 13], [6, 7], [6, 8], [6, 13], [7, 9], [7, 10], [7, 13], [8, 9], [8, 13], [8, 14], [10, 15], [11, 15], [12, 13], [12, 15], [13, 15], [14, 15]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l2-s9/tests/run.py b/tasks/construct-nppc-independent-set-l2-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l2-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-independent-set-l2-s9/tests/test.sh b/tasks/construct-nppc-independent-set-l2-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l2-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-independent-set-l6-s1/environment/Dockerfile b/tasks/construct-nppc-independent-set-l6-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l6-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-independent-set-l6-s1/environment/instance.json b/tasks/construct-nppc-independent-set-l6-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6db9348e34ab0a05318d2ed82af4ffdf921e8451 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l6-s1/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 100, "k": 30, "edges": [[0, 4], [0, 5], [0, 7], [0, 12], [0, 15], [0, 17], [0, 18], [0, 20], [0, 24], [0, 26], [0, 27], [0, 30], [0, 31], [0, 32], [0, 35], [0, 37], [0, 43], [0, 46], [0, 48], [0, 49], [0, 51], [0, 53], [0, 59], [0, 63], [0, 65], [0, 78], [0, 80], [0, 87], [0, 92], [0, 93], [0, 95], [0, 96], [0, 97], [1, 3], [1, 14], [1, 15], [1, 22], [1, 27], [1, 39], [1, 40], [1, 46], [1, 57], [1, 59], [1, 64], [1, 65], [1, 68], [1, 71], [1, 74], [1, 86], [1, 92], [1, 94], [2, 3], [2, 4], [2, 7], [2, 8], [2, 10], [2, 13], [2, 14], [2, 17], [2, 18], [2, 19], [2, 26], [2, 33], [2, 40], [2, 42], [2, 44], [2, 47], [2, 48], [2, 52], [2, 55], [2, 57], [2, 65], [2, 66], [2, 69], [2, 70], [2, 78], [2, 79], [2, 81], [2, 83], [2, 85], [2, 86], [2, 92], [2, 94], [2, 97], [3, 5], [3, 7], [3, 15], [3, 17], [3, 18], [3, 19], [3, 20], [3, 24], [3, 31], [3, 40], [3, 41], [3, 44], [3, 47], [3, 58], [3, 59], [3, 62], [3, 64], [3, 74], [3, 79], [3, 82], [3, 85], [3, 91], [3, 93], [3, 99], [4, 8], [4, 17], [4, 26], [4, 28], [4, 38], [4, 47], [4, 50], [4, 56], [4, 61], [4, 64], [4, 66], [4, 67], [4, 68], [4, 71], [4, 74], [4, 75], [4, 79], [4, 81], [4, 85], [4, 92], [4, 94], [4, 97], [5, 7], [5, 11], [5, 12], [5, 13], [5, 17], [5, 22], [5, 28], [5, 44], [5, 62], [5, 66], [5, 71], [5, 73], [5, 76], [5, 85], [5, 86], [5, 92], [5, 96], [5, 97], [6, 12], [6, 15], [6, 23], [6, 25], [6, 27], [6, 28], [6, 29], [6, 37], [6, 38], [6, 39], [6, 40], [6, 41], [6, 43], [6, 45], [6, 46], [6, 48], [6, 53], [6, 57], [6, 58], [6, 60], [6, 64], [6, 68], [6, 75], [6, 77], [6, 79], [6, 93], [6, 94], [7, 13], [7, 16], [7, 22], [7, 25], [7, 30], [7, 32], [7, 33], [7, 34], [7, 47], [7, 56], [7, 57], [7, 64], [7, 68], [7, 75], [7, 81], [7, 83], [7, 87], [7, 90], [7, 99], [8, 10], [8, 13], [8, 15], [8, 16], [8, 19], [8, 25], [8, 27], [8, 32], [8, 35], [8, 36], [8, 37], [8, 44], [8, 45], [8, 50], [8, 53], [8, 57], [8, 62], [8, 66], [8, 70], [8, 71], [8, 74], [8, 78], [8, 83], [8, 84], [8, 86], [8, 88], [8, 91], [8, 95], [8, 97], [8, 98], [9, 12], [9, 15], [9, 17], [9, 20], [9, 24], [9, 29], [9, 30], [9, 35], [9, 39], [9, 40], [9, 44], [9, 46], [9, 50], [9, 57], [9, 59], [9, 61], [9, 62], [9, 64], [9, 71], [9, 72], [9, 75], [9, 85], [9, 94], [10, 11], [10, 12], [10, 18], [10, 24], [10, 25], [10, 27], [10, 31], [10, 33], [10, 37], [10, 41], [10, 46], [10, 49], [10, 51], [10, 53], [10, 56], [10, 58], [10, 59], [10, 66], [10, 69], [10, 70], [10, 72], [10, 74], [10, 75], [10, 80], [10, 87], [10, 89], [10, 91], [10, 92], [10, 96], [11, 16], [11, 18], [11, 25], [11, 29], [11, 32], [11, 41], [11, 46], [11, 47], [11, 51], [11, 56], [11, 62], [11, 64], [11, 65], [11, 70], [11, 73], [11, 76], [11, 78], [11, 81], [11, 83], [11, 85], [11, 86], [11, 88], [11, 90], [11, 91], [11, 92], [11, 93], [11, 96], [12, 15], [12, 16], [12, 18], [12, 25], [12, 31], [12, 32], [12, 33], [12, 38], [12, 39], [12, 41], [12, 43], [12, 51], [12, 54], [12, 56], [12, 57], [12, 58], [12, 59], [12, 61], [12, 64], [12, 66], [12, 71], [12, 72], [12, 74], [12, 79], [12, 81], [12, 86], [12, 88], [12, 91], [12, 93], [12, 94], [12, 97], [13, 14], [13, 25], [13, 27], [13, 28], [13, 34], [13, 35], [13, 38], [13, 41], [13, 45], [13, 48], [13, 50], [13, 53], [13, 55], [13, 57], [13, 58], [13, 59], [13, 65], [13, 67], [13, 68], [13, 70], [13, 71], [13, 72], [13, 77], [13, 78], [13, 81], [13, 82], [13, 83], [13, 85], [13, 89], [13, 90], [13, 94], [13, 95], [13, 99], [14, 16], [14, 17], [14, 22], [14, 28], [14, 32], [14, 38], [14, 39], [14, 41], [14, 42], [14, 46], [14, 48], [14, 50], [14, 51], [14, 56], [14, 57], [14, 67], [14, 73], [14, 75], [14, 76], [14, 93], [14, 97], [15, 17], [15, 20], [15, 21], [15, 23], [15, 24], [15, 26], [15, 27], [15, 31], [15, 35], [15, 36], [15, 37], [15, 42], [15, 43], [15, 45], [15, 46], [15, 47], [15, 48], [15, 50], [15, 53], [15, 54], [15, 55], [15, 57], [15, 63], [15, 65], [15, 72], [15, 75], [15, 78], [15, 80], [15, 83], [15, 84], [15, 85], [15, 91], [15, 93], [15, 99], [16, 21], [16, 28], [16, 29], [16, 38], [16, 42], [16, 44], [16, 51], [16, 56], [16, 58], [16, 64], [16, 67], [16, 70], [16, 72], [16, 73], [16, 74], [16, 75], [16, 80], [16, 83], [16, 84], [16, 85], [16, 87], [16, 92], [16, 97], [16, 98], [17, 18], [17, 19], [17, 20], [17, 22], [17, 24], [17, 27], [17, 33], [17, 35], [17, 40], [17, 41], [17, 42], [17, 45], [17, 50], [17, 52], [17, 53], [17, 54], [17, 56], [17, 59], [17, 62], [17, 64], [17, 67], [17, 71], [17, 73], [17, 75], [17, 76], [17, 78], [17, 81], [17, 82], [17, 84], [17, 87], [17, 90], [17, 92], [17, 93], [18, 22], [18, 23], [18, 24], [18, 25], [18, 27], [18, 38], [18, 49], [18, 50], [18, 53], [18, 57], [18, 58], [18, 62], [18, 65], [18, 74], [18, 77], [18, 78], [18, 84], [18, 86], [18, 88], [18, 89], [18, 93], [19, 20], [19, 22], [19, 36], [19, 37], [19, 40], [19, 46], [19, 48], [19, 49], [19, 55], [19, 59], [19, 60], [19, 61], [19, 62], [19, 63], [19, 64], [19, 79], [19, 80], [19, 84], [19, 85], [19, 86], [19, 90], [19, 97], [19, 99], [20, 22], [20, 24], [20, 25], [20, 26], [20, 30], [20, 31], [20, 51], [20, 62], [20, 64], [20, 66], [20, 67], [20, 68], [20, 69], [20, 70], [20, 76], [20, 77], [20, 78], [20, 79], [20, 85], [20, 87], [20, 88], [20, 92], [20, 97], [21, 22], [21, 24], [21, 25], [21, 27], [21, 34], [21, 38], [21, 39], [21, 40], [21, 43], [21, 47], [21, 48], [21, 49], [21, 52], [21, 57], [21, 59], [21, 65], [21, 68], [21, 71], [21, 72], [21, 73], [21, 74], [21, 76], [21, 77], [21, 80], [21, 84], [21, 89], [21, 90], [21, 94], [21, 97], [21, 99], [22, 24], [22, 30], [22, 31], [22, 33], [22, 37], [22, 40], [22, 47], [22, 49], [22, 50], [22, 53], [22, 57], [22, 66], [22, 69], [22, 72], [22, 73], [22, 75], [22, 77], [22, 78], [22, 83], [22, 85], [22, 96], [22, 97], [23, 25], [23, 26], [23, 27], [23, 28], [23, 29], [23, 30], [23, 36], [23, 38], [23, 39], [23, 40], [23, 41], [23, 47], [23, 48], [23, 49], [23, 51], [23, 52], [23, 53], [23, 55], [23, 56], [23, 64], [23, 76], [23, 85], [23, 86], [23, 90], [23, 91], [23, 92], [23, 94], [24, 27], [24, 38], [24, 41], [24, 42], [24, 43], [24, 44], [24, 46], [24, 47], [24, 57], [24, 58], [24, 64], [24, 65], [24, 66], [24, 68], [24, 75], [24, 76], [24, 78], [24, 79], [24, 81], [24, 83], [24, 85], [24, 89], [24, 91], [24, 93], [24, 94], [24, 95], [24, 97], [24, 99], [25, 29], [25, 35], [25, 55], [25, 56], [25, 62], [25, 68], [25, 69], [25, 81], [25, 85], [25, 91], [25, 92], [25, 96], [25, 97], [26, 38], [26, 41], [26, 44], [26, 48], [26, 50], [26, 53], [26, 54], [26, 58], [26, 59], [26, 62], [26, 63], [26, 64], [26, 69], [26, 70], [26, 80], [26, 83], [26, 84], [26, 85], [26, 86], [26, 92], [26, 93], [26, 94], [27, 31], [27, 38], [27, 40], [27, 46], [27, 54], [27, 55], [27, 56], [27, 57], [27, 61], [27, 62], [27, 63], [27, 69], [27, 70], [27, 75], [27, 78], [27, 82], [27, 90], [27, 93], [27, 94], [27, 96], [28, 29], [28, 32], [28, 33], [28, 35], [28, 38], [28, 44], [28, 48], [28, 54], [28, 60], [28, 65], [28, 66], [28, 67], [28, 68], [28, 69], [28, 73], [28, 74], [28, 85], [28, 87], [28, 88], [28, 89], [28, 90], [28, 93], [28, 96], [28, 98], [28, 99], [29, 31], [29, 33], [29, 34], [29, 36], [29, 37], [29, 39], [29, 41], [29, 47], [29, 52], [29, 55], [29, 74], [29, 77], [29, 80], [29, 81], [29, 83], [29, 84], [29, 85], [29, 86], [29, 91], [29, 92], [29, 94], [29, 95], [29, 98], [29, 99], [30, 31], [30, 32], [30, 34], [30, 36], [30, 40], [30, 41], [30, 47], [30, 50], [30, 58], [30, 61], [30, 62], [30, 73], [30, 74], [30, 75], [30, 76], [30, 80], [30, 82], [30, 85], [30, 89], [30, 90], [30, 91], [30, 92], [30, 99], [31, 35], [31, 43], [31, 51], [31, 54], [31, 61], [31, 62], [31, 64], [31, 65], [31, 66], [31, 69], [31, 71], [31, 72], [31, 73], [31, 76], [31, 77], [31, 80], [31, 85], [31, 87], [32, 35], [32, 51], [32, 55], [32, 56], [32, 61], [32, 69], [32, 77], [32, 80], [32, 85], [32, 94], [33, 39], [33, 47], [33, 49], [33, 50], [33, 51], [33, 54], [33, 57], [33, 64], [33, 66], [33, 72], [33, 74], [33, 79], [33, 80], [33, 81], [33, 86], [34, 39], [34, 62], [34, 67], [34, 68], [34, 81], [34, 86], [34, 90], [34, 92], [35, 42], [35, 43], [35, 48], [35, 54], [35, 56], [35, 62], [35, 63], [35, 64], [35, 69], [35, 73], [35, 75], [35, 78], [35, 82], [35, 87], [35, 90], [35, 92], [35, 95], [36, 38], [36, 44], [36, 46], [36, 47], [36, 49], [36, 50], [36, 54], [36, 57], [36, 62], [36, 66], [36, 67], [36, 68], [36, 74], [36, 77], [36, 80], [37, 39], [37, 43], [37, 56], [37, 61], [37, 62], [37, 67], [37, 69], [37, 72], [37, 85], [37, 91], [37, 92], [38, 40], [38, 43], [38, 45], [38, 46], [38, 49], [38, 50], [38, 52], [38, 55], [38, 62], [38, 64], [38, 65], [38, 74], [38, 76], [38, 77], [38, 78], [38, 81], [38, 82], [38, 83], [38, 85], [38, 87], [38, 88], [38, 90], [38, 91], [38, 92], [38, 93], [39, 40], [39, 41], [39, 47], [39, 49], [39, 53], [39, 59], [39, 62], [39, 63], [39, 64], [39, 65], [39, 66], [39, 85], [39, 86], [39, 91], [39, 95], [39, 96], [39, 97], [40, 42], [40, 45], [40, 46], [40, 51], [40, 57], [40, 58], [40, 61], [40, 63], [40, 65], [40, 67], [40, 68], [40, 70], [40, 73], [40, 75], [40, 76], [40, 81], [40, 89], [40, 90], [40, 91], [40, 92], [40, 93], [40, 98], [40, 99], [41, 42], [41, 48], [41, 55], [41, 57], [41, 60], [41, 62], [41, 67], [41, 75], [41, 79], [41, 80], [41, 86], [41, 89], [41, 90], [41, 91], [41, 93], [41, 94], [41, 95], [42, 44], [42, 47], [42, 57], [42, 65], [42, 67], [42, 73], [42, 80], [42, 92], [42, 96], [43, 45], [43, 48], [43, 51], [43, 60], [43, 61], [43, 63], [43, 64], [43, 65], [43, 68], [43, 70], [43, 73], [43, 74], [43, 79], [43, 80], [43, 81], [43, 88], [43, 90], [43, 92], [43, 99], [44, 48], [44, 51], [44, 53], [44, 61], [44, 66], [44, 76], [44, 77], [44, 78], [44, 81], [44, 82], [44, 83], [44, 85], [44, 86], [44, 90], [44, 91], [44, 94], [44, 96], [45, 46], [45, 47], [45, 56], [45, 57], [45, 64], [45, 65], [45, 69], [45, 76], [45, 77], [45, 94], [45, 96], [46, 47], [46, 51], [46, 57], [46, 60], [46, 68], [46, 73], [46, 74], [46, 77], [46, 81], [46, 84], [46, 90], [46, 92], [46, 94], [47, 49], [47, 57], [47, 65], [47, 67], [47, 74], [47, 75], [47, 76], [47, 78], [47, 79], [47, 83], [47, 87], [47, 91], [47, 92], [47, 97], [48, 49], [48, 50], [48, 54], [48, 66], [48, 75], [48, 76], [48, 81], [48, 85], [48, 86], [48, 94], [48, 97], [49, 53], [49, 55], [49, 58], [49, 60], [49, 61], [49, 62], [49, 64], [49, 65], [49, 68], [49, 72], [49, 77], [49, 81], [49, 84], [49, 87], [49, 88], [49, 89], [49, 94], [49, 97], [49, 98], [50, 52], [50, 55], [50, 59], [50, 61], [50, 63], [50, 64], [50, 66], [50, 68], [50, 69], [50, 73], [50, 75], [50, 76], [50, 77], [50, 88], [50, 93], [51, 57], [51, 60], [51, 61], [51, 64], [51, 65], [51, 74], [51, 76], [51, 78], [51, 80], [51, 83], [51, 90], [51, 94], [51, 99], [52, 56], [52, 62], [52, 65], [52, 75], [52, 77], [52, 85], [52, 90], [52, 91], [52, 92], [52, 94], [53, 55], [53, 64], [53, 65], [53, 72], [53, 74], [53, 81], [53, 86], [53, 90], [53, 91], [53, 94], [53, 96], [54, 57], [54, 62], [54, 63], [54, 64], [54, 71], [54, 73], [54, 74], [54, 78], [54, 80], [54, 81], [54, 83], [54, 84], [54, 92], [54, 95], [54, 99], [55, 64], [55, 66], [55, 67], [55, 68], [55, 73], [55, 75], [55, 76], [55, 83], [55, 84], [55, 90], [55, 93], [55, 97], [55, 99], [56, 60], [56, 61], [56, 79], [56, 88], [56, 89], [56, 90], [56, 91], [56, 92], [56, 94], [57, 63], [57, 67], [57, 68], [57, 71], [57, 73], [57, 77], [57, 79], [57, 81], [57, 88], [57, 92], [58, 64], [58, 69], [58, 72], [58, 74], [58, 76], [58, 85], [58, 86], [58, 87], [59, 60], [59, 61], [59, 66], [59, 71], [59, 85], [59, 90], [59, 95], [59, 97], [60, 61], [60, 64], [60, 69], [60, 71], [60, 79], [60, 87], [60, 97], [61, 64], [61, 65], [61, 71], [61, 72], [61, 73], [61, 76], [61, 78], [61, 82], [61, 83], [61, 92], [61, 95], [62, 68], [62, 69], [62, 76], [62, 77], [62, 79], [62, 80], [62, 83], [62, 92], [62, 96], [62, 98], [63, 64], [63, 67], [63, 71], [63, 72], [63, 81], [63, 85], [63, 92], [63, 96], [64, 67], [64, 68], [64, 70], [64, 73], [64, 79], [64, 80], [64, 81], [64, 82], [64, 84], [64, 86], [64, 88], [64, 93], [64, 94], [64, 98], [64, 99], [65, 68], [65, 70], [65, 74], [65, 76], [65, 85], [65, 89], [65, 95], [65, 97], [66, 70], [66, 71], [66, 74], [66, 76], [66, 80], [66, 85], [66, 89], [66, 91], [66, 93], [66, 97], [67, 68], [67, 77], [67, 85], [67, 91], [67, 92], [67, 96], [68, 70], [68, 73], [68, 75], [68, 78], [68, 82], [68, 85], [68, 87], [68, 91], [68, 93], [68, 94], [68, 96], [68, 99], [69, 76], [69, 78], [69, 90], [69, 96], [69, 97], [70, 87], [70, 92], [70, 94], [71, 74], [71, 77], [71, 80], [71, 83], [71, 85], [71, 86], [72, 75], [72, 76], [72, 82], [72, 84], [72, 89], [72, 93], [72, 98], [72, 99], [73, 77], [73, 78], [73, 80], [73, 83], [73, 88], [73, 98], [73, 99], [74, 77], [74, 80], [74, 82], [74, 85], [74, 87], [74, 89], [74, 90], [74, 91], [74, 98], [74, 99], [75, 82], [75, 83], [75, 85], [75, 88], [75, 92], [75, 94], [75, 96], [76, 78], [76, 81], [76, 82], [76, 83], [76, 84], [76, 88], [76, 89], [76, 90], [76, 91], [76, 97], [77, 84], [77, 86], [77, 88], [77, 97], [78, 86], [78, 87], [78, 91], [78, 94], [78, 97], [79, 81], [79, 82], [79, 86], [79, 89], [79, 90], [79, 94], [79, 95], [79, 96], [80, 83], [80, 84], [80, 85], [80, 87], [80, 88], [80, 89], [80, 93], [80, 96], [80, 97], [80, 99], [81, 87], [81, 94], [81, 96], [81, 97], [82, 87], [82, 90], [82, 92], [83, 86], [83, 87], [83, 91], [84, 97], [85, 92], [86, 89], [86, 91], [86, 95], [87, 95], [88, 94], [89, 90], [89, 94], [89, 96], [89, 97], [90, 93], [90, 94], [90, 95], [90, 96], [91, 94], [91, 97], [91, 99], [92, 95], [92, 96], [92, 97], [92, 99], [93, 94], [94, 95], [94, 96], [95, 97], [96, 98], [97, 99]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l6-s1/solution/solve.sh b/tasks/construct-nppc-independent-set-l6-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b7523fbfa0bdcb09a52ab535c85bbcd16e71fdd6 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l6-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"independent_set": [1, 4, 5, 9, 25, 31, 32, 33, 34, 36, 37, 42, 45, 48, 52, 53, 58, 60, 63, 70, 78, 82, 83, 84, 88, 89, 93, 95, 98, 99]} +RLMATH_EOF diff --git a/tasks/construct-nppc-independent-set-l6-s1/tests/check.py b/tasks/construct-nppc-independent-set-l6-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..92279a931488c7f39c08a3b11162b3f54a9c662a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l6-s1/tests/check.py @@ -0,0 +1,19 @@ +"""Independent set of size >= k. Accepts any valid independent set.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + s = int_list(ans.get("independent_set"), None, 0, n - 1, "independent_set") + # upstream NPPC verifier checks len(list) >= size but only tests pairs u < v, so [v]*k passed + if len(set(s)) != len(s): + raise Invalid("independent_set contains duplicates") + if len(s) < k: + raise Invalid(f"independent_set has {len(s)} < {k} vertices") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(s), 2): + if (u, v) in es: + raise Invalid(f"edge between {u} and {v}") + return None, {"size": len(s)} diff --git a/tasks/construct-nppc-independent-set-l6-s1/tests/instance.json b/tasks/construct-nppc-independent-set-l6-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6db9348e34ab0a05318d2ed82af4ffdf921e8451 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l6-s1/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 100, "k": 30, "edges": [[0, 4], [0, 5], [0, 7], [0, 12], [0, 15], [0, 17], [0, 18], [0, 20], [0, 24], [0, 26], [0, 27], [0, 30], [0, 31], [0, 32], [0, 35], [0, 37], [0, 43], [0, 46], [0, 48], [0, 49], [0, 51], [0, 53], [0, 59], [0, 63], [0, 65], [0, 78], [0, 80], [0, 87], [0, 92], [0, 93], [0, 95], [0, 96], [0, 97], [1, 3], [1, 14], [1, 15], [1, 22], [1, 27], [1, 39], [1, 40], [1, 46], [1, 57], [1, 59], [1, 64], [1, 65], [1, 68], [1, 71], [1, 74], [1, 86], [1, 92], [1, 94], [2, 3], [2, 4], [2, 7], [2, 8], [2, 10], [2, 13], [2, 14], [2, 17], [2, 18], [2, 19], [2, 26], [2, 33], [2, 40], [2, 42], [2, 44], [2, 47], [2, 48], [2, 52], [2, 55], [2, 57], [2, 65], [2, 66], [2, 69], [2, 70], [2, 78], [2, 79], [2, 81], [2, 83], [2, 85], [2, 86], [2, 92], [2, 94], [2, 97], [3, 5], [3, 7], [3, 15], [3, 17], [3, 18], [3, 19], [3, 20], [3, 24], [3, 31], [3, 40], [3, 41], [3, 44], [3, 47], [3, 58], [3, 59], [3, 62], [3, 64], [3, 74], [3, 79], [3, 82], [3, 85], [3, 91], [3, 93], [3, 99], [4, 8], [4, 17], [4, 26], [4, 28], [4, 38], [4, 47], [4, 50], [4, 56], [4, 61], [4, 64], [4, 66], [4, 67], [4, 68], [4, 71], [4, 74], [4, 75], [4, 79], [4, 81], [4, 85], [4, 92], [4, 94], [4, 97], [5, 7], [5, 11], [5, 12], [5, 13], [5, 17], [5, 22], [5, 28], [5, 44], [5, 62], [5, 66], [5, 71], [5, 73], [5, 76], [5, 85], [5, 86], [5, 92], [5, 96], [5, 97], [6, 12], [6, 15], [6, 23], [6, 25], [6, 27], [6, 28], [6, 29], [6, 37], [6, 38], [6, 39], [6, 40], [6, 41], [6, 43], [6, 45], [6, 46], [6, 48], [6, 53], [6, 57], [6, 58], [6, 60], [6, 64], [6, 68], [6, 75], [6, 77], [6, 79], [6, 93], [6, 94], [7, 13], [7, 16], [7, 22], [7, 25], [7, 30], [7, 32], [7, 33], [7, 34], [7, 47], [7, 56], [7, 57], [7, 64], [7, 68], [7, 75], [7, 81], [7, 83], [7, 87], [7, 90], [7, 99], [8, 10], [8, 13], [8, 15], [8, 16], [8, 19], [8, 25], [8, 27], [8, 32], [8, 35], [8, 36], [8, 37], [8, 44], [8, 45], [8, 50], [8, 53], [8, 57], [8, 62], [8, 66], [8, 70], [8, 71], [8, 74], [8, 78], [8, 83], [8, 84], [8, 86], [8, 88], [8, 91], [8, 95], [8, 97], [8, 98], [9, 12], [9, 15], [9, 17], [9, 20], [9, 24], [9, 29], [9, 30], [9, 35], [9, 39], [9, 40], [9, 44], [9, 46], [9, 50], [9, 57], [9, 59], [9, 61], [9, 62], [9, 64], [9, 71], [9, 72], [9, 75], [9, 85], [9, 94], [10, 11], [10, 12], [10, 18], [10, 24], [10, 25], [10, 27], [10, 31], [10, 33], [10, 37], [10, 41], [10, 46], [10, 49], [10, 51], [10, 53], [10, 56], [10, 58], [10, 59], [10, 66], [10, 69], [10, 70], [10, 72], [10, 74], [10, 75], [10, 80], [10, 87], [10, 89], [10, 91], [10, 92], [10, 96], [11, 16], [11, 18], [11, 25], [11, 29], [11, 32], [11, 41], [11, 46], [11, 47], [11, 51], [11, 56], [11, 62], [11, 64], [11, 65], [11, 70], [11, 73], [11, 76], [11, 78], [11, 81], [11, 83], [11, 85], [11, 86], [11, 88], [11, 90], [11, 91], [11, 92], [11, 93], [11, 96], [12, 15], [12, 16], [12, 18], [12, 25], [12, 31], [12, 32], [12, 33], [12, 38], [12, 39], [12, 41], [12, 43], [12, 51], [12, 54], [12, 56], [12, 57], [12, 58], [12, 59], [12, 61], [12, 64], [12, 66], [12, 71], [12, 72], [12, 74], [12, 79], [12, 81], [12, 86], [12, 88], [12, 91], [12, 93], [12, 94], [12, 97], [13, 14], [13, 25], [13, 27], [13, 28], [13, 34], [13, 35], [13, 38], [13, 41], [13, 45], [13, 48], [13, 50], [13, 53], [13, 55], [13, 57], [13, 58], [13, 59], [13, 65], [13, 67], [13, 68], [13, 70], [13, 71], [13, 72], [13, 77], [13, 78], [13, 81], [13, 82], [13, 83], [13, 85], [13, 89], [13, 90], [13, 94], [13, 95], [13, 99], [14, 16], [14, 17], [14, 22], [14, 28], [14, 32], [14, 38], [14, 39], [14, 41], [14, 42], [14, 46], [14, 48], [14, 50], [14, 51], [14, 56], [14, 57], [14, 67], [14, 73], [14, 75], [14, 76], [14, 93], [14, 97], [15, 17], [15, 20], [15, 21], [15, 23], [15, 24], [15, 26], [15, 27], [15, 31], [15, 35], [15, 36], [15, 37], [15, 42], [15, 43], [15, 45], [15, 46], [15, 47], [15, 48], [15, 50], [15, 53], [15, 54], [15, 55], [15, 57], [15, 63], [15, 65], [15, 72], [15, 75], [15, 78], [15, 80], [15, 83], [15, 84], [15, 85], [15, 91], [15, 93], [15, 99], [16, 21], [16, 28], [16, 29], [16, 38], [16, 42], [16, 44], [16, 51], [16, 56], [16, 58], [16, 64], [16, 67], [16, 70], [16, 72], [16, 73], [16, 74], [16, 75], [16, 80], [16, 83], [16, 84], [16, 85], [16, 87], [16, 92], [16, 97], [16, 98], [17, 18], [17, 19], [17, 20], [17, 22], [17, 24], [17, 27], [17, 33], [17, 35], [17, 40], [17, 41], [17, 42], [17, 45], [17, 50], [17, 52], [17, 53], [17, 54], [17, 56], [17, 59], [17, 62], [17, 64], [17, 67], [17, 71], [17, 73], [17, 75], [17, 76], [17, 78], [17, 81], [17, 82], [17, 84], [17, 87], [17, 90], [17, 92], [17, 93], [18, 22], [18, 23], [18, 24], [18, 25], [18, 27], [18, 38], [18, 49], [18, 50], [18, 53], [18, 57], [18, 58], [18, 62], [18, 65], [18, 74], [18, 77], [18, 78], [18, 84], [18, 86], [18, 88], [18, 89], [18, 93], [19, 20], [19, 22], [19, 36], [19, 37], [19, 40], [19, 46], [19, 48], [19, 49], [19, 55], [19, 59], [19, 60], [19, 61], [19, 62], [19, 63], [19, 64], [19, 79], [19, 80], [19, 84], [19, 85], [19, 86], [19, 90], [19, 97], [19, 99], [20, 22], [20, 24], [20, 25], [20, 26], [20, 30], [20, 31], [20, 51], [20, 62], [20, 64], [20, 66], [20, 67], [20, 68], [20, 69], [20, 70], [20, 76], [20, 77], [20, 78], [20, 79], [20, 85], [20, 87], [20, 88], [20, 92], [20, 97], [21, 22], [21, 24], [21, 25], [21, 27], [21, 34], [21, 38], [21, 39], [21, 40], [21, 43], [21, 47], [21, 48], [21, 49], [21, 52], [21, 57], [21, 59], [21, 65], [21, 68], [21, 71], [21, 72], [21, 73], [21, 74], [21, 76], [21, 77], [21, 80], [21, 84], [21, 89], [21, 90], [21, 94], [21, 97], [21, 99], [22, 24], [22, 30], [22, 31], [22, 33], [22, 37], [22, 40], [22, 47], [22, 49], [22, 50], [22, 53], [22, 57], [22, 66], [22, 69], [22, 72], [22, 73], [22, 75], [22, 77], [22, 78], [22, 83], [22, 85], [22, 96], [22, 97], [23, 25], [23, 26], [23, 27], [23, 28], [23, 29], [23, 30], [23, 36], [23, 38], [23, 39], [23, 40], [23, 41], [23, 47], [23, 48], [23, 49], [23, 51], [23, 52], [23, 53], [23, 55], [23, 56], [23, 64], [23, 76], [23, 85], [23, 86], [23, 90], [23, 91], [23, 92], [23, 94], [24, 27], [24, 38], [24, 41], [24, 42], [24, 43], [24, 44], [24, 46], [24, 47], [24, 57], [24, 58], [24, 64], [24, 65], [24, 66], [24, 68], [24, 75], [24, 76], [24, 78], [24, 79], [24, 81], [24, 83], [24, 85], [24, 89], [24, 91], [24, 93], [24, 94], [24, 95], [24, 97], [24, 99], [25, 29], [25, 35], [25, 55], [25, 56], [25, 62], [25, 68], [25, 69], [25, 81], [25, 85], [25, 91], [25, 92], [25, 96], [25, 97], [26, 38], [26, 41], [26, 44], [26, 48], [26, 50], [26, 53], [26, 54], [26, 58], [26, 59], [26, 62], [26, 63], [26, 64], [26, 69], [26, 70], [26, 80], [26, 83], [26, 84], [26, 85], [26, 86], [26, 92], [26, 93], [26, 94], [27, 31], [27, 38], [27, 40], [27, 46], [27, 54], [27, 55], [27, 56], [27, 57], [27, 61], [27, 62], [27, 63], [27, 69], [27, 70], [27, 75], [27, 78], [27, 82], [27, 90], [27, 93], [27, 94], [27, 96], [28, 29], [28, 32], [28, 33], [28, 35], [28, 38], [28, 44], [28, 48], [28, 54], [28, 60], [28, 65], [28, 66], [28, 67], [28, 68], [28, 69], [28, 73], [28, 74], [28, 85], [28, 87], [28, 88], [28, 89], [28, 90], [28, 93], [28, 96], [28, 98], [28, 99], [29, 31], [29, 33], [29, 34], [29, 36], [29, 37], [29, 39], [29, 41], [29, 47], [29, 52], [29, 55], [29, 74], [29, 77], [29, 80], [29, 81], [29, 83], [29, 84], [29, 85], [29, 86], [29, 91], [29, 92], [29, 94], [29, 95], [29, 98], [29, 99], [30, 31], [30, 32], [30, 34], [30, 36], [30, 40], [30, 41], [30, 47], [30, 50], [30, 58], [30, 61], [30, 62], [30, 73], [30, 74], [30, 75], [30, 76], [30, 80], [30, 82], [30, 85], [30, 89], [30, 90], [30, 91], [30, 92], [30, 99], [31, 35], [31, 43], [31, 51], [31, 54], [31, 61], [31, 62], [31, 64], [31, 65], [31, 66], [31, 69], [31, 71], [31, 72], [31, 73], [31, 76], [31, 77], [31, 80], [31, 85], [31, 87], [32, 35], [32, 51], [32, 55], [32, 56], [32, 61], [32, 69], [32, 77], [32, 80], [32, 85], [32, 94], [33, 39], [33, 47], [33, 49], [33, 50], [33, 51], [33, 54], [33, 57], [33, 64], [33, 66], [33, 72], [33, 74], [33, 79], [33, 80], [33, 81], [33, 86], [34, 39], [34, 62], [34, 67], [34, 68], [34, 81], [34, 86], [34, 90], [34, 92], [35, 42], [35, 43], [35, 48], [35, 54], [35, 56], [35, 62], [35, 63], [35, 64], [35, 69], [35, 73], [35, 75], [35, 78], [35, 82], [35, 87], [35, 90], [35, 92], [35, 95], [36, 38], [36, 44], [36, 46], [36, 47], [36, 49], [36, 50], [36, 54], [36, 57], [36, 62], [36, 66], [36, 67], [36, 68], [36, 74], [36, 77], [36, 80], [37, 39], [37, 43], [37, 56], [37, 61], [37, 62], [37, 67], [37, 69], [37, 72], [37, 85], [37, 91], [37, 92], [38, 40], [38, 43], [38, 45], [38, 46], [38, 49], [38, 50], [38, 52], [38, 55], [38, 62], [38, 64], [38, 65], [38, 74], [38, 76], [38, 77], [38, 78], [38, 81], [38, 82], [38, 83], [38, 85], [38, 87], [38, 88], [38, 90], [38, 91], [38, 92], [38, 93], [39, 40], [39, 41], [39, 47], [39, 49], [39, 53], [39, 59], [39, 62], [39, 63], [39, 64], [39, 65], [39, 66], [39, 85], [39, 86], [39, 91], [39, 95], [39, 96], [39, 97], [40, 42], [40, 45], [40, 46], [40, 51], [40, 57], [40, 58], [40, 61], [40, 63], [40, 65], [40, 67], [40, 68], [40, 70], [40, 73], [40, 75], [40, 76], [40, 81], [40, 89], [40, 90], [40, 91], [40, 92], [40, 93], [40, 98], [40, 99], [41, 42], [41, 48], [41, 55], [41, 57], [41, 60], [41, 62], [41, 67], [41, 75], [41, 79], [41, 80], [41, 86], [41, 89], [41, 90], [41, 91], [41, 93], [41, 94], [41, 95], [42, 44], [42, 47], [42, 57], [42, 65], [42, 67], [42, 73], [42, 80], [42, 92], [42, 96], [43, 45], [43, 48], [43, 51], [43, 60], [43, 61], [43, 63], [43, 64], [43, 65], [43, 68], [43, 70], [43, 73], [43, 74], [43, 79], [43, 80], [43, 81], [43, 88], [43, 90], [43, 92], [43, 99], [44, 48], [44, 51], [44, 53], [44, 61], [44, 66], [44, 76], [44, 77], [44, 78], [44, 81], [44, 82], [44, 83], [44, 85], [44, 86], [44, 90], [44, 91], [44, 94], [44, 96], [45, 46], [45, 47], [45, 56], [45, 57], [45, 64], [45, 65], [45, 69], [45, 76], [45, 77], [45, 94], [45, 96], [46, 47], [46, 51], [46, 57], [46, 60], [46, 68], [46, 73], [46, 74], [46, 77], [46, 81], [46, 84], [46, 90], [46, 92], [46, 94], [47, 49], [47, 57], [47, 65], [47, 67], [47, 74], [47, 75], [47, 76], [47, 78], [47, 79], [47, 83], [47, 87], [47, 91], [47, 92], [47, 97], [48, 49], [48, 50], [48, 54], [48, 66], [48, 75], [48, 76], [48, 81], [48, 85], [48, 86], [48, 94], [48, 97], [49, 53], [49, 55], [49, 58], [49, 60], [49, 61], [49, 62], [49, 64], [49, 65], [49, 68], [49, 72], [49, 77], [49, 81], [49, 84], [49, 87], [49, 88], [49, 89], [49, 94], [49, 97], [49, 98], [50, 52], [50, 55], [50, 59], [50, 61], [50, 63], [50, 64], [50, 66], [50, 68], [50, 69], [50, 73], [50, 75], [50, 76], [50, 77], [50, 88], [50, 93], [51, 57], [51, 60], [51, 61], [51, 64], [51, 65], [51, 74], [51, 76], [51, 78], [51, 80], [51, 83], [51, 90], [51, 94], [51, 99], [52, 56], [52, 62], [52, 65], [52, 75], [52, 77], [52, 85], [52, 90], [52, 91], [52, 92], [52, 94], [53, 55], [53, 64], [53, 65], [53, 72], [53, 74], [53, 81], [53, 86], [53, 90], [53, 91], [53, 94], [53, 96], [54, 57], [54, 62], [54, 63], [54, 64], [54, 71], [54, 73], [54, 74], [54, 78], [54, 80], [54, 81], [54, 83], [54, 84], [54, 92], [54, 95], [54, 99], [55, 64], [55, 66], [55, 67], [55, 68], [55, 73], [55, 75], [55, 76], [55, 83], [55, 84], [55, 90], [55, 93], [55, 97], [55, 99], [56, 60], [56, 61], [56, 79], [56, 88], [56, 89], [56, 90], [56, 91], [56, 92], [56, 94], [57, 63], [57, 67], [57, 68], [57, 71], [57, 73], [57, 77], [57, 79], [57, 81], [57, 88], [57, 92], [58, 64], [58, 69], [58, 72], [58, 74], [58, 76], [58, 85], [58, 86], [58, 87], [59, 60], [59, 61], [59, 66], [59, 71], [59, 85], [59, 90], [59, 95], [59, 97], [60, 61], [60, 64], [60, 69], [60, 71], [60, 79], [60, 87], [60, 97], [61, 64], [61, 65], [61, 71], [61, 72], [61, 73], [61, 76], [61, 78], [61, 82], [61, 83], [61, 92], [61, 95], [62, 68], [62, 69], [62, 76], [62, 77], [62, 79], [62, 80], [62, 83], [62, 92], [62, 96], [62, 98], [63, 64], [63, 67], [63, 71], [63, 72], [63, 81], [63, 85], [63, 92], [63, 96], [64, 67], [64, 68], [64, 70], [64, 73], [64, 79], [64, 80], [64, 81], [64, 82], [64, 84], [64, 86], [64, 88], [64, 93], [64, 94], [64, 98], [64, 99], [65, 68], [65, 70], [65, 74], [65, 76], [65, 85], [65, 89], [65, 95], [65, 97], [66, 70], [66, 71], [66, 74], [66, 76], [66, 80], [66, 85], [66, 89], [66, 91], [66, 93], [66, 97], [67, 68], [67, 77], [67, 85], [67, 91], [67, 92], [67, 96], [68, 70], [68, 73], [68, 75], [68, 78], [68, 82], [68, 85], [68, 87], [68, 91], [68, 93], [68, 94], [68, 96], [68, 99], [69, 76], [69, 78], [69, 90], [69, 96], [69, 97], [70, 87], [70, 92], [70, 94], [71, 74], [71, 77], [71, 80], [71, 83], [71, 85], [71, 86], [72, 75], [72, 76], [72, 82], [72, 84], [72, 89], [72, 93], [72, 98], [72, 99], [73, 77], [73, 78], [73, 80], [73, 83], [73, 88], [73, 98], [73, 99], [74, 77], [74, 80], [74, 82], [74, 85], [74, 87], [74, 89], [74, 90], [74, 91], [74, 98], [74, 99], [75, 82], [75, 83], [75, 85], [75, 88], [75, 92], [75, 94], [75, 96], [76, 78], [76, 81], [76, 82], [76, 83], [76, 84], [76, 88], [76, 89], [76, 90], [76, 91], [76, 97], [77, 84], [77, 86], [77, 88], [77, 97], [78, 86], [78, 87], [78, 91], [78, 94], [78, 97], [79, 81], [79, 82], [79, 86], [79, 89], [79, 90], [79, 94], [79, 95], [79, 96], [80, 83], [80, 84], [80, 85], [80, 87], [80, 88], [80, 89], [80, 93], [80, 96], [80, 97], [80, 99], [81, 87], [81, 94], [81, 96], [81, 97], [82, 87], [82, 90], [82, 92], [83, 86], [83, 87], [83, 91], [84, 97], [85, 92], [86, 89], [86, 91], [86, 95], [87, 95], [88, 94], [89, 90], [89, 94], [89, 96], [89, 97], [90, 93], [90, 94], [90, 95], [90, 96], [91, 94], [91, 97], [91, 99], [92, 95], [92, 96], [92, 97], [92, 99], [93, 94], [94, 95], [94, 96], [95, 97], [96, 98], [97, 99]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l6-s1/tests/run.py b/tasks/construct-nppc-independent-set-l6-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l6-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-independent-set-l6-s1/tests/test.sh b/tasks/construct-nppc-independent-set-l6-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l6-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-independent-set-l6-s6/environment/Dockerfile b/tasks/construct-nppc-independent-set-l6-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l6-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-independent-set-l6-s6/environment/instance.json b/tasks/construct-nppc-independent-set-l6-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bde3921b96be4fdf9cca54e1dc43086a7a1b8ced --- /dev/null +++ b/tasks/construct-nppc-independent-set-l6-s6/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 100, "k": 30, "edges": [[0, 1], [0, 9], [0, 11], [0, 14], [0, 16], [0, 21], [0, 24], [0, 28], [0, 30], [0, 39], [0, 42], [0, 44], [0, 45], [0, 46], [0, 51], [0, 54], [0, 58], [0, 65], [0, 69], [0, 70], [0, 71], [0, 72], [0, 73], [0, 80], [0, 82], [0, 84], [0, 87], [0, 96], [0, 98], [1, 5], [1, 9], [1, 10], [1, 11], [1, 12], [1, 18], [1, 21], [1, 27], [1, 28], [1, 33], [1, 38], [1, 41], [1, 46], [1, 51], [1, 55], [1, 59], [1, 60], [1, 63], [1, 66], [1, 70], [1, 72], [1, 73], [1, 77], [1, 78], [1, 79], [1, 81], [1, 85], [1, 89], [1, 91], [1, 95], [2, 5], [2, 9], [2, 13], [2, 15], [2, 17], [2, 20], [2, 33], [2, 37], [2, 38], [2, 39], [2, 42], [2, 46], [2, 50], [2, 52], [2, 55], [2, 59], [2, 60], [2, 66], [2, 67], [2, 78], [2, 82], [2, 83], [2, 87], [2, 91], [2, 97], [2, 99], [3, 4], [3, 6], [3, 10], [3, 14], [3, 17], [3, 19], [3, 20], [3, 21], [3, 28], [3, 30], [3, 40], [3, 44], [3, 45], [3, 46], [3, 52], [3, 53], [3, 54], [3, 55], [3, 57], [3, 62], [3, 66], [3, 67], [3, 73], [3, 76], [3, 77], [3, 87], [3, 99], [4, 5], [4, 7], [4, 9], [4, 12], [4, 13], [4, 15], [4, 17], [4, 26], [4, 27], [4, 28], [4, 33], [4, 36], [4, 42], [4, 48], [4, 50], [4, 52], [4, 54], [4, 57], [4, 58], [4, 59], [4, 62], [4, 67], [4, 69], [4, 75], [4, 77], [4, 81], [4, 89], [4, 92], [4, 93], [4, 97], [5, 6], [5, 7], [5, 9], [5, 11], [5, 12], [5, 14], [5, 19], [5, 21], [5, 27], [5, 33], [5, 37], [5, 50], [5, 52], [5, 53], [5, 54], [5, 55], [5, 56], [5, 59], [5, 64], [5, 66], [5, 69], [5, 71], [5, 75], [5, 78], [5, 81], [5, 82], [5, 84], [5, 89], [5, 90], [5, 92], [5, 98], [5, 99], [6, 8], [6, 10], [6, 12], [6, 13], [6, 16], [6, 22], [6, 23], [6, 24], [6, 27], [6, 28], [6, 32], [6, 35], [6, 39], [6, 40], [6, 41], [6, 47], [6, 50], [6, 55], [6, 67], [6, 68], [6, 69], [6, 73], [6, 76], [6, 77], [6, 78], [6, 85], [6, 88], [6, 96], [6, 98], [6, 99], [7, 9], [7, 15], [7, 21], [7, 22], [7, 25], [7, 28], [7, 29], [7, 31], [7, 36], [7, 40], [7, 42], [7, 46], [7, 48], [7, 50], [7, 53], [7, 54], [7, 56], [7, 57], [7, 58], [7, 59], [7, 60], [7, 63], [7, 65], [7, 66], [7, 68], [7, 69], [7, 70], [7, 76], [7, 77], [7, 81], [7, 84], [7, 87], [7, 88], [7, 89], [7, 91], [8, 10], [8, 15], [8, 22], [8, 23], [8, 32], [8, 35], [8, 37], [8, 39], [8, 41], [8, 43], [8, 50], [8, 51], [8, 54], [8, 63], [8, 67], [8, 74], [8, 78], [8, 81], [8, 86], [8, 89], [8, 90], [8, 91], [8, 94], [8, 99], [9, 12], [9, 13], [9, 16], [9, 19], [9, 27], [9, 29], [9, 31], [9, 34], [9, 38], [9, 39], [9, 42], [9, 53], [9, 56], [9, 57], [9, 81], [9, 88], [9, 90], [9, 91], [9, 93], [9, 94], [10, 18], [10, 19], [10, 25], [10, 29], [10, 42], [10, 45], [10, 50], [10, 57], [10, 60], [10, 62], [10, 76], [10, 88], [10, 91], [10, 92], [10, 94], [10, 95], [10, 96], [11, 12], [11, 14], [11, 15], [11, 22], [11, 28], [11, 29], [11, 32], [11, 34], [11, 35], [11, 40], [11, 42], [11, 43], [11, 46], [11, 50], [11, 52], [11, 54], [11, 58], [11, 68], [11, 70], [11, 71], [11, 72], [11, 73], [11, 74], [11, 83], [11, 89], [11, 93], [11, 95], [11, 98], [12, 16], [12, 17], [12, 20], [12, 21], [12, 24], [12, 34], [12, 37], [12, 40], [12, 50], [12, 54], [12, 58], [12, 66], [12, 67], [12, 79], [12, 80], [12, 85], [12, 90], [12, 98], [13, 21], [13, 27], [13, 39], [13, 44], [13, 45], [13, 53], [13, 58], [13, 65], [13, 67], [13, 68], [13, 76], [13, 79], [13, 80], [13, 90], [14, 23], [14, 24], [14, 30], [14, 34], [14, 36], [14, 38], [14, 42], [14, 46], [14, 47], [14, 51], [14, 52], [14, 53], [14, 54], [14, 55], [14, 57], [14, 58], [14, 60], [14, 62], [14, 64], [14, 66], [14, 68], [14, 70], [14, 72], [14, 74], [14, 80], [14, 83], [14, 86], [14, 90], [14, 91], [14, 92], [14, 96], [15, 27], [15, 29], [15, 42], [15, 43], [15, 46], [15, 54], [15, 57], [15, 58], [15, 62], [15, 64], [15, 67], [15, 69], [15, 70], [15, 80], [15, 82], [15, 84], [15, 90], [15, 96], [16, 17], [16, 19], [16, 23], [16, 26], [16, 27], [16, 46], [16, 55], [16, 58], [16, 59], [16, 61], [16, 69], [16, 75], [16, 77], [16, 81], [16, 84], [16, 90], [16, 92], [16, 97], [16, 99], [17, 20], [17, 21], [17, 25], [17, 32], [17, 33], [17, 37], [17, 43], [17, 52], [17, 54], [17, 62], [17, 64], [17, 65], [17, 69], [17, 70], [17, 71], [17, 77], [17, 80], [17, 82], [17, 83], [17, 88], [17, 93], [18, 23], [18, 24], [18, 25], [18, 27], [18, 29], [18, 31], [18, 34], [18, 37], [18, 43], [18, 49], [18, 50], [18, 53], [18, 57], [18, 64], [18, 69], [18, 70], [18, 71], [18, 72], [18, 74], [18, 80], [18, 86], [18, 90], [18, 92], [18, 93], [19, 20], [19, 21], [19, 22], [19, 23], [19, 29], [19, 31], [19, 33], [19, 34], [19, 36], [19, 38], [19, 45], [19, 63], [19, 64], [19, 65], [19, 66], [19, 67], [19, 73], [19, 75], [19, 77], [19, 78], [19, 80], [19, 81], [19, 87], [19, 89], [19, 92], [20, 21], [20, 22], [20, 23], [20, 25], [20, 28], [20, 35], [20, 39], [20, 40], [20, 47], [20, 53], [20, 55], [20, 59], [20, 60], [20, 67], [20, 70], [20, 73], [20, 75], [20, 80], [20, 86], [20, 92], [20, 94], [21, 25], [21, 30], [21, 33], [21, 35], [21, 39], [21, 41], [21, 43], [21, 45], [21, 46], [21, 51], [21, 53], [21, 56], [21, 59], [21, 62], [21, 64], [21, 65], [21, 69], [21, 73], [21, 74], [21, 78], [21, 79], [21, 80], [21, 86], [21, 90], [21, 91], [21, 93], [22, 29], [22, 40], [22, 43], [22, 45], [22, 48], [22, 50], [22, 51], [22, 55], [22, 62], [22, 69], [22, 70], [22, 71], [22, 76], [22, 77], [22, 82], [22, 84], [22, 86], [23, 25], [23, 28], [23, 29], [23, 31], [23, 37], [23, 39], [23, 40], [23, 43], [23, 66], [23, 67], [23, 68], [23, 71], [23, 72], [23, 82], [23, 84], [23, 87], [23, 96], [24, 26], [24, 27], [24, 28], [24, 30], [24, 31], [24, 32], [24, 36], [24, 40], [24, 49], [24, 51], [24, 54], [24, 55], [24, 56], [24, 58], [24, 60], [24, 61], [24, 64], [24, 69], [24, 70], [24, 71], [24, 74], [24, 79], [24, 80], [24, 81], [24, 83], [24, 90], [24, 93], [24, 94], [24, 98], [25, 27], [25, 29], [25, 30], [25, 31], [25, 32], [25, 33], [25, 37], [25, 38], [25, 40], [25, 50], [25, 61], [25, 63], [25, 72], [25, 75], [25, 76], [25, 77], [25, 82], [25, 87], [25, 91], [25, 94], [25, 95], [26, 30], [26, 32], [26, 37], [26, 38], [26, 39], [26, 40], [26, 44], [26, 47], [26, 54], [26, 63], [26, 65], [26, 68], [26, 74], [26, 83], [26, 84], [26, 87], [26, 94], [27, 30], [27, 31], [27, 39], [27, 40], [27, 45], [27, 46], [27, 48], [27, 49], [27, 50], [27, 52], [27, 57], [27, 60], [27, 61], [27, 62], [27, 67], [27, 70], [27, 71], [27, 73], [27, 74], [27, 83], [27, 86], [27, 88], [27, 89], [27, 93], [27, 96], [28, 30], [28, 31], [28, 32], [28, 40], [28, 41], [28, 45], [28, 49], [28, 50], [28, 52], [28, 53], [28, 60], [28, 65], [28, 72], [28, 74], [28, 76], [28, 78], [28, 79], [28, 80], [28, 81], [28, 83], [28, 87], [28, 97], [28, 98], [28, 99], [29, 30], [29, 33], [29, 42], [29, 44], [29, 54], [29, 56], [29, 58], [29, 67], [29, 70], [29, 73], [29, 74], [29, 75], [29, 79], [29, 81], [29, 82], [29, 86], [29, 92], [29, 94], [30, 31], [30, 35], [30, 39], [30, 40], [30, 41], [30, 43], [30, 44], [30, 47], [30, 48], [30, 54], [30, 55], [30, 58], [30, 65], [30, 66], [30, 69], [30, 77], [30, 78], [30, 89], [30, 90], [30, 91], [30, 97], [30, 99], [31, 34], [31, 38], [31, 44], [31, 48], [31, 50], [31, 57], [31, 64], [31, 65], [31, 66], [31, 68], [31, 69], [31, 74], [31, 75], [31, 77], [31, 79], [31, 85], [31, 87], [31, 88], [32, 34], [32, 43], [32, 46], [32, 51], [32, 52], [32, 55], [32, 58], [32, 62], [32, 69], [32, 73], [32, 79], [32, 82], [32, 96], [33, 40], [33, 42], [33, 46], [33, 48], [33, 50], [33, 55], [33, 66], [33, 71], [33, 82], [33, 84], [33, 87], [33, 98], [34, 36], [34, 39], [34, 40], [34, 41], [34, 42], [34, 49], [34, 51], [34, 55], [34, 59], [34, 65], [34, 72], [34, 78], [34, 79], [34, 83], [34, 85], [34, 87], [34, 88], [34, 95], [34, 97], [34, 98], [34, 99], [35, 37], [35, 42], [35, 44], [35, 45], [35, 46], [35, 57], [35, 67], [35, 72], [35, 76], [35, 77], [35, 80], [35, 84], [35, 99], [36, 37], [36, 43], [36, 48], [36, 54], [36, 58], [36, 65], [36, 66], [36, 70], [36, 71], [36, 72], [36, 73], [36, 76], [36, 78], [36, 79], [36, 80], [36, 95], [37, 41], [37, 43], [37, 44], [37, 45], [37, 48], [37, 49], [37, 56], [37, 61], [37, 64], [37, 68], [37, 69], [37, 73], [37, 76], [37, 77], [37, 78], [37, 79], [37, 81], [37, 83], [37, 84], [37, 85], [37, 89], [37, 91], [37, 94], [37, 96], [37, 98], [38, 46], [38, 52], [38, 57], [38, 58], [38, 62], [38, 63], [38, 65], [38, 66], [38, 68], [38, 78], [38, 79], [38, 80], [38, 84], [38, 85], [38, 86], [38, 87], [38, 90], [38, 96], [39, 40], [39, 41], [39, 49], [39, 53], [39, 57], [39, 58], [39, 59], [39, 60], [39, 63], [39, 65], [39, 70], [39, 76], [39, 80], [39, 81], [39, 85], [39, 86], [39, 89], [39, 90], [39, 93], [39, 94], [39, 96], [40, 44], [40, 49], [40, 64], [40, 65], [40, 69], [40, 71], [40, 72], [40, 74], [40, 75], [40, 79], [40, 81], [40, 82], [40, 94], [40, 97], [40, 99], [41, 45], [41, 54], [41, 57], [41, 58], [41, 62], [41, 63], [41, 64], [41, 66], [41, 68], [41, 71], [41, 72], [41, 73], [41, 80], [41, 85], [41, 86], [41, 96], [41, 99], [42, 51], [42, 55], [42, 61], [42, 66], [42, 68], [42, 69], [42, 70], [42, 72], [42, 79], [42, 87], [42, 89], [42, 90], [42, 92], [42, 96], [42, 97], [43, 48], [43, 49], [43, 50], [43, 51], [43, 54], [43, 76], [43, 77], [43, 78], [43, 79], [43, 80], [43, 82], [43, 85], [43, 86], [43, 91], [43, 95], [43, 96], [43, 98], [43, 99], [44, 45], [44, 50], [44, 53], [44, 56], [44, 58], [44, 59], [44, 60], [44, 63], [44, 64], [44, 67], [44, 69], [44, 71], [44, 78], [44, 79], [44, 82], [44, 84], [44, 85], [45, 47], [45, 50], [45, 59], [45, 62], [45, 63], [45, 65], [45, 66], [45, 69], [45, 70], [45, 72], [45, 79], [45, 80], [45, 83], [45, 84], [45, 92], [46, 47], [46, 49], [46, 52], [46, 54], [46, 59], [46, 69], [46, 76], [46, 78], [46, 86], [46, 88], [46, 89], [46, 92], [46, 93], [46, 96], [47, 53], [47, 64], [47, 65], [47, 67], [47, 72], [47, 76], [47, 77], [47, 78], [47, 80], [47, 85], [47, 86], [47, 98], [47, 99], [48, 56], [48, 58], [48, 62], [48, 65], [48, 66], [48, 71], [48, 72], [48, 75], [48, 84], [48, 89], [48, 90], [48, 93], [48, 95], [48, 96], [49, 53], [49, 54], [49, 58], [49, 66], [49, 70], [49, 71], [49, 72], [49, 76], [49, 82], [49, 84], [49, 96], [49, 98], [50, 52], [50, 54], [50, 55], [50, 56], [50, 57], [50, 58], [50, 62], [50, 66], [50, 74], [50, 78], [50, 79], [50, 82], [50, 89], [50, 94], [50, 99], [51, 52], [51, 58], [51, 65], [51, 66], [51, 74], [51, 80], [51, 81], [51, 82], [51, 83], [51, 94], [52, 55], [52, 57], [52, 66], [52, 68], [52, 75], [52, 76], [52, 78], [52, 81], [52, 82], [52, 83], [52, 86], [52, 98], [53, 57], [53, 58], [53, 60], [53, 64], [53, 66], [53, 71], [53, 73], [53, 83], [53, 91], [53, 94], [53, 96], [54, 61], [54, 62], [54, 65], [54, 66], [54, 71], [54, 72], [54, 75], [54, 76], [54, 77], [54, 79], [54, 87], [54, 93], [54, 94], [54, 96], [55, 58], [55, 60], [55, 63], [55, 68], [55, 73], [55, 74], [55, 76], [55, 81], [55, 91], [55, 97], [56, 63], [56, 64], [56, 67], [56, 78], [56, 79], [56, 98], [57, 60], [57, 62], [57, 64], [57, 67], [57, 74], [57, 78], [57, 81], [57, 82], [57, 84], [57, 87], [57, 92], [57, 94], [57, 97], [57, 98], [58, 60], [58, 62], [58, 63], [58, 67], [58, 70], [58, 71], [58, 73], [58, 79], [58, 82], [58, 84], [58, 86], [58, 89], [58, 96], [59, 66], [59, 68], [59, 72], [59, 84], [59, 99], [60, 68], [60, 70], [60, 80], [60, 86], [60, 99], [61, 62], [61, 63], [61, 64], [61, 65], [61, 69], [61, 70], [61, 71], [61, 79], [61, 85], [61, 90], [61, 95], [61, 96], [62, 68], [62, 69], [62, 71], [62, 81], [62, 83], [62, 94], [62, 97], [62, 99], [63, 68], [63, 74], [63, 75], [63, 76], [63, 77], [63, 86], [63, 88], [63, 99], [64, 66], [64, 68], [64, 70], [64, 79], [64, 80], [64, 88], [64, 93], [64, 95], [64, 98], [64, 99], [65, 66], [65, 70], [65, 77], [65, 80], [65, 86], [65, 87], [65, 91], [65, 95], [65, 97], [65, 98], [66, 68], [66, 71], [66, 73], [66, 75], [66, 80], [66, 87], [66, 89], [66, 92], [66, 93], [66, 94], [66, 97], [66, 99], [67, 69], [67, 72], [67, 77], [67, 78], [67, 82], [67, 90], [67, 91], [67, 93], [67, 95], [67, 97], [68, 70], [68, 71], [68, 72], [68, 73], [68, 74], [68, 76], [68, 79], [68, 82], [68, 84], [68, 85], [68, 87], [68, 92], [68, 94], [68, 98], [69, 77], [69, 82], [69, 83], [69, 84], [69, 86], [69, 88], [69, 90], [69, 91], [69, 94], [69, 95], [69, 96], [69, 98], [70, 73], [70, 74], [70, 82], [70, 85], [70, 86], [70, 91], [70, 93], [70, 95], [70, 98], [71, 74], [71, 75], [71, 77], [71, 82], [71, 85], [71, 86], [71, 89], [71, 94], [71, 98], [72, 77], [72, 81], [72, 82], [72, 84], [72, 85], [72, 86], [72, 92], [72, 97], [73, 74], [73, 78], [73, 79], [73, 82], [73, 86], [73, 87], [73, 88], [73, 91], [73, 96], [74, 82], [74, 84], [74, 86], [74, 90], [74, 95], [75, 76], [75, 86], [75, 90], [76, 78], [76, 80], [76, 82], [76, 83], [76, 86], [76, 87], [76, 93], [76, 95], [77, 79], [77, 83], [77, 87], [78, 80], [78, 82], [78, 86], [78, 87], [78, 89], [78, 90], [78, 91], [78, 94], [78, 97], [78, 98], [78, 99], [79, 80], [79, 83], [79, 87], [79, 88], [79, 97], [81, 82], [81, 86], [82, 83], [82, 85], [82, 89], [82, 90], [82, 91], [82, 94], [82, 96], [84, 87], [84, 93], [84, 95], [85, 88], [85, 95], [85, 96], [85, 97], [85, 98], [86, 87], [86, 92], [86, 93], [86, 96], [86, 98], [87, 91], [88, 98], [89, 99], [90, 91], [91, 95], [91, 98], [92, 98], [93, 95], [94, 96], [96, 97], [97, 98], [97, 99], [98, 99]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l6-s6/solution/solve.sh b/tasks/construct-nppc-independent-set-l6-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..3bd982a38822ce10c8dbdbfa9ae671917d388af9 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l6-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"independent_set": [0, 3, 12, 13, 15, 22, 23, 32, 33, 35, 36, 38, 41, 47, 49, 56, 59, 60, 61, 74, 75, 81, 83, 88, 89, 91, 92, 93, 94, 97]} +RLMATH_EOF diff --git a/tasks/construct-nppc-independent-set-l6-s6/tests/check.py b/tasks/construct-nppc-independent-set-l6-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..92279a931488c7f39c08a3b11162b3f54a9c662a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l6-s6/tests/check.py @@ -0,0 +1,19 @@ +"""Independent set of size >= k. Accepts any valid independent set.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + s = int_list(ans.get("independent_set"), None, 0, n - 1, "independent_set") + # upstream NPPC verifier checks len(list) >= size but only tests pairs u < v, so [v]*k passed + if len(set(s)) != len(s): + raise Invalid("independent_set contains duplicates") + if len(s) < k: + raise Invalid(f"independent_set has {len(s)} < {k} vertices") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(s), 2): + if (u, v) in es: + raise Invalid(f"edge between {u} and {v}") + return None, {"size": len(s)} diff --git a/tasks/construct-nppc-independent-set-l6-s6/tests/instance.json b/tasks/construct-nppc-independent-set-l6-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bde3921b96be4fdf9cca54e1dc43086a7a1b8ced --- /dev/null +++ b/tasks/construct-nppc-independent-set-l6-s6/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 100, "k": 30, "edges": [[0, 1], [0, 9], [0, 11], [0, 14], [0, 16], [0, 21], [0, 24], [0, 28], [0, 30], [0, 39], [0, 42], [0, 44], [0, 45], [0, 46], [0, 51], [0, 54], [0, 58], [0, 65], [0, 69], [0, 70], [0, 71], [0, 72], [0, 73], [0, 80], [0, 82], [0, 84], [0, 87], [0, 96], [0, 98], [1, 5], [1, 9], [1, 10], [1, 11], [1, 12], [1, 18], [1, 21], [1, 27], [1, 28], [1, 33], [1, 38], [1, 41], [1, 46], [1, 51], [1, 55], [1, 59], [1, 60], [1, 63], [1, 66], [1, 70], [1, 72], [1, 73], [1, 77], [1, 78], [1, 79], [1, 81], [1, 85], [1, 89], [1, 91], [1, 95], [2, 5], [2, 9], [2, 13], [2, 15], [2, 17], [2, 20], [2, 33], [2, 37], [2, 38], [2, 39], [2, 42], [2, 46], [2, 50], [2, 52], [2, 55], [2, 59], [2, 60], [2, 66], [2, 67], [2, 78], [2, 82], [2, 83], [2, 87], [2, 91], [2, 97], [2, 99], [3, 4], [3, 6], [3, 10], [3, 14], [3, 17], [3, 19], [3, 20], [3, 21], [3, 28], [3, 30], [3, 40], [3, 44], [3, 45], [3, 46], [3, 52], [3, 53], [3, 54], [3, 55], [3, 57], [3, 62], [3, 66], [3, 67], [3, 73], [3, 76], [3, 77], [3, 87], [3, 99], [4, 5], [4, 7], [4, 9], [4, 12], [4, 13], [4, 15], [4, 17], [4, 26], [4, 27], [4, 28], [4, 33], [4, 36], [4, 42], [4, 48], [4, 50], [4, 52], [4, 54], [4, 57], [4, 58], [4, 59], [4, 62], [4, 67], [4, 69], [4, 75], [4, 77], [4, 81], [4, 89], [4, 92], [4, 93], [4, 97], [5, 6], [5, 7], [5, 9], [5, 11], [5, 12], [5, 14], [5, 19], [5, 21], [5, 27], [5, 33], [5, 37], [5, 50], [5, 52], [5, 53], [5, 54], [5, 55], [5, 56], [5, 59], [5, 64], [5, 66], [5, 69], [5, 71], [5, 75], [5, 78], [5, 81], [5, 82], [5, 84], [5, 89], [5, 90], [5, 92], [5, 98], [5, 99], [6, 8], [6, 10], [6, 12], [6, 13], [6, 16], [6, 22], [6, 23], [6, 24], [6, 27], [6, 28], [6, 32], [6, 35], [6, 39], [6, 40], [6, 41], [6, 47], [6, 50], [6, 55], [6, 67], [6, 68], [6, 69], [6, 73], [6, 76], [6, 77], [6, 78], [6, 85], [6, 88], [6, 96], [6, 98], [6, 99], [7, 9], [7, 15], [7, 21], [7, 22], [7, 25], [7, 28], [7, 29], [7, 31], [7, 36], [7, 40], [7, 42], [7, 46], [7, 48], [7, 50], [7, 53], [7, 54], [7, 56], [7, 57], [7, 58], [7, 59], [7, 60], [7, 63], [7, 65], [7, 66], [7, 68], [7, 69], [7, 70], [7, 76], [7, 77], [7, 81], [7, 84], [7, 87], [7, 88], [7, 89], [7, 91], [8, 10], [8, 15], [8, 22], [8, 23], [8, 32], [8, 35], [8, 37], [8, 39], [8, 41], [8, 43], [8, 50], [8, 51], [8, 54], [8, 63], [8, 67], [8, 74], [8, 78], [8, 81], [8, 86], [8, 89], [8, 90], [8, 91], [8, 94], [8, 99], [9, 12], [9, 13], [9, 16], [9, 19], [9, 27], [9, 29], [9, 31], [9, 34], [9, 38], [9, 39], [9, 42], [9, 53], [9, 56], [9, 57], [9, 81], [9, 88], [9, 90], [9, 91], [9, 93], [9, 94], [10, 18], [10, 19], [10, 25], [10, 29], [10, 42], [10, 45], [10, 50], [10, 57], [10, 60], [10, 62], [10, 76], [10, 88], [10, 91], [10, 92], [10, 94], [10, 95], [10, 96], [11, 12], [11, 14], [11, 15], [11, 22], [11, 28], [11, 29], [11, 32], [11, 34], [11, 35], [11, 40], [11, 42], [11, 43], [11, 46], [11, 50], [11, 52], [11, 54], [11, 58], [11, 68], [11, 70], [11, 71], [11, 72], [11, 73], [11, 74], [11, 83], [11, 89], [11, 93], [11, 95], [11, 98], [12, 16], [12, 17], [12, 20], [12, 21], [12, 24], [12, 34], [12, 37], [12, 40], [12, 50], [12, 54], [12, 58], [12, 66], [12, 67], [12, 79], [12, 80], [12, 85], [12, 90], [12, 98], [13, 21], [13, 27], [13, 39], [13, 44], [13, 45], [13, 53], [13, 58], [13, 65], [13, 67], [13, 68], [13, 76], [13, 79], [13, 80], [13, 90], [14, 23], [14, 24], [14, 30], [14, 34], [14, 36], [14, 38], [14, 42], [14, 46], [14, 47], [14, 51], [14, 52], [14, 53], [14, 54], [14, 55], [14, 57], [14, 58], [14, 60], [14, 62], [14, 64], [14, 66], [14, 68], [14, 70], [14, 72], [14, 74], [14, 80], [14, 83], [14, 86], [14, 90], [14, 91], [14, 92], [14, 96], [15, 27], [15, 29], [15, 42], [15, 43], [15, 46], [15, 54], [15, 57], [15, 58], [15, 62], [15, 64], [15, 67], [15, 69], [15, 70], [15, 80], [15, 82], [15, 84], [15, 90], [15, 96], [16, 17], [16, 19], [16, 23], [16, 26], [16, 27], [16, 46], [16, 55], [16, 58], [16, 59], [16, 61], [16, 69], [16, 75], [16, 77], [16, 81], [16, 84], [16, 90], [16, 92], [16, 97], [16, 99], [17, 20], [17, 21], [17, 25], [17, 32], [17, 33], [17, 37], [17, 43], [17, 52], [17, 54], [17, 62], [17, 64], [17, 65], [17, 69], [17, 70], [17, 71], [17, 77], [17, 80], [17, 82], [17, 83], [17, 88], [17, 93], [18, 23], [18, 24], [18, 25], [18, 27], [18, 29], [18, 31], [18, 34], [18, 37], [18, 43], [18, 49], [18, 50], [18, 53], [18, 57], [18, 64], [18, 69], [18, 70], [18, 71], [18, 72], [18, 74], [18, 80], [18, 86], [18, 90], [18, 92], [18, 93], [19, 20], [19, 21], [19, 22], [19, 23], [19, 29], [19, 31], [19, 33], [19, 34], [19, 36], [19, 38], [19, 45], [19, 63], [19, 64], [19, 65], [19, 66], [19, 67], [19, 73], [19, 75], [19, 77], [19, 78], [19, 80], [19, 81], [19, 87], [19, 89], [19, 92], [20, 21], [20, 22], [20, 23], [20, 25], [20, 28], [20, 35], [20, 39], [20, 40], [20, 47], [20, 53], [20, 55], [20, 59], [20, 60], [20, 67], [20, 70], [20, 73], [20, 75], [20, 80], [20, 86], [20, 92], [20, 94], [21, 25], [21, 30], [21, 33], [21, 35], [21, 39], [21, 41], [21, 43], [21, 45], [21, 46], [21, 51], [21, 53], [21, 56], [21, 59], [21, 62], [21, 64], [21, 65], [21, 69], [21, 73], [21, 74], [21, 78], [21, 79], [21, 80], [21, 86], [21, 90], [21, 91], [21, 93], [22, 29], [22, 40], [22, 43], [22, 45], [22, 48], [22, 50], [22, 51], [22, 55], [22, 62], [22, 69], [22, 70], [22, 71], [22, 76], [22, 77], [22, 82], [22, 84], [22, 86], [23, 25], [23, 28], [23, 29], [23, 31], [23, 37], [23, 39], [23, 40], [23, 43], [23, 66], [23, 67], [23, 68], [23, 71], [23, 72], [23, 82], [23, 84], [23, 87], [23, 96], [24, 26], [24, 27], [24, 28], [24, 30], [24, 31], [24, 32], [24, 36], [24, 40], [24, 49], [24, 51], [24, 54], [24, 55], [24, 56], [24, 58], [24, 60], [24, 61], [24, 64], [24, 69], [24, 70], [24, 71], [24, 74], [24, 79], [24, 80], [24, 81], [24, 83], [24, 90], [24, 93], [24, 94], [24, 98], [25, 27], [25, 29], [25, 30], [25, 31], [25, 32], [25, 33], [25, 37], [25, 38], [25, 40], [25, 50], [25, 61], [25, 63], [25, 72], [25, 75], [25, 76], [25, 77], [25, 82], [25, 87], [25, 91], [25, 94], [25, 95], [26, 30], [26, 32], [26, 37], [26, 38], [26, 39], [26, 40], [26, 44], [26, 47], [26, 54], [26, 63], [26, 65], [26, 68], [26, 74], [26, 83], [26, 84], [26, 87], [26, 94], [27, 30], [27, 31], [27, 39], [27, 40], [27, 45], [27, 46], [27, 48], [27, 49], [27, 50], [27, 52], [27, 57], [27, 60], [27, 61], [27, 62], [27, 67], [27, 70], [27, 71], [27, 73], [27, 74], [27, 83], [27, 86], [27, 88], [27, 89], [27, 93], [27, 96], [28, 30], [28, 31], [28, 32], [28, 40], [28, 41], [28, 45], [28, 49], [28, 50], [28, 52], [28, 53], [28, 60], [28, 65], [28, 72], [28, 74], [28, 76], [28, 78], [28, 79], [28, 80], [28, 81], [28, 83], [28, 87], [28, 97], [28, 98], [28, 99], [29, 30], [29, 33], [29, 42], [29, 44], [29, 54], [29, 56], [29, 58], [29, 67], [29, 70], [29, 73], [29, 74], [29, 75], [29, 79], [29, 81], [29, 82], [29, 86], [29, 92], [29, 94], [30, 31], [30, 35], [30, 39], [30, 40], [30, 41], [30, 43], [30, 44], [30, 47], [30, 48], [30, 54], [30, 55], [30, 58], [30, 65], [30, 66], [30, 69], [30, 77], [30, 78], [30, 89], [30, 90], [30, 91], [30, 97], [30, 99], [31, 34], [31, 38], [31, 44], [31, 48], [31, 50], [31, 57], [31, 64], [31, 65], [31, 66], [31, 68], [31, 69], [31, 74], [31, 75], [31, 77], [31, 79], [31, 85], [31, 87], [31, 88], [32, 34], [32, 43], [32, 46], [32, 51], [32, 52], [32, 55], [32, 58], [32, 62], [32, 69], [32, 73], [32, 79], [32, 82], [32, 96], [33, 40], [33, 42], [33, 46], [33, 48], [33, 50], [33, 55], [33, 66], [33, 71], [33, 82], [33, 84], [33, 87], [33, 98], [34, 36], [34, 39], [34, 40], [34, 41], [34, 42], [34, 49], [34, 51], [34, 55], [34, 59], [34, 65], [34, 72], [34, 78], [34, 79], [34, 83], [34, 85], [34, 87], [34, 88], [34, 95], [34, 97], [34, 98], [34, 99], [35, 37], [35, 42], [35, 44], [35, 45], [35, 46], [35, 57], [35, 67], [35, 72], [35, 76], [35, 77], [35, 80], [35, 84], [35, 99], [36, 37], [36, 43], [36, 48], [36, 54], [36, 58], [36, 65], [36, 66], [36, 70], [36, 71], [36, 72], [36, 73], [36, 76], [36, 78], [36, 79], [36, 80], [36, 95], [37, 41], [37, 43], [37, 44], [37, 45], [37, 48], [37, 49], [37, 56], [37, 61], [37, 64], [37, 68], [37, 69], [37, 73], [37, 76], [37, 77], [37, 78], [37, 79], [37, 81], [37, 83], [37, 84], [37, 85], [37, 89], [37, 91], [37, 94], [37, 96], [37, 98], [38, 46], [38, 52], [38, 57], [38, 58], [38, 62], [38, 63], [38, 65], [38, 66], [38, 68], [38, 78], [38, 79], [38, 80], [38, 84], [38, 85], [38, 86], [38, 87], [38, 90], [38, 96], [39, 40], [39, 41], [39, 49], [39, 53], [39, 57], [39, 58], [39, 59], [39, 60], [39, 63], [39, 65], [39, 70], [39, 76], [39, 80], [39, 81], [39, 85], [39, 86], [39, 89], [39, 90], [39, 93], [39, 94], [39, 96], [40, 44], [40, 49], [40, 64], [40, 65], [40, 69], [40, 71], [40, 72], [40, 74], [40, 75], [40, 79], [40, 81], [40, 82], [40, 94], [40, 97], [40, 99], [41, 45], [41, 54], [41, 57], [41, 58], [41, 62], [41, 63], [41, 64], [41, 66], [41, 68], [41, 71], [41, 72], [41, 73], [41, 80], [41, 85], [41, 86], [41, 96], [41, 99], [42, 51], [42, 55], [42, 61], [42, 66], [42, 68], [42, 69], [42, 70], [42, 72], [42, 79], [42, 87], [42, 89], [42, 90], [42, 92], [42, 96], [42, 97], [43, 48], [43, 49], [43, 50], [43, 51], [43, 54], [43, 76], [43, 77], [43, 78], [43, 79], [43, 80], [43, 82], [43, 85], [43, 86], [43, 91], [43, 95], [43, 96], [43, 98], [43, 99], [44, 45], [44, 50], [44, 53], [44, 56], [44, 58], [44, 59], [44, 60], [44, 63], [44, 64], [44, 67], [44, 69], [44, 71], [44, 78], [44, 79], [44, 82], [44, 84], [44, 85], [45, 47], [45, 50], [45, 59], [45, 62], [45, 63], [45, 65], [45, 66], [45, 69], [45, 70], [45, 72], [45, 79], [45, 80], [45, 83], [45, 84], [45, 92], [46, 47], [46, 49], [46, 52], [46, 54], [46, 59], [46, 69], [46, 76], [46, 78], [46, 86], [46, 88], [46, 89], [46, 92], [46, 93], [46, 96], [47, 53], [47, 64], [47, 65], [47, 67], [47, 72], [47, 76], [47, 77], [47, 78], [47, 80], [47, 85], [47, 86], [47, 98], [47, 99], [48, 56], [48, 58], [48, 62], [48, 65], [48, 66], [48, 71], [48, 72], [48, 75], [48, 84], [48, 89], [48, 90], [48, 93], [48, 95], [48, 96], [49, 53], [49, 54], [49, 58], [49, 66], [49, 70], [49, 71], [49, 72], [49, 76], [49, 82], [49, 84], [49, 96], [49, 98], [50, 52], [50, 54], [50, 55], [50, 56], [50, 57], [50, 58], [50, 62], [50, 66], [50, 74], [50, 78], [50, 79], [50, 82], [50, 89], [50, 94], [50, 99], [51, 52], [51, 58], [51, 65], [51, 66], [51, 74], [51, 80], [51, 81], [51, 82], [51, 83], [51, 94], [52, 55], [52, 57], [52, 66], [52, 68], [52, 75], [52, 76], [52, 78], [52, 81], [52, 82], [52, 83], [52, 86], [52, 98], [53, 57], [53, 58], [53, 60], [53, 64], [53, 66], [53, 71], [53, 73], [53, 83], [53, 91], [53, 94], [53, 96], [54, 61], [54, 62], [54, 65], [54, 66], [54, 71], [54, 72], [54, 75], [54, 76], [54, 77], [54, 79], [54, 87], [54, 93], [54, 94], [54, 96], [55, 58], [55, 60], [55, 63], [55, 68], [55, 73], [55, 74], [55, 76], [55, 81], [55, 91], [55, 97], [56, 63], [56, 64], [56, 67], [56, 78], [56, 79], [56, 98], [57, 60], [57, 62], [57, 64], [57, 67], [57, 74], [57, 78], [57, 81], [57, 82], [57, 84], [57, 87], [57, 92], [57, 94], [57, 97], [57, 98], [58, 60], [58, 62], [58, 63], [58, 67], [58, 70], [58, 71], [58, 73], [58, 79], [58, 82], [58, 84], [58, 86], [58, 89], [58, 96], [59, 66], [59, 68], [59, 72], [59, 84], [59, 99], [60, 68], [60, 70], [60, 80], [60, 86], [60, 99], [61, 62], [61, 63], [61, 64], [61, 65], [61, 69], [61, 70], [61, 71], [61, 79], [61, 85], [61, 90], [61, 95], [61, 96], [62, 68], [62, 69], [62, 71], [62, 81], [62, 83], [62, 94], [62, 97], [62, 99], [63, 68], [63, 74], [63, 75], [63, 76], [63, 77], [63, 86], [63, 88], [63, 99], [64, 66], [64, 68], [64, 70], [64, 79], [64, 80], [64, 88], [64, 93], [64, 95], [64, 98], [64, 99], [65, 66], [65, 70], [65, 77], [65, 80], [65, 86], [65, 87], [65, 91], [65, 95], [65, 97], [65, 98], [66, 68], [66, 71], [66, 73], [66, 75], [66, 80], [66, 87], [66, 89], [66, 92], [66, 93], [66, 94], [66, 97], [66, 99], [67, 69], [67, 72], [67, 77], [67, 78], [67, 82], [67, 90], [67, 91], [67, 93], [67, 95], [67, 97], [68, 70], [68, 71], [68, 72], [68, 73], [68, 74], [68, 76], [68, 79], [68, 82], [68, 84], [68, 85], [68, 87], [68, 92], [68, 94], [68, 98], [69, 77], [69, 82], [69, 83], [69, 84], [69, 86], [69, 88], [69, 90], [69, 91], [69, 94], [69, 95], [69, 96], [69, 98], [70, 73], [70, 74], [70, 82], [70, 85], [70, 86], [70, 91], [70, 93], [70, 95], [70, 98], [71, 74], [71, 75], [71, 77], [71, 82], [71, 85], [71, 86], [71, 89], [71, 94], [71, 98], [72, 77], [72, 81], [72, 82], [72, 84], [72, 85], [72, 86], [72, 92], [72, 97], [73, 74], [73, 78], [73, 79], [73, 82], [73, 86], [73, 87], [73, 88], [73, 91], [73, 96], [74, 82], [74, 84], [74, 86], [74, 90], [74, 95], [75, 76], [75, 86], [75, 90], [76, 78], [76, 80], [76, 82], [76, 83], [76, 86], [76, 87], [76, 93], [76, 95], [77, 79], [77, 83], [77, 87], [78, 80], [78, 82], [78, 86], [78, 87], [78, 89], [78, 90], [78, 91], [78, 94], [78, 97], [78, 98], [78, 99], [79, 80], [79, 83], [79, 87], [79, 88], [79, 97], [81, 82], [81, 86], [82, 83], [82, 85], [82, 89], [82, 90], [82, 91], [82, 94], [82, 96], [84, 87], [84, 93], [84, 95], [85, 88], [85, 95], [85, 96], [85, 97], [85, 98], [86, 87], [86, 92], [86, 93], [86, 96], [86, 98], [87, 91], [88, 98], [89, 99], [90, 91], [91, 95], [91, 98], [92, 98], [93, 95], [94, 96], [96, 97], [97, 98], [97, 99], [98, 99]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l6-s6/tests/run.py b/tasks/construct-nppc-independent-set-l6-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l6-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-independent-set-l6-s6/tests/test.sh b/tasks/construct-nppc-independent-set-l6-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l6-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-independent-set-l6-s8/environment/Dockerfile b/tasks/construct-nppc-independent-set-l6-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l6-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-independent-set-l6-s8/environment/instance.json b/tasks/construct-nppc-independent-set-l6-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3b1aacc4f8e76d01ab9af8f4feee1cca1e7e0aeb --- /dev/null +++ b/tasks/construct-nppc-independent-set-l6-s8/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 100, "k": 30, "edges": [[0, 4], [0, 13], [0, 15], [0, 21], [0, 26], [0, 28], [0, 43], [0, 49], [0, 54], [0, 62], [0, 73], [0, 74], [0, 75], [0, 90], [0, 91], [0, 96], [0, 97], [0, 99], [1, 10], [1, 11], [1, 21], [1, 32], [1, 37], [1, 39], [1, 42], [1, 45], [1, 52], [1, 53], [1, 61], [1, 72], [1, 74], [1, 75], [1, 77], [1, 79], [1, 82], [1, 87], [1, 91], [1, 93], [1, 94], [2, 4], [2, 8], [2, 9], [2, 13], [2, 14], [2, 15], [2, 17], [2, 26], [2, 35], [2, 37], [2, 53], [2, 55], [2, 70], [2, 71], [2, 74], [2, 87], [2, 89], [2, 90], [2, 91], [2, 93], [3, 12], [3, 18], [3, 20], [3, 25], [3, 28], [3, 29], [3, 30], [3, 34], [3, 36], [3, 42], [3, 44], [3, 45], [3, 49], [3, 50], [3, 51], [3, 60], [3, 64], [3, 67], [3, 71], [3, 80], [3, 81], [3, 85], [3, 88], [3, 93], [3, 94], [3, 95], [3, 96], [3, 97], [4, 5], [4, 6], [4, 11], [4, 12], [4, 19], [4, 21], [4, 24], [4, 26], [4, 28], [4, 29], [4, 34], [4, 36], [4, 38], [4, 42], [4, 43], [4, 47], [4, 49], [4, 56], [4, 59], [4, 64], [4, 66], [4, 69], [4, 74], [4, 78], [4, 80], [4, 81], [4, 82], [4, 86], [4, 91], [4, 98], [4, 99], [5, 6], [5, 8], [5, 13], [5, 21], [5, 22], [5, 28], [5, 33], [5, 37], [5, 42], [5, 46], [5, 49], [5, 51], [5, 52], [5, 55], [5, 57], [5, 58], [5, 59], [5, 60], [5, 62], [5, 65], [5, 66], [5, 70], [5, 71], [5, 75], [5, 77], [5, 78], [5, 87], [5, 88], [5, 98], [6, 10], [6, 17], [6, 26], [6, 27], [6, 32], [6, 37], [6, 41], [6, 49], [6, 52], [6, 62], [6, 72], [6, 77], [6, 81], [6, 82], [6, 86], [6, 90], [6, 96], [6, 97], [7, 11], [7, 12], [7, 26], [7, 28], [7, 34], [7, 43], [7, 51], [7, 57], [7, 61], [7, 63], [7, 71], [7, 72], [7, 75], [7, 77], [7, 85], [7, 87], [7, 90], [7, 91], [7, 93], [7, 96], [8, 10], [8, 12], [8, 14], [8, 19], [8, 20], [8, 22], [8, 24], [8, 31], [8, 33], [8, 35], [8, 36], [8, 37], [8, 40], [8, 43], [8, 46], [8, 48], [8, 50], [8, 51], [8, 54], [8, 57], [8, 62], [8, 65], [8, 72], [8, 73], [8, 75], [8, 76], [8, 77], [8, 78], [8, 84], [8, 85], [8, 90], [8, 92], [9, 14], [9, 15], [9, 23], [9, 24], [9, 25], [9, 29], [9, 31], [9, 32], [9, 34], [9, 35], [9, 38], [9, 45], [9, 50], [9, 54], [9, 55], [9, 61], [9, 62], [9, 63], [9, 68], [9, 74], [9, 83], [9, 84], [9, 85], [9, 87], [9, 90], [10, 16], [10, 20], [10, 23], [10, 31], [10, 33], [10, 35], [10, 36], [10, 40], [10, 43], [10, 52], [10, 54], [10, 56], [10, 57], [10, 58], [10, 65], [10, 67], [10, 68], [10, 70], [10, 72], [10, 73], [10, 79], [10, 81], [10, 83], [10, 85], [10, 86], [10, 90], [10, 91], [10, 92], [10, 93], [10, 94], [10, 99], [11, 15], [11, 17], [11, 18], [11, 19], [11, 22], [11, 25], [11, 30], [11, 31], [11, 35], [11, 37], [11, 38], [11, 39], [11, 41], [11, 44], [11, 45], [11, 48], [11, 49], [11, 50], [11, 51], [11, 52], [11, 53], [11, 58], [11, 61], [11, 66], [11, 73], [11, 76], [11, 78], [11, 79], [11, 87], [11, 88], [11, 89], [11, 95], [11, 96], [11, 98], [12, 14], [12, 16], [12, 18], [12, 21], [12, 26], [12, 29], [12, 33], [12, 35], [12, 36], [12, 37], [12, 45], [12, 53], [12, 57], [12, 58], [12, 60], [12, 65], [12, 70], [12, 80], [12, 82], [12, 84], [12, 86], [12, 91], [12, 93], [12, 97], [12, 99], [13, 21], [13, 27], [13, 28], [13, 30], [13, 31], [13, 38], [13, 40], [13, 42], [13, 53], [13, 54], [13, 55], [13, 62], [13, 63], [13, 71], [13, 72], [13, 80], [13, 90], [13, 94], [14, 16], [14, 17], [14, 19], [14, 22], [14, 28], [14, 33], [14, 34], [14, 38], [14, 52], [14, 53], [14, 56], [14, 59], [14, 60], [14, 62], [14, 64], [14, 65], [14, 66], [14, 78], [14, 79], [14, 80], [14, 82], [14, 83], [14, 85], [14, 86], [14, 90], [14, 96], [15, 21], [15, 23], [15, 31], [15, 45], [15, 48], [15, 49], [15, 54], [15, 55], [15, 57], [15, 58], [15, 60], [15, 64], [15, 66], [15, 68], [15, 70], [15, 72], [15, 73], [15, 76], [15, 83], [15, 84], [15, 86], [15, 91], [15, 93], [15, 95], [15, 98], [16, 21], [16, 24], [16, 26], [16, 27], [16, 39], [16, 47], [16, 54], [16, 61], [16, 71], [16, 73], [16, 75], [16, 77], [16, 90], [16, 94], [17, 23], [17, 27], [17, 34], [17, 39], [17, 40], [17, 41], [17, 42], [17, 43], [17, 44], [17, 45], [17, 51], [17, 55], [17, 60], [17, 62], [17, 64], [17, 65], [17, 67], [17, 69], [17, 74], [17, 76], [17, 77], [17, 78], [17, 86], [17, 88], [17, 90], [17, 92], [17, 96], [17, 98], [17, 99], [18, 21], [18, 24], [18, 25], [18, 29], [18, 33], [18, 36], [18, 41], [18, 43], [18, 44], [18, 48], [18, 53], [18, 54], [18, 55], [18, 61], [18, 62], [18, 63], [18, 75], [18, 84], [18, 91], [18, 93], [18, 94], [18, 96], [18, 97], [19, 21], [19, 28], [19, 32], [19, 37], [19, 38], [19, 43], [19, 45], [19, 46], [19, 47], [19, 49], [19, 52], [19, 58], [19, 61], [19, 63], [19, 65], [19, 75], [19, 82], [19, 83], [19, 89], [19, 94], [19, 98], [19, 99], [20, 24], [20, 26], [20, 28], [20, 30], [20, 39], [20, 40], [20, 42], [20, 45], [20, 47], [20, 53], [20, 57], [20, 58], [20, 61], [20, 68], [20, 71], [20, 72], [20, 74], [20, 89], [20, 90], [20, 94], [21, 23], [21, 25], [21, 31], [21, 32], [21, 37], [21, 39], [21, 40], [21, 45], [21, 46], [21, 54], [21, 55], [21, 61], [21, 62], [21, 63], [21, 65], [21, 67], [21, 77], [21, 81], [21, 83], [21, 87], [21, 92], [21, 93], [21, 95], [21, 96], [22, 26], [22, 27], [22, 30], [22, 32], [22, 34], [22, 37], [22, 38], [22, 40], [22, 43], [22, 45], [22, 47], [22, 52], [22, 53], [22, 57], [22, 58], [22, 65], [22, 66], [22, 73], [22, 79], [22, 83], [22, 85], [22, 86], [22, 98], [22, 99], [23, 28], [23, 30], [23, 35], [23, 40], [23, 41], [23, 43], [23, 46], [23, 54], [23, 55], [23, 57], [23, 61], [23, 65], [23, 74], [23, 79], [23, 85], [23, 86], [23, 90], [23, 91], [23, 93], [23, 94], [23, 99], [24, 28], [24, 29], [24, 31], [24, 32], [24, 35], [24, 38], [24, 40], [24, 46], [24, 47], [24, 55], [24, 58], [24, 62], [24, 66], [24, 73], [24, 78], [24, 80], [24, 81], [24, 96], [24, 99], [25, 26], [25, 28], [25, 31], [25, 34], [25, 36], [25, 37], [25, 38], [25, 41], [25, 59], [25, 60], [25, 64], [25, 65], [25, 69], [25, 70], [25, 72], [25, 75], [25, 77], [25, 86], [25, 87], [25, 92], [25, 93], [25, 94], [25, 96], [26, 27], [26, 33], [26, 36], [26, 38], [26, 42], [26, 43], [26, 49], [26, 50], [26, 52], [26, 55], [26, 59], [26, 70], [26, 75], [26, 78], [26, 82], [26, 83], [26, 90], [26, 91], [26, 95], [26, 96], [26, 97], [26, 98], [27, 29], [27, 30], [27, 31], [27, 32], [27, 34], [27, 44], [27, 46], [27, 47], [27, 48], [27, 50], [27, 53], [27, 57], [27, 58], [27, 59], [27, 62], [27, 63], [27, 64], [27, 68], [27, 83], [27, 84], [27, 86], [27, 88], [27, 89], [27, 92], [27, 96], [27, 97], [27, 98], [28, 29], [28, 33], [28, 35], [28, 36], [28, 37], [28, 45], [28, 46], [28, 47], [28, 49], [28, 50], [28, 56], [28, 72], [28, 82], [28, 83], [28, 85], [28, 90], [28, 95], [28, 99], [29, 30], [29, 32], [29, 47], [29, 58], [29, 62], [29, 66], [29, 73], [29, 75], [29, 77], [29, 79], [29, 82], [29, 85], [29, 86], [29, 91], [29, 97], [29, 98], [30, 32], [30, 33], [30, 42], [30, 46], [30, 49], [30, 51], [30, 53], [30, 54], [30, 58], [30, 62], [30, 66], [30, 68], [30, 73], [30, 75], [30, 77], [30, 78], [30, 81], [30, 83], [30, 90], [30, 95], [30, 97], [30, 98], [30, 99], [31, 34], [31, 39], [31, 40], [31, 51], [31, 66], [31, 70], [31, 79], [31, 82], [31, 83], [31, 85], [31, 87], [31, 90], [31, 98], [32, 35], [32, 37], [32, 42], [32, 43], [32, 44], [32, 51], [32, 52], [32, 55], [32, 57], [32, 58], [32, 59], [32, 67], [32, 71], [32, 72], [32, 78], [32, 80], [32, 84], [32, 85], [32, 88], [32, 89], [32, 94], [32, 96], [32, 99], [33, 41], [33, 43], [33, 46], [33, 49], [33, 53], [33, 54], [33, 57], [33, 70], [33, 74], [33, 77], [33, 82], [33, 85], [33, 86], [33, 89], [33, 93], [33, 94], [33, 97], [34, 39], [34, 44], [34, 49], [34, 53], [34, 59], [34, 64], [34, 69], [34, 70], [34, 71], [34, 74], [34, 78], [34, 80], [34, 82], [34, 83], [34, 86], [34, 87], [34, 90], [34, 94], [34, 98], [34, 99], [35, 41], [35, 43], [35, 44], [35, 45], [35, 52], [35, 54], [35, 55], [35, 58], [35, 63], [35, 65], [35, 71], [35, 80], [35, 83], [35, 84], [35, 87], [35, 92], [35, 93], [35, 94], [35, 96], [35, 97], [36, 38], [36, 40], [36, 47], [36, 63], [36, 65], [36, 75], [36, 77], [36, 79], [36, 83], [36, 89], [36, 96], [36, 97], [37, 40], [37, 41], [37, 43], [37, 50], [37, 58], [37, 63], [37, 70], [37, 72], [37, 74], [37, 75], [37, 77], [37, 83], [37, 87], [37, 91], [37, 97], [37, 99], [38, 40], [38, 44], [38, 45], [38, 46], [38, 52], [38, 59], [38, 64], [38, 66], [38, 69], [38, 72], [38, 73], [38, 74], [38, 76], [38, 77], [38, 80], [38, 82], [38, 88], [38, 92], [38, 93], [39, 40], [39, 41], [39, 43], [39, 48], [39, 51], [39, 56], [39, 62], [39, 64], [39, 67], [39, 72], [39, 73], [39, 74], [39, 75], [39, 77], [39, 80], [39, 84], [39, 94], [40, 41], [40, 50], [40, 51], [40, 55], [40, 60], [40, 62], [40, 65], [40, 66], [40, 77], [40, 79], [40, 81], [40, 89], [40, 93], [40, 97], [40, 99], [41, 52], [41, 58], [41, 61], [41, 63], [41, 64], [41, 67], [41, 69], [41, 75], [41, 79], [41, 82], [41, 83], [41, 86], [41, 89], [41, 90], [41, 96], [41, 97], [41, 98], [41, 99], [42, 49], [42, 51], [42, 52], [42, 57], [42, 59], [42, 63], [42, 70], [42, 72], [42, 83], [42, 84], [42, 86], [42, 87], [42, 89], [42, 93], [42, 99], [43, 44], [43, 51], [43, 56], [43, 57], [43, 59], [43, 60], [43, 62], [43, 70], [43, 72], [43, 77], [43, 79], [43, 80], [43, 83], [43, 84], [43, 88], [43, 89], [43, 97], [44, 47], [44, 49], [44, 52], [44, 54], [44, 55], [44, 65], [44, 66], [44, 70], [44, 72], [44, 74], [44, 75], [44, 83], [44, 91], [44, 97], [44, 99], [45, 48], [45, 49], [45, 51], [45, 55], [45, 56], [45, 60], [45, 62], [45, 66], [45, 67], [45, 69], [45, 78], [45, 80], [45, 82], [45, 86], [45, 87], [45, 88], [45, 90], [45, 91], [45, 93], [45, 94], [45, 98], [45, 99], [46, 50], [46, 52], [46, 58], [46, 62], [46, 65], [46, 67], [46, 69], [46, 70], [46, 73], [46, 78], [46, 80], [46, 81], [46, 82], [46, 90], [46, 93], [46, 95], [46, 96], [46, 98], [46, 99], [47, 48], [47, 50], [47, 51], [47, 53], [47, 57], [47, 60], [47, 67], [47, 71], [47, 74], [47, 75], [47, 78], [47, 80], [47, 83], [47, 84], [47, 86], [47, 88], [47, 89], [47, 90], [47, 91], [47, 94], [47, 97], [48, 49], [48, 51], [48, 52], [48, 62], [48, 89], [48, 93], [49, 51], [49, 56], [49, 62], [49, 68], [49, 73], [49, 74], [49, 76], [49, 79], [49, 86], [49, 88], [49, 94], [49, 95], [49, 98], [50, 52], [50, 57], [50, 61], [50, 63], [50, 66], [50, 74], [50, 86], [50, 93], [50, 94], [50, 99], [51, 58], [51, 60], [51, 62], [51, 63], [51, 65], [51, 66], [51, 68], [51, 70], [51, 74], [51, 79], [51, 80], [51, 81], [51, 83], [51, 88], [51, 91], [51, 96], [51, 98], [52, 55], [52, 56], [52, 57], [52, 61], [52, 66], [52, 67], [52, 69], [52, 72], [52, 80], [52, 82], [52, 88], [52, 89], [52, 91], [52, 95], [53, 54], [53, 56], [53, 58], [53, 60], [53, 61], [53, 62], [53, 63], [53, 68], [53, 71], [53, 72], [53, 73], [53, 77], [53, 86], [53, 89], [53, 94], [53, 97], [54, 57], [54, 59], [54, 60], [54, 63], [54, 64], [54, 66], [54, 67], [54, 69], [54, 71], [54, 73], [54, 74], [54, 75], [54, 77], [54, 78], [54, 80], [54, 91], [54, 94], [54, 99], [55, 58], [55, 59], [55, 62], [55, 67], [55, 75], [55, 80], [55, 87], [55, 93], [55, 99], [56, 71], [56, 74], [56, 77], [56, 90], [56, 91], [56, 96], [57, 59], [57, 60], [57, 61], [57, 62], [57, 63], [57, 64], [57, 69], [57, 74], [57, 77], [57, 79], [57, 84], [57, 86], [57, 93], [58, 70], [58, 82], [58, 84], [58, 86], [58, 99], [59, 62], [59, 68], [59, 71], [59, 72], [59, 83], [59, 89], [59, 99], [60, 61], [60, 63], [60, 70], [60, 75], [60, 81], [60, 85], [60, 87], [60, 89], [60, 91], [60, 94], [61, 67], [61, 69], [61, 71], [61, 72], [61, 75], [61, 77], [61, 85], [61, 91], [61, 94], [61, 95], [61, 96], [61, 98], [61, 99], [62, 65], [62, 67], [62, 70], [62, 71], [62, 74], [62, 75], [62, 77], [62, 89], [62, 91], [62, 95], [63, 65], [63, 66], [63, 68], [63, 71], [63, 72], [63, 76], [63, 81], [63, 86], [63, 92], [63, 96], [64, 65], [64, 81], [64, 93], [64, 98], [65, 66], [65, 67], [65, 69], [65, 70], [65, 72], [65, 73], [65, 74], [65, 82], [65, 83], [65, 87], [65, 88], [65, 89], [65, 92], [65, 97], [66, 67], [66, 71], [66, 72], [66, 77], [66, 80], [66, 82], [66, 86], [66, 88], [66, 94], [66, 98], [67, 72], [67, 81], [67, 82], [67, 89], [67, 91], [67, 97], [67, 98], [68, 72], [68, 73], [68, 77], [68, 79], [68, 81], [68, 82], [68, 85], [68, 91], [68, 92], [68, 94], [68, 95], [68, 98], [69, 73], [69, 74], [69, 77], [69, 79], [70, 71], [70, 73], [70, 75], [70, 78], [70, 81], [70, 83], [70, 84], [70, 86], [70, 89], [71, 77], [71, 83], [71, 85], [71, 89], [71, 91], [71, 94], [71, 97], [71, 99], [72, 73], [72, 78], [72, 80], [72, 81], [72, 89], [72, 90], [72, 92], [72, 94], [73, 74], [73, 75], [73, 77], [73, 80], [73, 81], [73, 84], [73, 87], [73, 97], [74, 76], [74, 79], [74, 83], [74, 84], [74, 85], [74, 88], [74, 97], [75, 85], [75, 91], [75, 95], [76, 82], [76, 86], [76, 87], [76, 93], [76, 97], [76, 98], [77, 81], [77, 94], [77, 98], [78, 79], [78, 81], [78, 86], [78, 90], [79, 82], [79, 87], [79, 88], [79, 93], [79, 94], [79, 95], [80, 81], [80, 83], [80, 86], [80, 87], [80, 89], [80, 99], [81, 89], [81, 90], [81, 96], [82, 83], [82, 87], [82, 88], [82, 90], [82, 94], [82, 99], [83, 88], [83, 94], [83, 98], [84, 85], [84, 86], [84, 90], [84, 94], [84, 97], [85, 86], [85, 88], [85, 96], [86, 88], [86, 90], [86, 94], [86, 97], [87, 89], [87, 90], [87, 93], [87, 94], [87, 95], [87, 96], [87, 97], [87, 98], [88, 90], [88, 93], [88, 94], [88, 97], [88, 99], [89, 90], [89, 91], [89, 94], [89, 97], [89, 99], [90, 96], [90, 98], [91, 97], [92, 98], [93, 94], [93, 97], [94, 95], [94, 96], [94, 97], [95, 96], [95, 99], [96, 99], [97, 98], [98, 99]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l6-s8/solution/solve.sh b/tasks/construct-nppc-independent-set-l6-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9163206cabb9d756d53d21713ec2f9d81cb47e63 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l6-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"independent_set": [0, 1, 2, 6, 7, 16, 19, 20, 22, 23, 29, 31, 33, 36, 44, 48, 50, 56, 59, 60, 64, 67, 69, 76, 78, 80, 84, 88, 92, 95]} +RLMATH_EOF diff --git a/tasks/construct-nppc-independent-set-l6-s8/tests/check.py b/tasks/construct-nppc-independent-set-l6-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..92279a931488c7f39c08a3b11162b3f54a9c662a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l6-s8/tests/check.py @@ -0,0 +1,19 @@ +"""Independent set of size >= k. Accepts any valid independent set.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + s = int_list(ans.get("independent_set"), None, 0, n - 1, "independent_set") + # upstream NPPC verifier checks len(list) >= size but only tests pairs u < v, so [v]*k passed + if len(set(s)) != len(s): + raise Invalid("independent_set contains duplicates") + if len(s) < k: + raise Invalid(f"independent_set has {len(s)} < {k} vertices") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(s), 2): + if (u, v) in es: + raise Invalid(f"edge between {u} and {v}") + return None, {"size": len(s)} diff --git a/tasks/construct-nppc-independent-set-l6-s8/tests/instance.json b/tasks/construct-nppc-independent-set-l6-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3b1aacc4f8e76d01ab9af8f4feee1cca1e7e0aeb --- /dev/null +++ b/tasks/construct-nppc-independent-set-l6-s8/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 100, "k": 30, "edges": [[0, 4], [0, 13], [0, 15], [0, 21], [0, 26], [0, 28], [0, 43], [0, 49], [0, 54], [0, 62], [0, 73], [0, 74], [0, 75], [0, 90], [0, 91], [0, 96], [0, 97], [0, 99], [1, 10], [1, 11], [1, 21], [1, 32], [1, 37], [1, 39], [1, 42], [1, 45], [1, 52], [1, 53], [1, 61], [1, 72], [1, 74], [1, 75], [1, 77], [1, 79], [1, 82], [1, 87], [1, 91], [1, 93], [1, 94], [2, 4], [2, 8], [2, 9], [2, 13], [2, 14], [2, 15], [2, 17], [2, 26], [2, 35], [2, 37], [2, 53], [2, 55], [2, 70], [2, 71], [2, 74], [2, 87], [2, 89], [2, 90], [2, 91], [2, 93], [3, 12], [3, 18], [3, 20], [3, 25], [3, 28], [3, 29], [3, 30], [3, 34], [3, 36], [3, 42], [3, 44], [3, 45], [3, 49], [3, 50], [3, 51], [3, 60], [3, 64], [3, 67], [3, 71], [3, 80], [3, 81], [3, 85], [3, 88], [3, 93], [3, 94], [3, 95], [3, 96], [3, 97], [4, 5], [4, 6], [4, 11], [4, 12], [4, 19], [4, 21], [4, 24], [4, 26], [4, 28], [4, 29], [4, 34], [4, 36], [4, 38], [4, 42], [4, 43], [4, 47], [4, 49], [4, 56], [4, 59], [4, 64], [4, 66], [4, 69], [4, 74], [4, 78], [4, 80], [4, 81], [4, 82], [4, 86], [4, 91], [4, 98], [4, 99], [5, 6], [5, 8], [5, 13], [5, 21], [5, 22], [5, 28], [5, 33], [5, 37], [5, 42], [5, 46], [5, 49], [5, 51], [5, 52], [5, 55], [5, 57], [5, 58], [5, 59], [5, 60], [5, 62], [5, 65], [5, 66], [5, 70], [5, 71], [5, 75], [5, 77], [5, 78], [5, 87], [5, 88], [5, 98], [6, 10], [6, 17], [6, 26], [6, 27], [6, 32], [6, 37], [6, 41], [6, 49], [6, 52], [6, 62], [6, 72], [6, 77], [6, 81], [6, 82], [6, 86], [6, 90], [6, 96], [6, 97], [7, 11], [7, 12], [7, 26], [7, 28], [7, 34], [7, 43], [7, 51], [7, 57], [7, 61], [7, 63], [7, 71], [7, 72], [7, 75], [7, 77], [7, 85], [7, 87], [7, 90], [7, 91], [7, 93], [7, 96], [8, 10], [8, 12], [8, 14], [8, 19], [8, 20], [8, 22], [8, 24], [8, 31], [8, 33], [8, 35], [8, 36], [8, 37], [8, 40], [8, 43], [8, 46], [8, 48], [8, 50], [8, 51], [8, 54], [8, 57], [8, 62], [8, 65], [8, 72], [8, 73], [8, 75], [8, 76], [8, 77], [8, 78], [8, 84], [8, 85], [8, 90], [8, 92], [9, 14], [9, 15], [9, 23], [9, 24], [9, 25], [9, 29], [9, 31], [9, 32], [9, 34], [9, 35], [9, 38], [9, 45], [9, 50], [9, 54], [9, 55], [9, 61], [9, 62], [9, 63], [9, 68], [9, 74], [9, 83], [9, 84], [9, 85], [9, 87], [9, 90], [10, 16], [10, 20], [10, 23], [10, 31], [10, 33], [10, 35], [10, 36], [10, 40], [10, 43], [10, 52], [10, 54], [10, 56], [10, 57], [10, 58], [10, 65], [10, 67], [10, 68], [10, 70], [10, 72], [10, 73], [10, 79], [10, 81], [10, 83], [10, 85], [10, 86], [10, 90], [10, 91], [10, 92], [10, 93], [10, 94], [10, 99], [11, 15], [11, 17], [11, 18], [11, 19], [11, 22], [11, 25], [11, 30], [11, 31], [11, 35], [11, 37], [11, 38], [11, 39], [11, 41], [11, 44], [11, 45], [11, 48], [11, 49], [11, 50], [11, 51], [11, 52], [11, 53], [11, 58], [11, 61], [11, 66], [11, 73], [11, 76], [11, 78], [11, 79], [11, 87], [11, 88], [11, 89], [11, 95], [11, 96], [11, 98], [12, 14], [12, 16], [12, 18], [12, 21], [12, 26], [12, 29], [12, 33], [12, 35], [12, 36], [12, 37], [12, 45], [12, 53], [12, 57], [12, 58], [12, 60], [12, 65], [12, 70], [12, 80], [12, 82], [12, 84], [12, 86], [12, 91], [12, 93], [12, 97], [12, 99], [13, 21], [13, 27], [13, 28], [13, 30], [13, 31], [13, 38], [13, 40], [13, 42], [13, 53], [13, 54], [13, 55], [13, 62], [13, 63], [13, 71], [13, 72], [13, 80], [13, 90], [13, 94], [14, 16], [14, 17], [14, 19], [14, 22], [14, 28], [14, 33], [14, 34], [14, 38], [14, 52], [14, 53], [14, 56], [14, 59], [14, 60], [14, 62], [14, 64], [14, 65], [14, 66], [14, 78], [14, 79], [14, 80], [14, 82], [14, 83], [14, 85], [14, 86], [14, 90], [14, 96], [15, 21], [15, 23], [15, 31], [15, 45], [15, 48], [15, 49], [15, 54], [15, 55], [15, 57], [15, 58], [15, 60], [15, 64], [15, 66], [15, 68], [15, 70], [15, 72], [15, 73], [15, 76], [15, 83], [15, 84], [15, 86], [15, 91], [15, 93], [15, 95], [15, 98], [16, 21], [16, 24], [16, 26], [16, 27], [16, 39], [16, 47], [16, 54], [16, 61], [16, 71], [16, 73], [16, 75], [16, 77], [16, 90], [16, 94], [17, 23], [17, 27], [17, 34], [17, 39], [17, 40], [17, 41], [17, 42], [17, 43], [17, 44], [17, 45], [17, 51], [17, 55], [17, 60], [17, 62], [17, 64], [17, 65], [17, 67], [17, 69], [17, 74], [17, 76], [17, 77], [17, 78], [17, 86], [17, 88], [17, 90], [17, 92], [17, 96], [17, 98], [17, 99], [18, 21], [18, 24], [18, 25], [18, 29], [18, 33], [18, 36], [18, 41], [18, 43], [18, 44], [18, 48], [18, 53], [18, 54], [18, 55], [18, 61], [18, 62], [18, 63], [18, 75], [18, 84], [18, 91], [18, 93], [18, 94], [18, 96], [18, 97], [19, 21], [19, 28], [19, 32], [19, 37], [19, 38], [19, 43], [19, 45], [19, 46], [19, 47], [19, 49], [19, 52], [19, 58], [19, 61], [19, 63], [19, 65], [19, 75], [19, 82], [19, 83], [19, 89], [19, 94], [19, 98], [19, 99], [20, 24], [20, 26], [20, 28], [20, 30], [20, 39], [20, 40], [20, 42], [20, 45], [20, 47], [20, 53], [20, 57], [20, 58], [20, 61], [20, 68], [20, 71], [20, 72], [20, 74], [20, 89], [20, 90], [20, 94], [21, 23], [21, 25], [21, 31], [21, 32], [21, 37], [21, 39], [21, 40], [21, 45], [21, 46], [21, 54], [21, 55], [21, 61], [21, 62], [21, 63], [21, 65], [21, 67], [21, 77], [21, 81], [21, 83], [21, 87], [21, 92], [21, 93], [21, 95], [21, 96], [22, 26], [22, 27], [22, 30], [22, 32], [22, 34], [22, 37], [22, 38], [22, 40], [22, 43], [22, 45], [22, 47], [22, 52], [22, 53], [22, 57], [22, 58], [22, 65], [22, 66], [22, 73], [22, 79], [22, 83], [22, 85], [22, 86], [22, 98], [22, 99], [23, 28], [23, 30], [23, 35], [23, 40], [23, 41], [23, 43], [23, 46], [23, 54], [23, 55], [23, 57], [23, 61], [23, 65], [23, 74], [23, 79], [23, 85], [23, 86], [23, 90], [23, 91], [23, 93], [23, 94], [23, 99], [24, 28], [24, 29], [24, 31], [24, 32], [24, 35], [24, 38], [24, 40], [24, 46], [24, 47], [24, 55], [24, 58], [24, 62], [24, 66], [24, 73], [24, 78], [24, 80], [24, 81], [24, 96], [24, 99], [25, 26], [25, 28], [25, 31], [25, 34], [25, 36], [25, 37], [25, 38], [25, 41], [25, 59], [25, 60], [25, 64], [25, 65], [25, 69], [25, 70], [25, 72], [25, 75], [25, 77], [25, 86], [25, 87], [25, 92], [25, 93], [25, 94], [25, 96], [26, 27], [26, 33], [26, 36], [26, 38], [26, 42], [26, 43], [26, 49], [26, 50], [26, 52], [26, 55], [26, 59], [26, 70], [26, 75], [26, 78], [26, 82], [26, 83], [26, 90], [26, 91], [26, 95], [26, 96], [26, 97], [26, 98], [27, 29], [27, 30], [27, 31], [27, 32], [27, 34], [27, 44], [27, 46], [27, 47], [27, 48], [27, 50], [27, 53], [27, 57], [27, 58], [27, 59], [27, 62], [27, 63], [27, 64], [27, 68], [27, 83], [27, 84], [27, 86], [27, 88], [27, 89], [27, 92], [27, 96], [27, 97], [27, 98], [28, 29], [28, 33], [28, 35], [28, 36], [28, 37], [28, 45], [28, 46], [28, 47], [28, 49], [28, 50], [28, 56], [28, 72], [28, 82], [28, 83], [28, 85], [28, 90], [28, 95], [28, 99], [29, 30], [29, 32], [29, 47], [29, 58], [29, 62], [29, 66], [29, 73], [29, 75], [29, 77], [29, 79], [29, 82], [29, 85], [29, 86], [29, 91], [29, 97], [29, 98], [30, 32], [30, 33], [30, 42], [30, 46], [30, 49], [30, 51], [30, 53], [30, 54], [30, 58], [30, 62], [30, 66], [30, 68], [30, 73], [30, 75], [30, 77], [30, 78], [30, 81], [30, 83], [30, 90], [30, 95], [30, 97], [30, 98], [30, 99], [31, 34], [31, 39], [31, 40], [31, 51], [31, 66], [31, 70], [31, 79], [31, 82], [31, 83], [31, 85], [31, 87], [31, 90], [31, 98], [32, 35], [32, 37], [32, 42], [32, 43], [32, 44], [32, 51], [32, 52], [32, 55], [32, 57], [32, 58], [32, 59], [32, 67], [32, 71], [32, 72], [32, 78], [32, 80], [32, 84], [32, 85], [32, 88], [32, 89], [32, 94], [32, 96], [32, 99], [33, 41], [33, 43], [33, 46], [33, 49], [33, 53], [33, 54], [33, 57], [33, 70], [33, 74], [33, 77], [33, 82], [33, 85], [33, 86], [33, 89], [33, 93], [33, 94], [33, 97], [34, 39], [34, 44], [34, 49], [34, 53], [34, 59], [34, 64], [34, 69], [34, 70], [34, 71], [34, 74], [34, 78], [34, 80], [34, 82], [34, 83], [34, 86], [34, 87], [34, 90], [34, 94], [34, 98], [34, 99], [35, 41], [35, 43], [35, 44], [35, 45], [35, 52], [35, 54], [35, 55], [35, 58], [35, 63], [35, 65], [35, 71], [35, 80], [35, 83], [35, 84], [35, 87], [35, 92], [35, 93], [35, 94], [35, 96], [35, 97], [36, 38], [36, 40], [36, 47], [36, 63], [36, 65], [36, 75], [36, 77], [36, 79], [36, 83], [36, 89], [36, 96], [36, 97], [37, 40], [37, 41], [37, 43], [37, 50], [37, 58], [37, 63], [37, 70], [37, 72], [37, 74], [37, 75], [37, 77], [37, 83], [37, 87], [37, 91], [37, 97], [37, 99], [38, 40], [38, 44], [38, 45], [38, 46], [38, 52], [38, 59], [38, 64], [38, 66], [38, 69], [38, 72], [38, 73], [38, 74], [38, 76], [38, 77], [38, 80], [38, 82], [38, 88], [38, 92], [38, 93], [39, 40], [39, 41], [39, 43], [39, 48], [39, 51], [39, 56], [39, 62], [39, 64], [39, 67], [39, 72], [39, 73], [39, 74], [39, 75], [39, 77], [39, 80], [39, 84], [39, 94], [40, 41], [40, 50], [40, 51], [40, 55], [40, 60], [40, 62], [40, 65], [40, 66], [40, 77], [40, 79], [40, 81], [40, 89], [40, 93], [40, 97], [40, 99], [41, 52], [41, 58], [41, 61], [41, 63], [41, 64], [41, 67], [41, 69], [41, 75], [41, 79], [41, 82], [41, 83], [41, 86], [41, 89], [41, 90], [41, 96], [41, 97], [41, 98], [41, 99], [42, 49], [42, 51], [42, 52], [42, 57], [42, 59], [42, 63], [42, 70], [42, 72], [42, 83], [42, 84], [42, 86], [42, 87], [42, 89], [42, 93], [42, 99], [43, 44], [43, 51], [43, 56], [43, 57], [43, 59], [43, 60], [43, 62], [43, 70], [43, 72], [43, 77], [43, 79], [43, 80], [43, 83], [43, 84], [43, 88], [43, 89], [43, 97], [44, 47], [44, 49], [44, 52], [44, 54], [44, 55], [44, 65], [44, 66], [44, 70], [44, 72], [44, 74], [44, 75], [44, 83], [44, 91], [44, 97], [44, 99], [45, 48], [45, 49], [45, 51], [45, 55], [45, 56], [45, 60], [45, 62], [45, 66], [45, 67], [45, 69], [45, 78], [45, 80], [45, 82], [45, 86], [45, 87], [45, 88], [45, 90], [45, 91], [45, 93], [45, 94], [45, 98], [45, 99], [46, 50], [46, 52], [46, 58], [46, 62], [46, 65], [46, 67], [46, 69], [46, 70], [46, 73], [46, 78], [46, 80], [46, 81], [46, 82], [46, 90], [46, 93], [46, 95], [46, 96], [46, 98], [46, 99], [47, 48], [47, 50], [47, 51], [47, 53], [47, 57], [47, 60], [47, 67], [47, 71], [47, 74], [47, 75], [47, 78], [47, 80], [47, 83], [47, 84], [47, 86], [47, 88], [47, 89], [47, 90], [47, 91], [47, 94], [47, 97], [48, 49], [48, 51], [48, 52], [48, 62], [48, 89], [48, 93], [49, 51], [49, 56], [49, 62], [49, 68], [49, 73], [49, 74], [49, 76], [49, 79], [49, 86], [49, 88], [49, 94], [49, 95], [49, 98], [50, 52], [50, 57], [50, 61], [50, 63], [50, 66], [50, 74], [50, 86], [50, 93], [50, 94], [50, 99], [51, 58], [51, 60], [51, 62], [51, 63], [51, 65], [51, 66], [51, 68], [51, 70], [51, 74], [51, 79], [51, 80], [51, 81], [51, 83], [51, 88], [51, 91], [51, 96], [51, 98], [52, 55], [52, 56], [52, 57], [52, 61], [52, 66], [52, 67], [52, 69], [52, 72], [52, 80], [52, 82], [52, 88], [52, 89], [52, 91], [52, 95], [53, 54], [53, 56], [53, 58], [53, 60], [53, 61], [53, 62], [53, 63], [53, 68], [53, 71], [53, 72], [53, 73], [53, 77], [53, 86], [53, 89], [53, 94], [53, 97], [54, 57], [54, 59], [54, 60], [54, 63], [54, 64], [54, 66], [54, 67], [54, 69], [54, 71], [54, 73], [54, 74], [54, 75], [54, 77], [54, 78], [54, 80], [54, 91], [54, 94], [54, 99], [55, 58], [55, 59], [55, 62], [55, 67], [55, 75], [55, 80], [55, 87], [55, 93], [55, 99], [56, 71], [56, 74], [56, 77], [56, 90], [56, 91], [56, 96], [57, 59], [57, 60], [57, 61], [57, 62], [57, 63], [57, 64], [57, 69], [57, 74], [57, 77], [57, 79], [57, 84], [57, 86], [57, 93], [58, 70], [58, 82], [58, 84], [58, 86], [58, 99], [59, 62], [59, 68], [59, 71], [59, 72], [59, 83], [59, 89], [59, 99], [60, 61], [60, 63], [60, 70], [60, 75], [60, 81], [60, 85], [60, 87], [60, 89], [60, 91], [60, 94], [61, 67], [61, 69], [61, 71], [61, 72], [61, 75], [61, 77], [61, 85], [61, 91], [61, 94], [61, 95], [61, 96], [61, 98], [61, 99], [62, 65], [62, 67], [62, 70], [62, 71], [62, 74], [62, 75], [62, 77], [62, 89], [62, 91], [62, 95], [63, 65], [63, 66], [63, 68], [63, 71], [63, 72], [63, 76], [63, 81], [63, 86], [63, 92], [63, 96], [64, 65], [64, 81], [64, 93], [64, 98], [65, 66], [65, 67], [65, 69], [65, 70], [65, 72], [65, 73], [65, 74], [65, 82], [65, 83], [65, 87], [65, 88], [65, 89], [65, 92], [65, 97], [66, 67], [66, 71], [66, 72], [66, 77], [66, 80], [66, 82], [66, 86], [66, 88], [66, 94], [66, 98], [67, 72], [67, 81], [67, 82], [67, 89], [67, 91], [67, 97], [67, 98], [68, 72], [68, 73], [68, 77], [68, 79], [68, 81], [68, 82], [68, 85], [68, 91], [68, 92], [68, 94], [68, 95], [68, 98], [69, 73], [69, 74], [69, 77], [69, 79], [70, 71], [70, 73], [70, 75], [70, 78], [70, 81], [70, 83], [70, 84], [70, 86], [70, 89], [71, 77], [71, 83], [71, 85], [71, 89], [71, 91], [71, 94], [71, 97], [71, 99], [72, 73], [72, 78], [72, 80], [72, 81], [72, 89], [72, 90], [72, 92], [72, 94], [73, 74], [73, 75], [73, 77], [73, 80], [73, 81], [73, 84], [73, 87], [73, 97], [74, 76], [74, 79], [74, 83], [74, 84], [74, 85], [74, 88], [74, 97], [75, 85], [75, 91], [75, 95], [76, 82], [76, 86], [76, 87], [76, 93], [76, 97], [76, 98], [77, 81], [77, 94], [77, 98], [78, 79], [78, 81], [78, 86], [78, 90], [79, 82], [79, 87], [79, 88], [79, 93], [79, 94], [79, 95], [80, 81], [80, 83], [80, 86], [80, 87], [80, 89], [80, 99], [81, 89], [81, 90], [81, 96], [82, 83], [82, 87], [82, 88], [82, 90], [82, 94], [82, 99], [83, 88], [83, 94], [83, 98], [84, 85], [84, 86], [84, 90], [84, 94], [84, 97], [85, 86], [85, 88], [85, 96], [86, 88], [86, 90], [86, 94], [86, 97], [87, 89], [87, 90], [87, 93], [87, 94], [87, 95], [87, 96], [87, 97], [87, 98], [88, 90], [88, 93], [88, 94], [88, 97], [88, 99], [89, 90], [89, 91], [89, 94], [89, 97], [89, 99], [90, 96], [90, 98], [91, 97], [92, 98], [93, 94], [93, 97], [94, 95], [94, 96], [94, 97], [95, 96], [95, 99], [96, 99], [97, 98], [98, 99]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l6-s8/tests/run.py b/tasks/construct-nppc-independent-set-l6-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l6-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-independent-set-l6-s8/tests/test.sh b/tasks/construct-nppc-independent-set-l6-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l6-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-quad-diophantine-l3-s1/environment/Dockerfile b/tasks/construct-nppc-quad-diophantine-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l3-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-quad-diophantine-l3-s1/environment/instance.json b/tasks/construct-nppc-quad-diophantine-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8d195ebc86c41387abfb11d19d9c6710e9b21706 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"a": 7555, "b": 9939, "c": 169692304042, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l3-s1/solution/solve.sh b/tasks/construct-nppc-quad-diophantine-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e11ed7554556ecad6c234e7a6daca2b45b0881e6 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l3-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 4739, "y": 2133} +RLMATH_EOF diff --git a/tasks/construct-nppc-quad-diophantine-l3-s1/tests/check.py b/tasks/construct-nppc-quad-diophantine-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..88989d2a8839b089c9b07dd2d3c26c21bfdca58c --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l3-s1/tests/check.py @@ -0,0 +1,11 @@ +"""a*x^2 + b*y = c in positive integers. Accepts any solution (exact integer arithmetic).""" +from run import Invalid, as_int + + +def check(inst, ans): + # upstream NPPC verifier only checks x > 0 and y > 0, so non-integer (float) x, y were accepted + x = as_int(ans.get("x"), "x", lo=1) + y = as_int(ans.get("y"), "y", lo=1) + if inst["a"] * x * x + inst["b"] * y != inst["c"]: + raise Invalid("a*x^2 + b*y != c") + return None, {} diff --git a/tasks/construct-nppc-quad-diophantine-l3-s1/tests/instance.json b/tasks/construct-nppc-quad-diophantine-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8d195ebc86c41387abfb11d19d9c6710e9b21706 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"a": 7555, "b": 9939, "c": 169692304042, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l3-s1/tests/run.py b/tasks/construct-nppc-quad-diophantine-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l3-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-quad-diophantine-l3-s1/tests/test.sh b/tasks/construct-nppc-quad-diophantine-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l3-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-quad-diophantine-l3-s6/environment/Dockerfile b/tasks/construct-nppc-quad-diophantine-l3-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l3-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-quad-diophantine-l3-s6/environment/instance.json b/tasks/construct-nppc-quad-diophantine-l3-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ab1e700d945ec1d54df4c05e378e2951d47742e1 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l3-s6/environment/instance.json @@ -0,0 +1 @@ +{"a": 8735, "b": 344, "c": 280407895, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l3-s6/solution/solve.sh b/tasks/construct-nppc-quad-diophantine-l3-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0ae7845442af9318ce54ee734aa7dfbfeca19ab6 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l3-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 179, "y": 1540} +RLMATH_EOF diff --git a/tasks/construct-nppc-quad-diophantine-l3-s6/tests/check.py b/tasks/construct-nppc-quad-diophantine-l3-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..88989d2a8839b089c9b07dd2d3c26c21bfdca58c --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l3-s6/tests/check.py @@ -0,0 +1,11 @@ +"""a*x^2 + b*y = c in positive integers. Accepts any solution (exact integer arithmetic).""" +from run import Invalid, as_int + + +def check(inst, ans): + # upstream NPPC verifier only checks x > 0 and y > 0, so non-integer (float) x, y were accepted + x = as_int(ans.get("x"), "x", lo=1) + y = as_int(ans.get("y"), "y", lo=1) + if inst["a"] * x * x + inst["b"] * y != inst["c"]: + raise Invalid("a*x^2 + b*y != c") + return None, {} diff --git a/tasks/construct-nppc-quad-diophantine-l3-s6/tests/instance.json b/tasks/construct-nppc-quad-diophantine-l3-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ab1e700d945ec1d54df4c05e378e2951d47742e1 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l3-s6/tests/instance.json @@ -0,0 +1 @@ +{"a": 8735, "b": 344, "c": 280407895, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l3-s6/tests/run.py b/tasks/construct-nppc-quad-diophantine-l3-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l3-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-quad-diophantine-l3-s6/tests/test.sh b/tasks/construct-nppc-quad-diophantine-l3-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l3-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-quad-diophantine-l3-s8/environment/Dockerfile b/tasks/construct-nppc-quad-diophantine-l3-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l3-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-quad-diophantine-l3-s8/environment/instance.json b/tasks/construct-nppc-quad-diophantine-l3-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fb5585d87489c4cf21601b84411761b47751304a --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l3-s8/environment/instance.json @@ -0,0 +1 @@ +{"a": 8536, "b": 6523, "c": 309502648565, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l3-s8/solution/solve.sh b/tasks/construct-nppc-quad-diophantine-l3-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..01d1d5b85253e3e90b2c4c1e3f1e337d26467983 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l3-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 6021, "y": 7943} +RLMATH_EOF diff --git a/tasks/construct-nppc-quad-diophantine-l3-s8/tests/check.py b/tasks/construct-nppc-quad-diophantine-l3-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..88989d2a8839b089c9b07dd2d3c26c21bfdca58c --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l3-s8/tests/check.py @@ -0,0 +1,11 @@ +"""a*x^2 + b*y = c in positive integers. Accepts any solution (exact integer arithmetic).""" +from run import Invalid, as_int + + +def check(inst, ans): + # upstream NPPC verifier only checks x > 0 and y > 0, so non-integer (float) x, y were accepted + x = as_int(ans.get("x"), "x", lo=1) + y = as_int(ans.get("y"), "y", lo=1) + if inst["a"] * x * x + inst["b"] * y != inst["c"]: + raise Invalid("a*x^2 + b*y != c") + return None, {} diff --git a/tasks/construct-nppc-quad-diophantine-l3-s8/tests/instance.json b/tasks/construct-nppc-quad-diophantine-l3-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fb5585d87489c4cf21601b84411761b47751304a --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l3-s8/tests/instance.json @@ -0,0 +1 @@ +{"a": 8536, "b": 6523, "c": 309502648565, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l3-s8/tests/run.py b/tasks/construct-nppc-quad-diophantine-l3-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l3-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-quad-diophantine-l3-s8/tests/test.sh b/tasks/construct-nppc-quad-diophantine-l3-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l3-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-quadratic-congruence-l3-s1/environment/Dockerfile b/tasks/construct-nppc-quadratic-congruence-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l3-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-quadratic-congruence-l3-s1/environment/instance.json b/tasks/construct-nppc-quadratic-congruence-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..752cfbe5c589484d7248726d13088fd5d5145920 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"a": 10210, "b": 16122, "c": 125582, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l3-s1/solution/solve.sh b/tasks/construct-nppc-quadratic-congruence-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7dfbc353c13c78d52c90289dc284f88ab1ed346f --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l3-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 78620} +RLMATH_EOF diff --git a/tasks/construct-nppc-quadratic-congruence-l3-s1/tests/check.py b/tasks/construct-nppc-quadratic-congruence-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..1a751c071a276ca0aae7fb05bfdcd7b6e0c6d3a6 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l3-s1/tests/check.py @@ -0,0 +1,11 @@ +"""Quadratic congruence: integer x with 1 <= x < c and x^2 = a (mod b). Accepts any such x.""" +from run import Invalid, as_int + + +def check(inst, ans): + # upstream NPPC verifier did int(x) (accepting "12", 12.9 -> 12) and only checked x < c, so negative x + # (e.g. -r for any root r) and x = 0 passed and the bound c was meaningless + x = as_int(ans.get("x"), "x", lo=1, hi=inst["c"] - 1) + if x * x % inst["b"] != inst["a"]: + raise Invalid("x^2 mod b != a") + return None, {} diff --git a/tasks/construct-nppc-quadratic-congruence-l3-s1/tests/instance.json b/tasks/construct-nppc-quadratic-congruence-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..752cfbe5c589484d7248726d13088fd5d5145920 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"a": 10210, "b": 16122, "c": 125582, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l3-s1/tests/run.py b/tasks/construct-nppc-quadratic-congruence-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l3-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-quadratic-congruence-l3-s1/tests/test.sh b/tasks/construct-nppc-quadratic-congruence-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l3-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-quadratic-congruence-l3-s6/environment/Dockerfile b/tasks/construct-nppc-quadratic-congruence-l3-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l3-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-quadratic-congruence-l3-s6/environment/instance.json b/tasks/construct-nppc-quadratic-congruence-l3-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..66cd82c355ba1ff794843ef770091f3f38611a7f --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l3-s6/environment/instance.json @@ -0,0 +1 @@ +{"a": 42453, "b": 88308, "c": 85990, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l3-s6/solution/solve.sh b/tasks/construct-nppc-quadratic-congruence-l3-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ab6fa9bf2a33982ac373d01f8a5240a675346d93 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l3-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 2253} +RLMATH_EOF diff --git a/tasks/construct-nppc-quadratic-congruence-l3-s6/tests/check.py b/tasks/construct-nppc-quadratic-congruence-l3-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..1a751c071a276ca0aae7fb05bfdcd7b6e0c6d3a6 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l3-s6/tests/check.py @@ -0,0 +1,11 @@ +"""Quadratic congruence: integer x with 1 <= x < c and x^2 = a (mod b). Accepts any such x.""" +from run import Invalid, as_int + + +def check(inst, ans): + # upstream NPPC verifier did int(x) (accepting "12", 12.9 -> 12) and only checked x < c, so negative x + # (e.g. -r for any root r) and x = 0 passed and the bound c was meaningless + x = as_int(ans.get("x"), "x", lo=1, hi=inst["c"] - 1) + if x * x % inst["b"] != inst["a"]: + raise Invalid("x^2 mod b != a") + return None, {} diff --git a/tasks/construct-nppc-quadratic-congruence-l3-s6/tests/instance.json b/tasks/construct-nppc-quadratic-congruence-l3-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..66cd82c355ba1ff794843ef770091f3f38611a7f --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l3-s6/tests/instance.json @@ -0,0 +1 @@ +{"a": 42453, "b": 88308, "c": 85990, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l3-s6/tests/run.py b/tasks/construct-nppc-quadratic-congruence-l3-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l3-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-quadratic-congruence-l3-s6/tests/test.sh b/tasks/construct-nppc-quadratic-congruence-l3-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l3-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-quadratic-congruence-l3-s8/environment/Dockerfile b/tasks/construct-nppc-quadratic-congruence-l3-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l3-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-quadratic-congruence-l3-s8/environment/instance.json b/tasks/construct-nppc-quadratic-congruence-l3-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d76bb552fe5c49955734ba8c8a9e476dc3ec4243 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l3-s8/environment/instance.json @@ -0,0 +1 @@ +{"a": 467, "b": 13759, "c": 79208, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l3-s8/solution/solve.sh b/tasks/construct-nppc-quadratic-congruence-l3-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d86b27c7f965c97fb9987e6cc3ead9f1927b6803 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l3-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 39573} +RLMATH_EOF diff --git a/tasks/construct-nppc-quadratic-congruence-l3-s8/tests/check.py b/tasks/construct-nppc-quadratic-congruence-l3-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..1a751c071a276ca0aae7fb05bfdcd7b6e0c6d3a6 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l3-s8/tests/check.py @@ -0,0 +1,11 @@ +"""Quadratic congruence: integer x with 1 <= x < c and x^2 = a (mod b). Accepts any such x.""" +from run import Invalid, as_int + + +def check(inst, ans): + # upstream NPPC verifier did int(x) (accepting "12", 12.9 -> 12) and only checked x < c, so negative x + # (e.g. -r for any root r) and x = 0 passed and the bound c was meaningless + x = as_int(ans.get("x"), "x", lo=1, hi=inst["c"] - 1) + if x * x % inst["b"] != inst["a"]: + raise Invalid("x^2 mod b != a") + return None, {} diff --git a/tasks/construct-nppc-quadratic-congruence-l3-s8/tests/instance.json b/tasks/construct-nppc-quadratic-congruence-l3-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d76bb552fe5c49955734ba8c8a9e476dc3ec4243 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l3-s8/tests/instance.json @@ -0,0 +1 @@ +{"a": 467, "b": 13759, "c": 79208, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l3-s8/tests/run.py b/tasks/construct-nppc-quadratic-congruence-l3-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l3-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-quadratic-congruence-l3-s8/tests/test.sh b/tasks/construct-nppc-quadratic-congruence-l3-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l3-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-vertex-cover-l1-s3/environment/Dockerfile b/tasks/construct-nppc-vertex-cover-l1-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l1-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-vertex-cover-l1-s3/environment/instance.json b/tasks/construct-nppc-vertex-cover-l1-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..452e368b8bad76d5689ca5e73450bf1f047ad773 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l1-s3/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "k": 3, "edges": [[0, 1], [0, 5], [1, 2], [1, 3], [1, 4], [1, 6], [1, 7], [2, 4], [2, 5], [3, 4], [4, 6], [5, 6], [5, 7]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l1-s3/solution/solve.sh b/tasks/construct-nppc-vertex-cover-l1-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5ab860b4fcbe259e4d80a32e261b11f47e0541d5 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l1-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"cover": [1, 4, 5]} +RLMATH_EOF diff --git a/tasks/construct-nppc-vertex-cover-l1-s3/tests/check.py b/tasks/construct-nppc-vertex-cover-l1-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d8ed740cc660c4837d941a8d70ea394c3bc9f69e --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l1-s3/tests/check.py @@ -0,0 +1,18 @@ +"""Vertex cover of size <= k. Accepts any valid cover.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + # upstream NPPC verifier converts to a set without type checks (floats/bools slip through and + # duplicates are silently merged); here entries must be distinct ints in range + c = int_list(ans.get("cover"), None, 0, n - 1, "cover") + if len(set(c)) != len(c): + raise Invalid("cover contains duplicates") + if len(c) > k: + raise Invalid(f"cover has {len(c)} > {k} vertices") + s = set(c) + for u, v in inst["edges"]: + if u not in s and v not in s: + raise Invalid(f"edge ({u},{v}) not covered") + return None, {"size": len(c)} diff --git a/tasks/construct-nppc-vertex-cover-l1-s3/tests/instance.json b/tasks/construct-nppc-vertex-cover-l1-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..452e368b8bad76d5689ca5e73450bf1f047ad773 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l1-s3/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "k": 3, "edges": [[0, 1], [0, 5], [1, 2], [1, 3], [1, 4], [1, 6], [1, 7], [2, 4], [2, 5], [3, 4], [4, 6], [5, 6], [5, 7]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l1-s3/tests/run.py b/tasks/construct-nppc-vertex-cover-l1-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l1-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-vertex-cover-l1-s3/tests/test.sh b/tasks/construct-nppc-vertex-cover-l1-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l1-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-vertex-cover-l1-s4/environment/Dockerfile b/tasks/construct-nppc-vertex-cover-l1-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l1-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-vertex-cover-l1-s4/environment/instance.json b/tasks/construct-nppc-vertex-cover-l1-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..94068278cdf7e51316dff65f1fb0f643af482edf --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l1-s4/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "k": 3, "edges": [[0, 4], [0, 7], [1, 2], [1, 7], [2, 3], [2, 4], [2, 6], [2, 7], [3, 4], [3, 7], [4, 5], [4, 6], [4, 7], [5, 7]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l1-s4/solution/solve.sh b/tasks/construct-nppc-vertex-cover-l1-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..118f4ac0afb103cd9b28f9473319970a5c50ea3e --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l1-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"cover": [2, 4, 7]} +RLMATH_EOF diff --git a/tasks/construct-nppc-vertex-cover-l1-s4/tests/check.py b/tasks/construct-nppc-vertex-cover-l1-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d8ed740cc660c4837d941a8d70ea394c3bc9f69e --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l1-s4/tests/check.py @@ -0,0 +1,18 @@ +"""Vertex cover of size <= k. Accepts any valid cover.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + # upstream NPPC verifier converts to a set without type checks (floats/bools slip through and + # duplicates are silently merged); here entries must be distinct ints in range + c = int_list(ans.get("cover"), None, 0, n - 1, "cover") + if len(set(c)) != len(c): + raise Invalid("cover contains duplicates") + if len(c) > k: + raise Invalid(f"cover has {len(c)} > {k} vertices") + s = set(c) + for u, v in inst["edges"]: + if u not in s and v not in s: + raise Invalid(f"edge ({u},{v}) not covered") + return None, {"size": len(c)} diff --git a/tasks/construct-nppc-vertex-cover-l1-s4/tests/instance.json b/tasks/construct-nppc-vertex-cover-l1-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..94068278cdf7e51316dff65f1fb0f643af482edf --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l1-s4/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "k": 3, "edges": [[0, 4], [0, 7], [1, 2], [1, 7], [2, 3], [2, 4], [2, 6], [2, 7], [3, 4], [3, 7], [4, 5], [4, 6], [4, 7], [5, 7]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l1-s4/tests/run.py b/tasks/construct-nppc-vertex-cover-l1-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l1-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-vertex-cover-l1-s4/tests/test.sh b/tasks/construct-nppc-vertex-cover-l1-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l1-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-vertex-cover-l5-s5/environment/Dockerfile b/tasks/construct-nppc-vertex-cover-l5-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l5-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-vertex-cover-l5-s5/environment/instance.json b/tasks/construct-nppc-vertex-cover-l5-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..44e11b9fa2995dca7a608101b25f7beb42772fd3 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l5-s5/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 80, "k": 40, "edges": [[0, 1], [0, 3], [0, 5], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [0, 14], [0, 15], [0, 18], [0, 19], [0, 20], [0, 23], [0, 24], [0, 25], [0, 31], [0, 33], [0, 34], [0, 35], [0, 39], [0, 40], [0, 41], [0, 44], [0, 46], [0, 47], [0, 50], [0, 52], [0, 55], [0, 57], [0, 58], [0, 59], [0, 60], [0, 61], [0, 64], [0, 65], [0, 67], [0, 68], [0, 69], [0, 70], [0, 72], [0, 73], [0, 75], [0, 76], [0, 77], [0, 78], [1, 3], [1, 4], [1, 5], [1, 7], [1, 9], [1, 11], [1, 12], [1, 15], [1, 16], [1, 18], [1, 19], [1, 20], [1, 21], [1, 23], [1, 24], [1, 27], [1, 28], [1, 29], [1, 31], [1, 34], [1, 35], [1, 36], [1, 37], [1, 40], [1, 41], [1, 43], [1, 44], [1, 46], [1, 47], [1, 50], [1, 53], [1, 54], [1, 55], [1, 60], [1, 62], [1, 64], [1, 65], [1, 66], [1, 68], [1, 70], [1, 71], [1, 74], [1, 75], [1, 76], [1, 77], [1, 78], [2, 3], [2, 12], [2, 13], [2, 27], [2, 28], [2, 30], [2, 34], [2, 36], [2, 38], [2, 49], [2, 53], [2, 54], [2, 55], [2, 64], [2, 68], [2, 69], [2, 74], [2, 76], [3, 4], [3, 5], [3, 7], [3, 8], [3, 9], [3, 11], [3, 12], [3, 13], [3, 14], [3, 15], [3, 17], [3, 18], [3, 21], [3, 23], [3, 25], [3, 28], [3, 30], [3, 32], [3, 33], [3, 34], [3, 35], [3, 37], [3, 38], [3, 39], [3, 40], [3, 41], [3, 42], [3, 43], [3, 44], [3, 45], [3, 46], [3, 47], [3, 49], [3, 51], [3, 53], [3, 54], [3, 55], [3, 56], [3, 58], [3, 59], [3, 62], [3, 63], [3, 64], [3, 66], [3, 68], [3, 69], [3, 71], [3, 72], [3, 73], [3, 74], [3, 75], [3, 77], [3, 78], [3, 79], [4, 12], [4, 19], [4, 21], [4, 23], [4, 30], [4, 31], [4, 35], [4, 38], [4, 39], [4, 44], [4, 46], [4, 62], [4, 64], [4, 72], [4, 76], [4, 78], [5, 12], [5, 19], [5, 20], [5, 23], [5, 27], [5, 28], [5, 31], [5, 43], [5, 44], [5, 51], [5, 53], [5, 54], [5, 62], [5, 67], [5, 69], [5, 72], [5, 74], [5, 78], [6, 13], [6, 15], [6, 27], [6, 28], [6, 31], [6, 34], [6, 36], [6, 38], [6, 39], [6, 41], [6, 46], [6, 51], [6, 53], [6, 54], [6, 55], [6, 66], [6, 69], [6, 72], [6, 75], [6, 76], [6, 78], [7, 13], [7, 19], [7, 20], [7, 21], [7, 23], [7, 27], [7, 34], [7, 35], [7, 36], [7, 39], [7, 41], [7, 46], [7, 49], [7, 53], [7, 54], [7, 55], [7, 64], [7, 67], [7, 75], [8, 12], [8, 13], [8, 27], [8, 30], [8, 35], [8, 36], [8, 43], [8, 46], [8, 49], [8, 54], [8, 55], [8, 62], [8, 64], [8, 67], [8, 68], [8, 76], [9, 12], [9, 13], [9, 20], [9, 27], [9, 30], [9, 31], [9, 34], [9, 38], [9, 43], [9, 44], [9, 46], [9, 51], [9, 62], [9, 66], [10, 13], [10, 21], [10, 36], [10, 38], [10, 40], [10, 41], [10, 43], [10, 44], [10, 46], [10, 54], [10, 55], [10, 62], [10, 64], [10, 66], [10, 67], [10, 68], [10, 69], [10, 72], [11, 13], [11, 15], [11, 20], [11, 23], [11, 36], [11, 39], [11, 40], [11, 43], [11, 55], [11, 62], [11, 66], [11, 67], [11, 75], [11, 78], [12, 13], [12, 14], [12, 15], [12, 16], [12, 17], [12, 19], [12, 21], [12, 23], [12, 24], [12, 25], [12, 31], [12, 32], [12, 37], [12, 38], [12, 39], [12, 42], [12, 43], [12, 44], [12, 46], [12, 47], [12, 52], [12, 53], [12, 54], [12, 55], [12, 60], [12, 61], [12, 62], [12, 63], [12, 64], [12, 65], [12, 67], [12, 68], [12, 69], [12, 72], [12, 73], [12, 75], [12, 76], [12, 77], [12, 78], [12, 79], [13, 15], [13, 16], [13, 18], [13, 20], [13, 21], [13, 22], [13, 23], [13, 24], [13, 25], [13, 27], [13, 28], [13, 30], [13, 31], [13, 34], [13, 35], [13, 38], [13, 39], [13, 42], [13, 44], [13, 45], [13, 47], [13, 50], [13, 51], [13, 52], [13, 53], [13, 54], [13, 55], [13, 59], [13, 60], [13, 62], [13, 63], [13, 64], [13, 65], [13, 66], [13, 67], [13, 70], [13, 71], [13, 72], [13, 73], [13, 75], [13, 78], [13, 79], [14, 15], [14, 19], [14, 20], [14, 23], [14, 27], [14, 28], [14, 31], [14, 34], [14, 35], [14, 38], [14, 40], [14, 41], [14, 43], [14, 46], [14, 54], [14, 55], [14, 62], [14, 66], [14, 67], [14, 68], [14, 72], [14, 76], [14, 78], [15, 16], [15, 17], [15, 18], [15, 19], [15, 20], [15, 21], [15, 24], [15, 28], [15, 29], [15, 30], [15, 31], [15, 32], [15, 33], [15, 34], [15, 35], [15, 36], [15, 37], [15, 40], [15, 43], [15, 44], [15, 45], [15, 47], [15, 49], [15, 51], [15, 52], [15, 53], [15, 54], [15, 55], [15, 56], [15, 61], [15, 62], [15, 64], [15, 67], [15, 69], [15, 73], [15, 74], [15, 75], [15, 77], [15, 78], [15, 79], [16, 23], [16, 27], [16, 28], [16, 31], [16, 35], [16, 38], [16, 40], [16, 44], [16, 49], [16, 51], [16, 54], [16, 62], [16, 72], [16, 74], [17, 20], [17, 30], [17, 31], [17, 40], [17, 41], [17, 43], [17, 49], [17, 55], [17, 66], [17, 67], [17, 72], [17, 74], [17, 76], [18, 19], [18, 20], [18, 27], [18, 35], [18, 36], [18, 39], [18, 46], [18, 49], [18, 54], [18, 55], [18, 62], [18, 66], [18, 67], [18, 68], [18, 72], [18, 74], [18, 75], [19, 21], [19, 22], [19, 25], [19, 26], [19, 27], [19, 29], [19, 30], [19, 31], [19, 32], [19, 33], [19, 34], [19, 35], [19, 36], [19, 39], [19, 40], [19, 41], [19, 42], [19, 44], [19, 45], [19, 49], [19, 50], [19, 51], [19, 54], [19, 55], [19, 64], [19, 68], [19, 69], [19, 71], [19, 72], [19, 73], [19, 74], [19, 75], [19, 78], [19, 79], [20, 21], [20, 25], [20, 26], [20, 27], [20, 28], [20, 30], [20, 31], [20, 32], [20, 33], [20, 34], [20, 36], [20, 39], [20, 40], [20, 44], [20, 45], [20, 48], [20, 49], [20, 50], [20, 51], [20, 53], [20, 54], [20, 55], [20, 56], [20, 57], [20, 59], [20, 60], [20, 61], [20, 62], [20, 63], [20, 64], [20, 67], [20, 69], [20, 70], [20, 72], [20, 73], [20, 74], [20, 75], [20, 77], [20, 78], [21, 23], [21, 25], [21, 28], [21, 29], [21, 33], [21, 34], [21, 35], [21, 38], [21, 39], [21, 40], [21, 41], [21, 42], [21, 43], [21, 48], [21, 49], [21, 50], [21, 51], [21, 52], [21, 53], [21, 54], [21, 55], [21, 57], [21, 60], [21, 61], [21, 62], [21, 64], [21, 65], [21, 66], [21, 67], [21, 69], [21, 70], [21, 71], [21, 72], [21, 73], [21, 76], [21, 77], [21, 79], [22, 23], [22, 27], [22, 28], [22, 30], [22, 31], [22, 34], [22, 38], [22, 39], [22, 46], [22, 53], [22, 55], [22, 66], [22, 69], [22, 72], [22, 75], [22, 76], [23, 24], [23, 27], [23, 28], [23, 30], [23, 31], [23, 32], [23, 33], [23, 35], [23, 36], [23, 37], [23, 39], [23, 40], [23, 41], [23, 43], [23, 44], [23, 46], [23, 49], [23, 50], [23, 51], [23, 57], [23, 58], [23, 64], [23, 65], [23, 70], [23, 72], [23, 75], [23, 77], [23, 78], [23, 79], [24, 27], [24, 30], [24, 31], [24, 34], [24, 38], [24, 39], [24, 43], [24, 44], [24, 51], [24, 54], [24, 55], [24, 62], [24, 64], [24, 67], [24, 68], [24, 72], [24, 74], [24, 75], [24, 76], [25, 28], [25, 34], [25, 36], [25, 38], [25, 39], [25, 40], [25, 41], [25, 46], [25, 49], [25, 53], [25, 54], [25, 62], [25, 64], [25, 67], [25, 68], [25, 74], [25, 76], [25, 78], [26, 31], [26, 34], [26, 36], [26, 38], [26, 44], [26, 46], [26, 49], [26, 54], [26, 64], [26, 67], [26, 69], [26, 74], [27, 28], [27, 31], [27, 32], [27, 33], [27, 34], [27, 36], [27, 37], [27, 38], [27, 39], [27, 40], [27, 41], [27, 42], [27, 43], [27, 44], [27, 46], [27, 48], [27, 49], [27, 50], [27, 51], [27, 52], [27, 53], [27, 54], [27, 55], [27, 56], [27, 59], [27, 62], [27, 63], [27, 66], [27, 68], [27, 69], [27, 71], [27, 72], [27, 73], [27, 74], [27, 75], [27, 76], [27, 79], [28, 29], [28, 30], [28, 31], [28, 35], [28, 36], [28, 38], [28, 39], [28, 40], [28, 41], [28, 42], [28, 44], [28, 45], [28, 46], [28, 49], [28, 50], [28, 51], [28, 53], [28, 54], [28, 55], [28, 57], [28, 59], [28, 63], [28, 64], [28, 65], [28, 67], [28, 68], [28, 69], [28, 70], [28, 71], [28, 72], [28, 73], [28, 74], [28, 75], [28, 76], [28, 77], [28, 78], [28, 79], [29, 34], [29, 36], [29, 39], [29, 40], [29, 41], [29, 43], [29, 49], [29, 66], [29, 68], [29, 69], [29, 72], [29, 75], [29, 78], [30, 31], [30, 33], [30, 34], [30, 35], [30, 36], [30, 37], [30, 40], [30, 41], [30, 43], [30, 44], [30, 46], [30, 48], [30, 51], [30, 54], [30, 55], [30, 56], [30, 57], [30, 58], [30, 59], [30, 61], [30, 62], [30, 66], [30, 67], [30, 68], [30, 69], [30, 70], [30, 71], [30, 72], [30, 73], [30, 74], [30, 75], [31, 32], [31, 34], [31, 37], [31, 38], [31, 39], [31, 40], [31, 41], [31, 44], [31, 46], [31, 47], [31, 48], [31, 49], [31, 54], [31, 55], [31, 56], [31, 57], [31, 60], [31, 61], [31, 62], [31, 64], [31, 66], [31, 67], [31, 68], [31, 69], [31, 70], [31, 74], [31, 75], [31, 76], [31, 78], [31, 79], [32, 34], [32, 39], [32, 40], [32, 41], [32, 43], [32, 46], [32, 53], [32, 54], [32, 64], [32, 72], [32, 74], [32, 76], [32, 78], [33, 35], [33, 36], [33, 38], [33, 39], [33, 44], [33, 49], [33, 51], [33, 54], [33, 68], [33, 69], [33, 76], [33, 78], [34, 36], [34, 38], [34, 39], [34, 40], [34, 41], [34, 42], [34, 43], [34, 44], [34, 46], [34, 48], [34, 49], [34, 51], [34, 54], [34, 55], [34, 56], [34, 57], [34, 59], [34, 60], [34, 64], [34, 65], [34, 66], [34, 67], [34, 68], [34, 70], [34, 71], [34, 74], [34, 78], [35, 36], [35, 37], [35, 38], [35, 39], [35, 40], [35, 41], [35, 42], [35, 43], [35, 44], [35, 46], [35, 47], [35, 48], [35, 49], [35, 50], [35, 51], [35, 53], [35, 54], [35, 59], [35, 60], [35, 61], [35, 66], [35, 68], [35, 69], [35, 70], [35, 73], [35, 76], [35, 77], [35, 78], [36, 37], [36, 38], [36, 40], [36, 41], [36, 42], [36, 43], [36, 45], [36, 46], [36, 47], [36, 49], [36, 51], [36, 53], [36, 54], [36, 56], [36, 57], [36, 58], [36, 62], [36, 64], [36, 65], [36, 67], [36, 71], [36, 73], [36, 74], [36, 75], [36, 76], [36, 77], [37, 38], [37, 41], [37, 44], [37, 49], [37, 54], [37, 55], [37, 68], [37, 69], [37, 72], [37, 74], [37, 76], [37, 78], [38, 39], [38, 40], [38, 41], [38, 42], [38, 43], [38, 44], [38, 46], [38, 48], [38, 49], [38, 51], [38, 52], [38, 53], [38, 54], [38, 55], [38, 62], [38, 63], [38, 65], [38, 66], [38, 67], [38, 68], [38, 69], [38, 72], [38, 74], [38, 75], [38, 76], [38, 77], [38, 79], [39, 40], [39, 41], [39, 44], [39, 45], [39, 46], [39, 47], [39, 50], [39, 53], [39, 56], [39, 57], [39, 59], [39, 61], [39, 62], [39, 66], [39, 67], [39, 68], [39, 69], [39, 72], [39, 74], [39, 75], [39, 76], [39, 78], [40, 41], [40, 43], [40, 44], [40, 46], [40, 47], [40, 49], [40, 50], [40, 51], [40, 52], [40, 54], [40, 56], [40, 58], [40, 62], [40, 63], [40, 64], [40, 65], [40, 66], [40, 67], [40, 71], [40, 73], [40, 76], [40, 77], [40, 78], [40, 79], [41, 43], [41, 46], [41, 48], [41, 49], [41, 50], [41, 54], [41, 55], [41, 56], [41, 59], [41, 60], [41, 62], [41, 64], [41, 65], [41, 66], [41, 67], [41, 69], [41, 71], [41, 72], [41, 74], [41, 76], [41, 78], [41, 79], [42, 43], [42, 44], [42, 49], [42, 54], [42, 55], [42, 66], [42, 69], [42, 72], [42, 75], [42, 78], [43, 45], [43, 46], [43, 50], [43, 51], [43, 52], [43, 54], [43, 55], [43, 58], [43, 59], [43, 62], [43, 65], [43, 66], [43, 68], [43, 70], [43, 73], [43, 74], [43, 75], [43, 77], [43, 78], [43, 79], [44, 45], [44, 48], [44, 50], [44, 51], [44, 52], [44, 53], [44, 55], [44, 56], [44, 57], [44, 58], [44, 59], [44, 62], [44, 63], [44, 65], [44, 67], [44, 70], [44, 71], [44, 74], [44, 75], [44, 76], [44, 79], [45, 49], [45, 51], [45, 53], [45, 55], [45, 64], [45, 72], [46, 50], [46, 51], [46, 54], [46, 55], [46, 57], [46, 59], [46, 62], [46, 63], [46, 64], [46, 66], [46, 67], [46, 68], [46, 69], [46, 70], [46, 71], [46, 72], [46, 73], [46, 74], [46, 77], [46, 78], [47, 53], [47, 54], [47, 64], [47, 66], [47, 67], [47, 68], [47, 69], [47, 72], [47, 74], [47, 75], [47, 76], [47, 78], [48, 51], [48, 53], [48, 54], [48, 62], [48, 67], [48, 68], [48, 72], [48, 75], [48, 76], [49, 50], [49, 51], [49, 55], [49, 57], [49, 60], [49, 62], [49, 63], [49, 66], [49, 68], [49, 70], [49, 71], [49, 72], [49, 74], [49, 75], [49, 76], [49, 77], [49, 78], [49, 79], [50, 51], [50, 55], [50, 67], [50, 69], [50, 72], [50, 74], [51, 53], [51, 57], [51, 58], [51, 60], [51, 62], [51, 63], [51, 65], [51, 66], [51, 67], [51, 68], [51, 69], [51, 71], [51, 72], [51, 74], [51, 76], [51, 78], [51, 79], [52, 53], [52, 54], [52, 55], [52, 62], [52, 68], [52, 72], [52, 74], [52, 76], [52, 78], [53, 54], [53, 60], [53, 61], [53, 62], [53, 63], [53, 64], [53, 65], [53, 66], [53, 67], [53, 68], [53, 69], [53, 70], [53, 71], [53, 72], [53, 74], [53, 75], [53, 76], [53, 77], [53, 79], [54, 55], [54, 56], [54, 58], [54, 62], [54, 65], [54, 66], [54, 67], [54, 68], [54, 69], [54, 71], [54, 73], [54, 74], [54, 76], [54, 77], [54, 78], [54, 79], [55, 58], [55, 60], [55, 64], [55, 65], [55, 66], [55, 67], [55, 69], [55, 72], [55, 74], [55, 76], [55, 77], [55, 78], [55, 79], [56, 62], [56, 64], [56, 72], [56, 75], [57, 62], [57, 64], [57, 66], [57, 67], [57, 68], [57, 74], [57, 76], [57, 78], [58, 62], [58, 67], [58, 69], [58, 72], [58, 76], [58, 78], [59, 62], [59, 67], [59, 68], [59, 74], [59, 75], [59, 76], [59, 78], [60, 64], [60, 72], [60, 76], [61, 68], [61, 72], [61, 74], [61, 75], [62, 64], [62, 65], [62, 66], [62, 68], [62, 69], [62, 70], [62, 72], [62, 74], [62, 76], [62, 77], [62, 78], [63, 64], [63, 68], [63, 69], [63, 74], [63, 78], [64, 65], [64, 66], [64, 67], [64, 68], [64, 69], [64, 71], [64, 72], [64, 74], [64, 75], [64, 77], [64, 79], [65, 66], [65, 68], [65, 72], [65, 75], [65, 78], [66, 68], [66, 69], [66, 70], [66, 71], [66, 73], [66, 77], [66, 78], [66, 79], [67, 68], [67, 69], [67, 72], [67, 74], [67, 75], [67, 76], [67, 77], [67, 78], [68, 69], [68, 71], [68, 72], [68, 73], [68, 75], [68, 77], [68, 78], [68, 79], [69, 70], [69, 72], [69, 75], [69, 76], [69, 78], [70, 72], [70, 76], [70, 78], [71, 72], [71, 74], [71, 75], [72, 74], [72, 76], [72, 78], [73, 74], [73, 75], [73, 76], [74, 75], [74, 76], [74, 77], [75, 79], [76, 77], [76, 78], [76, 79], [77, 78], [78, 79]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l5-s5/solution/solve.sh b/tasks/construct-nppc-vertex-cover-l5-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4616a5731c4716c6ac5684af3221f4a36388f514 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l5-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"cover": [0, 1, 3, 12, 13, 15, 19, 20, 21, 23, 27, 28, 30, 31, 34, 35, 36, 38, 39, 40, 41, 43, 44, 46, 49, 51, 53, 54, 55, 62, 64, 66, 67, 68, 69, 72, 74, 75, 76, 78]} +RLMATH_EOF diff --git a/tasks/construct-nppc-vertex-cover-l5-s5/tests/check.py b/tasks/construct-nppc-vertex-cover-l5-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d8ed740cc660c4837d941a8d70ea394c3bc9f69e --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l5-s5/tests/check.py @@ -0,0 +1,18 @@ +"""Vertex cover of size <= k. Accepts any valid cover.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + # upstream NPPC verifier converts to a set without type checks (floats/bools slip through and + # duplicates are silently merged); here entries must be distinct ints in range + c = int_list(ans.get("cover"), None, 0, n - 1, "cover") + if len(set(c)) != len(c): + raise Invalid("cover contains duplicates") + if len(c) > k: + raise Invalid(f"cover has {len(c)} > {k} vertices") + s = set(c) + for u, v in inst["edges"]: + if u not in s and v not in s: + raise Invalid(f"edge ({u},{v}) not covered") + return None, {"size": len(c)} diff --git a/tasks/construct-nppc-vertex-cover-l5-s5/tests/instance.json b/tasks/construct-nppc-vertex-cover-l5-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..44e11b9fa2995dca7a608101b25f7beb42772fd3 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l5-s5/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 80, "k": 40, "edges": [[0, 1], [0, 3], [0, 5], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [0, 14], [0, 15], [0, 18], [0, 19], [0, 20], [0, 23], [0, 24], [0, 25], [0, 31], [0, 33], [0, 34], [0, 35], [0, 39], [0, 40], [0, 41], [0, 44], [0, 46], [0, 47], [0, 50], [0, 52], [0, 55], [0, 57], [0, 58], [0, 59], [0, 60], [0, 61], [0, 64], [0, 65], [0, 67], [0, 68], [0, 69], [0, 70], [0, 72], [0, 73], [0, 75], [0, 76], [0, 77], [0, 78], [1, 3], [1, 4], [1, 5], [1, 7], [1, 9], [1, 11], [1, 12], [1, 15], [1, 16], [1, 18], [1, 19], [1, 20], [1, 21], [1, 23], [1, 24], [1, 27], [1, 28], [1, 29], [1, 31], [1, 34], [1, 35], [1, 36], [1, 37], [1, 40], [1, 41], [1, 43], [1, 44], [1, 46], [1, 47], [1, 50], [1, 53], [1, 54], [1, 55], [1, 60], [1, 62], [1, 64], [1, 65], [1, 66], [1, 68], [1, 70], [1, 71], [1, 74], [1, 75], [1, 76], [1, 77], [1, 78], [2, 3], [2, 12], [2, 13], [2, 27], [2, 28], [2, 30], [2, 34], [2, 36], [2, 38], [2, 49], [2, 53], [2, 54], [2, 55], [2, 64], [2, 68], [2, 69], [2, 74], [2, 76], [3, 4], [3, 5], [3, 7], [3, 8], [3, 9], [3, 11], [3, 12], [3, 13], [3, 14], [3, 15], [3, 17], [3, 18], [3, 21], [3, 23], [3, 25], [3, 28], [3, 30], [3, 32], [3, 33], [3, 34], [3, 35], [3, 37], [3, 38], [3, 39], [3, 40], [3, 41], [3, 42], [3, 43], [3, 44], [3, 45], [3, 46], [3, 47], [3, 49], [3, 51], [3, 53], [3, 54], [3, 55], [3, 56], [3, 58], [3, 59], [3, 62], [3, 63], [3, 64], [3, 66], [3, 68], [3, 69], [3, 71], [3, 72], [3, 73], [3, 74], [3, 75], [3, 77], [3, 78], [3, 79], [4, 12], [4, 19], [4, 21], [4, 23], [4, 30], [4, 31], [4, 35], [4, 38], [4, 39], [4, 44], [4, 46], [4, 62], [4, 64], [4, 72], [4, 76], [4, 78], [5, 12], [5, 19], [5, 20], [5, 23], [5, 27], [5, 28], [5, 31], [5, 43], [5, 44], [5, 51], [5, 53], [5, 54], [5, 62], [5, 67], [5, 69], [5, 72], [5, 74], [5, 78], [6, 13], [6, 15], [6, 27], [6, 28], [6, 31], [6, 34], [6, 36], [6, 38], [6, 39], [6, 41], [6, 46], [6, 51], [6, 53], [6, 54], [6, 55], [6, 66], [6, 69], [6, 72], [6, 75], [6, 76], [6, 78], [7, 13], [7, 19], [7, 20], [7, 21], [7, 23], [7, 27], [7, 34], [7, 35], [7, 36], [7, 39], [7, 41], [7, 46], [7, 49], [7, 53], [7, 54], [7, 55], [7, 64], [7, 67], [7, 75], [8, 12], [8, 13], [8, 27], [8, 30], [8, 35], [8, 36], [8, 43], [8, 46], [8, 49], [8, 54], [8, 55], [8, 62], [8, 64], [8, 67], [8, 68], [8, 76], [9, 12], [9, 13], [9, 20], [9, 27], [9, 30], [9, 31], [9, 34], [9, 38], [9, 43], [9, 44], [9, 46], [9, 51], [9, 62], [9, 66], [10, 13], [10, 21], [10, 36], [10, 38], [10, 40], [10, 41], [10, 43], [10, 44], [10, 46], [10, 54], [10, 55], [10, 62], [10, 64], [10, 66], [10, 67], [10, 68], [10, 69], [10, 72], [11, 13], [11, 15], [11, 20], [11, 23], [11, 36], [11, 39], [11, 40], [11, 43], [11, 55], [11, 62], [11, 66], [11, 67], [11, 75], [11, 78], [12, 13], [12, 14], [12, 15], [12, 16], [12, 17], [12, 19], [12, 21], [12, 23], [12, 24], [12, 25], [12, 31], [12, 32], [12, 37], [12, 38], [12, 39], [12, 42], [12, 43], [12, 44], [12, 46], [12, 47], [12, 52], [12, 53], [12, 54], [12, 55], [12, 60], [12, 61], [12, 62], [12, 63], [12, 64], [12, 65], [12, 67], [12, 68], [12, 69], [12, 72], [12, 73], [12, 75], [12, 76], [12, 77], [12, 78], [12, 79], [13, 15], [13, 16], [13, 18], [13, 20], [13, 21], [13, 22], [13, 23], [13, 24], [13, 25], [13, 27], [13, 28], [13, 30], [13, 31], [13, 34], [13, 35], [13, 38], [13, 39], [13, 42], [13, 44], [13, 45], [13, 47], [13, 50], [13, 51], [13, 52], [13, 53], [13, 54], [13, 55], [13, 59], [13, 60], [13, 62], [13, 63], [13, 64], [13, 65], [13, 66], [13, 67], [13, 70], [13, 71], [13, 72], [13, 73], [13, 75], [13, 78], [13, 79], [14, 15], [14, 19], [14, 20], [14, 23], [14, 27], [14, 28], [14, 31], [14, 34], [14, 35], [14, 38], [14, 40], [14, 41], [14, 43], [14, 46], [14, 54], [14, 55], [14, 62], [14, 66], [14, 67], [14, 68], [14, 72], [14, 76], [14, 78], [15, 16], [15, 17], [15, 18], [15, 19], [15, 20], [15, 21], [15, 24], [15, 28], [15, 29], [15, 30], [15, 31], [15, 32], [15, 33], [15, 34], [15, 35], [15, 36], [15, 37], [15, 40], [15, 43], [15, 44], [15, 45], [15, 47], [15, 49], [15, 51], [15, 52], [15, 53], [15, 54], [15, 55], [15, 56], [15, 61], [15, 62], [15, 64], [15, 67], [15, 69], [15, 73], [15, 74], [15, 75], [15, 77], [15, 78], [15, 79], [16, 23], [16, 27], [16, 28], [16, 31], [16, 35], [16, 38], [16, 40], [16, 44], [16, 49], [16, 51], [16, 54], [16, 62], [16, 72], [16, 74], [17, 20], [17, 30], [17, 31], [17, 40], [17, 41], [17, 43], [17, 49], [17, 55], [17, 66], [17, 67], [17, 72], [17, 74], [17, 76], [18, 19], [18, 20], [18, 27], [18, 35], [18, 36], [18, 39], [18, 46], [18, 49], [18, 54], [18, 55], [18, 62], [18, 66], [18, 67], [18, 68], [18, 72], [18, 74], [18, 75], [19, 21], [19, 22], [19, 25], [19, 26], [19, 27], [19, 29], [19, 30], [19, 31], [19, 32], [19, 33], [19, 34], [19, 35], [19, 36], [19, 39], [19, 40], [19, 41], [19, 42], [19, 44], [19, 45], [19, 49], [19, 50], [19, 51], [19, 54], [19, 55], [19, 64], [19, 68], [19, 69], [19, 71], [19, 72], [19, 73], [19, 74], [19, 75], [19, 78], [19, 79], [20, 21], [20, 25], [20, 26], [20, 27], [20, 28], [20, 30], [20, 31], [20, 32], [20, 33], [20, 34], [20, 36], [20, 39], [20, 40], [20, 44], [20, 45], [20, 48], [20, 49], [20, 50], [20, 51], [20, 53], [20, 54], [20, 55], [20, 56], [20, 57], [20, 59], [20, 60], [20, 61], [20, 62], [20, 63], [20, 64], [20, 67], [20, 69], [20, 70], [20, 72], [20, 73], [20, 74], [20, 75], [20, 77], [20, 78], [21, 23], [21, 25], [21, 28], [21, 29], [21, 33], [21, 34], [21, 35], [21, 38], [21, 39], [21, 40], [21, 41], [21, 42], [21, 43], [21, 48], [21, 49], [21, 50], [21, 51], [21, 52], [21, 53], [21, 54], [21, 55], [21, 57], [21, 60], [21, 61], [21, 62], [21, 64], [21, 65], [21, 66], [21, 67], [21, 69], [21, 70], [21, 71], [21, 72], [21, 73], [21, 76], [21, 77], [21, 79], [22, 23], [22, 27], [22, 28], [22, 30], [22, 31], [22, 34], [22, 38], [22, 39], [22, 46], [22, 53], [22, 55], [22, 66], [22, 69], [22, 72], [22, 75], [22, 76], [23, 24], [23, 27], [23, 28], [23, 30], [23, 31], [23, 32], [23, 33], [23, 35], [23, 36], [23, 37], [23, 39], [23, 40], [23, 41], [23, 43], [23, 44], [23, 46], [23, 49], [23, 50], [23, 51], [23, 57], [23, 58], [23, 64], [23, 65], [23, 70], [23, 72], [23, 75], [23, 77], [23, 78], [23, 79], [24, 27], [24, 30], [24, 31], [24, 34], [24, 38], [24, 39], [24, 43], [24, 44], [24, 51], [24, 54], [24, 55], [24, 62], [24, 64], [24, 67], [24, 68], [24, 72], [24, 74], [24, 75], [24, 76], [25, 28], [25, 34], [25, 36], [25, 38], [25, 39], [25, 40], [25, 41], [25, 46], [25, 49], [25, 53], [25, 54], [25, 62], [25, 64], [25, 67], [25, 68], [25, 74], [25, 76], [25, 78], [26, 31], [26, 34], [26, 36], [26, 38], [26, 44], [26, 46], [26, 49], [26, 54], [26, 64], [26, 67], [26, 69], [26, 74], [27, 28], [27, 31], [27, 32], [27, 33], [27, 34], [27, 36], [27, 37], [27, 38], [27, 39], [27, 40], [27, 41], [27, 42], [27, 43], [27, 44], [27, 46], [27, 48], [27, 49], [27, 50], [27, 51], [27, 52], [27, 53], [27, 54], [27, 55], [27, 56], [27, 59], [27, 62], [27, 63], [27, 66], [27, 68], [27, 69], [27, 71], [27, 72], [27, 73], [27, 74], [27, 75], [27, 76], [27, 79], [28, 29], [28, 30], [28, 31], [28, 35], [28, 36], [28, 38], [28, 39], [28, 40], [28, 41], [28, 42], [28, 44], [28, 45], [28, 46], [28, 49], [28, 50], [28, 51], [28, 53], [28, 54], [28, 55], [28, 57], [28, 59], [28, 63], [28, 64], [28, 65], [28, 67], [28, 68], [28, 69], [28, 70], [28, 71], [28, 72], [28, 73], [28, 74], [28, 75], [28, 76], [28, 77], [28, 78], [28, 79], [29, 34], [29, 36], [29, 39], [29, 40], [29, 41], [29, 43], [29, 49], [29, 66], [29, 68], [29, 69], [29, 72], [29, 75], [29, 78], [30, 31], [30, 33], [30, 34], [30, 35], [30, 36], [30, 37], [30, 40], [30, 41], [30, 43], [30, 44], [30, 46], [30, 48], [30, 51], [30, 54], [30, 55], [30, 56], [30, 57], [30, 58], [30, 59], [30, 61], [30, 62], [30, 66], [30, 67], [30, 68], [30, 69], [30, 70], [30, 71], [30, 72], [30, 73], [30, 74], [30, 75], [31, 32], [31, 34], [31, 37], [31, 38], [31, 39], [31, 40], [31, 41], [31, 44], [31, 46], [31, 47], [31, 48], [31, 49], [31, 54], [31, 55], [31, 56], [31, 57], [31, 60], [31, 61], [31, 62], [31, 64], [31, 66], [31, 67], [31, 68], [31, 69], [31, 70], [31, 74], [31, 75], [31, 76], [31, 78], [31, 79], [32, 34], [32, 39], [32, 40], [32, 41], [32, 43], [32, 46], [32, 53], [32, 54], [32, 64], [32, 72], [32, 74], [32, 76], [32, 78], [33, 35], [33, 36], [33, 38], [33, 39], [33, 44], [33, 49], [33, 51], [33, 54], [33, 68], [33, 69], [33, 76], [33, 78], [34, 36], [34, 38], [34, 39], [34, 40], [34, 41], [34, 42], [34, 43], [34, 44], [34, 46], [34, 48], [34, 49], [34, 51], [34, 54], [34, 55], [34, 56], [34, 57], [34, 59], [34, 60], [34, 64], [34, 65], [34, 66], [34, 67], [34, 68], [34, 70], [34, 71], [34, 74], [34, 78], [35, 36], [35, 37], [35, 38], [35, 39], [35, 40], [35, 41], [35, 42], [35, 43], [35, 44], [35, 46], [35, 47], [35, 48], [35, 49], [35, 50], [35, 51], [35, 53], [35, 54], [35, 59], [35, 60], [35, 61], [35, 66], [35, 68], [35, 69], [35, 70], [35, 73], [35, 76], [35, 77], [35, 78], [36, 37], [36, 38], [36, 40], [36, 41], [36, 42], [36, 43], [36, 45], [36, 46], [36, 47], [36, 49], [36, 51], [36, 53], [36, 54], [36, 56], [36, 57], [36, 58], [36, 62], [36, 64], [36, 65], [36, 67], [36, 71], [36, 73], [36, 74], [36, 75], [36, 76], [36, 77], [37, 38], [37, 41], [37, 44], [37, 49], [37, 54], [37, 55], [37, 68], [37, 69], [37, 72], [37, 74], [37, 76], [37, 78], [38, 39], [38, 40], [38, 41], [38, 42], [38, 43], [38, 44], [38, 46], [38, 48], [38, 49], [38, 51], [38, 52], [38, 53], [38, 54], [38, 55], [38, 62], [38, 63], [38, 65], [38, 66], [38, 67], [38, 68], [38, 69], [38, 72], [38, 74], [38, 75], [38, 76], [38, 77], [38, 79], [39, 40], [39, 41], [39, 44], [39, 45], [39, 46], [39, 47], [39, 50], [39, 53], [39, 56], [39, 57], [39, 59], [39, 61], [39, 62], [39, 66], [39, 67], [39, 68], [39, 69], [39, 72], [39, 74], [39, 75], [39, 76], [39, 78], [40, 41], [40, 43], [40, 44], [40, 46], [40, 47], [40, 49], [40, 50], [40, 51], [40, 52], [40, 54], [40, 56], [40, 58], [40, 62], [40, 63], [40, 64], [40, 65], [40, 66], [40, 67], [40, 71], [40, 73], [40, 76], [40, 77], [40, 78], [40, 79], [41, 43], [41, 46], [41, 48], [41, 49], [41, 50], [41, 54], [41, 55], [41, 56], [41, 59], [41, 60], [41, 62], [41, 64], [41, 65], [41, 66], [41, 67], [41, 69], [41, 71], [41, 72], [41, 74], [41, 76], [41, 78], [41, 79], [42, 43], [42, 44], [42, 49], [42, 54], [42, 55], [42, 66], [42, 69], [42, 72], [42, 75], [42, 78], [43, 45], [43, 46], [43, 50], [43, 51], [43, 52], [43, 54], [43, 55], [43, 58], [43, 59], [43, 62], [43, 65], [43, 66], [43, 68], [43, 70], [43, 73], [43, 74], [43, 75], [43, 77], [43, 78], [43, 79], [44, 45], [44, 48], [44, 50], [44, 51], [44, 52], [44, 53], [44, 55], [44, 56], [44, 57], [44, 58], [44, 59], [44, 62], [44, 63], [44, 65], [44, 67], [44, 70], [44, 71], [44, 74], [44, 75], [44, 76], [44, 79], [45, 49], [45, 51], [45, 53], [45, 55], [45, 64], [45, 72], [46, 50], [46, 51], [46, 54], [46, 55], [46, 57], [46, 59], [46, 62], [46, 63], [46, 64], [46, 66], [46, 67], [46, 68], [46, 69], [46, 70], [46, 71], [46, 72], [46, 73], [46, 74], [46, 77], [46, 78], [47, 53], [47, 54], [47, 64], [47, 66], [47, 67], [47, 68], [47, 69], [47, 72], [47, 74], [47, 75], [47, 76], [47, 78], [48, 51], [48, 53], [48, 54], [48, 62], [48, 67], [48, 68], [48, 72], [48, 75], [48, 76], [49, 50], [49, 51], [49, 55], [49, 57], [49, 60], [49, 62], [49, 63], [49, 66], [49, 68], [49, 70], [49, 71], [49, 72], [49, 74], [49, 75], [49, 76], [49, 77], [49, 78], [49, 79], [50, 51], [50, 55], [50, 67], [50, 69], [50, 72], [50, 74], [51, 53], [51, 57], [51, 58], [51, 60], [51, 62], [51, 63], [51, 65], [51, 66], [51, 67], [51, 68], [51, 69], [51, 71], [51, 72], [51, 74], [51, 76], [51, 78], [51, 79], [52, 53], [52, 54], [52, 55], [52, 62], [52, 68], [52, 72], [52, 74], [52, 76], [52, 78], [53, 54], [53, 60], [53, 61], [53, 62], [53, 63], [53, 64], [53, 65], [53, 66], [53, 67], [53, 68], [53, 69], [53, 70], [53, 71], [53, 72], [53, 74], [53, 75], [53, 76], [53, 77], [53, 79], [54, 55], [54, 56], [54, 58], [54, 62], [54, 65], [54, 66], [54, 67], [54, 68], [54, 69], [54, 71], [54, 73], [54, 74], [54, 76], [54, 77], [54, 78], [54, 79], [55, 58], [55, 60], [55, 64], [55, 65], [55, 66], [55, 67], [55, 69], [55, 72], [55, 74], [55, 76], [55, 77], [55, 78], [55, 79], [56, 62], [56, 64], [56, 72], [56, 75], [57, 62], [57, 64], [57, 66], [57, 67], [57, 68], [57, 74], [57, 76], [57, 78], [58, 62], [58, 67], [58, 69], [58, 72], [58, 76], [58, 78], [59, 62], [59, 67], [59, 68], [59, 74], [59, 75], [59, 76], [59, 78], [60, 64], [60, 72], [60, 76], [61, 68], [61, 72], [61, 74], [61, 75], [62, 64], [62, 65], [62, 66], [62, 68], [62, 69], [62, 70], [62, 72], [62, 74], [62, 76], [62, 77], [62, 78], [63, 64], [63, 68], [63, 69], [63, 74], [63, 78], [64, 65], [64, 66], [64, 67], [64, 68], [64, 69], [64, 71], [64, 72], [64, 74], [64, 75], [64, 77], [64, 79], [65, 66], [65, 68], [65, 72], [65, 75], [65, 78], [66, 68], [66, 69], [66, 70], [66, 71], [66, 73], [66, 77], [66, 78], [66, 79], [67, 68], [67, 69], [67, 72], [67, 74], [67, 75], [67, 76], [67, 77], [67, 78], [68, 69], [68, 71], [68, 72], [68, 73], [68, 75], [68, 77], [68, 78], [68, 79], [69, 70], [69, 72], [69, 75], [69, 76], [69, 78], [70, 72], [70, 76], [70, 78], [71, 72], [71, 74], [71, 75], [72, 74], [72, 76], [72, 78], [73, 74], [73, 75], [73, 76], [74, 75], [74, 76], [74, 77], [75, 79], [76, 77], [76, 78], [76, 79], [77, 78], [78, 79]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l5-s5/tests/run.py b/tasks/construct-nppc-vertex-cover-l5-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l5-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-vertex-cover-l5-s5/tests/test.sh b/tasks/construct-nppc-vertex-cover-l5-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l5-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-graph-color-l2-s6/environment/Dockerfile b/tasks/construct-rg-graph-color-l2-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-graph-color-l2-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rg-graph-color-l2-s6/environment/instance.json b/tasks/construct-rg-graph-color-l2-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ba9d57a8a0607988b46f6470dc96d393ad66fb3b --- /dev/null +++ b/tasks/construct-rg-graph-color-l2-s6/environment/instance.json @@ -0,0 +1 @@ +{"num_vertices": 10, "num_colors": 4, "edges": [[0, 6], [1, 4], [1, 5], [1, 9], [2, 8], [2, 9], [4, 5], [4, 6], [4, 7], [5, 6], [6, 7], [7, 8]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l2-s6/solution/solve.sh b/tasks/construct-rg-graph-color-l2-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2d1628a4e97e3616cefb7c640d0b980f3383e62c --- /dev/null +++ b/tasks/construct-rg-graph-color-l2-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [1, 1, 1, 1, 2, 3, 4, 1, 2, 2]} +RLMATH_EOF diff --git a/tasks/construct-rg-graph-color-l2-s6/tests/check.py b/tasks/construct-rg-graph-color-l2-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e9328912405d1c894970c90415be62bf9556ed36 --- /dev/null +++ b/tasks/construct-rg-graph-color-l2-s6/tests/check.py @@ -0,0 +1,13 @@ +"""Proper colouring with colours 1..k (Reasoning Gym graph_color, Apache-2.0). Any valid colouring. +Upstream note: its verifier checks `color in allowed_colors`, so True (== 1) and 1.0 were accepted as +colours, and extra keys were ignored. Here colours must be ints in 1..k, one per vertex.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_vertices"], inst["num_colors"] + c = int_list(ans.get("coloring"), n, 1, k, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"adjacent vertices {u} and {v} share colour {c[u]}") + return None, {} diff --git a/tasks/construct-rg-graph-color-l2-s6/tests/instance.json b/tasks/construct-rg-graph-color-l2-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ba9d57a8a0607988b46f6470dc96d393ad66fb3b --- /dev/null +++ b/tasks/construct-rg-graph-color-l2-s6/tests/instance.json @@ -0,0 +1 @@ +{"num_vertices": 10, "num_colors": 4, "edges": [[0, 6], [1, 4], [1, 5], [1, 9], [2, 8], [2, 9], [4, 5], [4, 6], [4, 7], [5, 6], [6, 7], [7, 8]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l2-s6/tests/run.py b/tasks/construct-rg-graph-color-l2-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-graph-color-l2-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rg-graph-color-l2-s6/tests/test.sh b/tasks/construct-rg-graph-color-l2-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-graph-color-l2-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-graph-color-l2-s8/environment/Dockerfile b/tasks/construct-rg-graph-color-l2-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-graph-color-l2-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rg-graph-color-l2-s8/environment/instance.json b/tasks/construct-rg-graph-color-l2-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e780fef0cc7a921286de3e14f28cf9c4c821f803 --- /dev/null +++ b/tasks/construct-rg-graph-color-l2-s8/environment/instance.json @@ -0,0 +1 @@ +{"num_vertices": 10, "num_colors": 4, "edges": [[0, 1], [0, 2], [0, 4], [0, 6], [1, 2], [1, 6], [1, 9], [2, 7], [3, 4], [3, 6], [3, 7], [4, 6], [6, 7], [6, 9]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l2-s8/solution/solve.sh b/tasks/construct-rg-graph-color-l2-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4a8581682bb55be07d87b7afc2ef9632394c64c5 --- /dev/null +++ b/tasks/construct-rg-graph-color-l2-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [1, 2, 3, 1, 2, 1, 3, 2, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-rg-graph-color-l2-s8/tests/check.py b/tasks/construct-rg-graph-color-l2-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e9328912405d1c894970c90415be62bf9556ed36 --- /dev/null +++ b/tasks/construct-rg-graph-color-l2-s8/tests/check.py @@ -0,0 +1,13 @@ +"""Proper colouring with colours 1..k (Reasoning Gym graph_color, Apache-2.0). Any valid colouring. +Upstream note: its verifier checks `color in allowed_colors`, so True (== 1) and 1.0 were accepted as +colours, and extra keys were ignored. Here colours must be ints in 1..k, one per vertex.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_vertices"], inst["num_colors"] + c = int_list(ans.get("coloring"), n, 1, k, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"adjacent vertices {u} and {v} share colour {c[u]}") + return None, {} diff --git a/tasks/construct-rg-graph-color-l2-s8/tests/instance.json b/tasks/construct-rg-graph-color-l2-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e780fef0cc7a921286de3e14f28cf9c4c821f803 --- /dev/null +++ b/tasks/construct-rg-graph-color-l2-s8/tests/instance.json @@ -0,0 +1 @@ +{"num_vertices": 10, "num_colors": 4, "edges": [[0, 1], [0, 2], [0, 4], [0, 6], [1, 2], [1, 6], [1, 9], [2, 7], [3, 4], [3, 6], [3, 7], [4, 6], [6, 7], [6, 9]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l2-s8/tests/run.py b/tasks/construct-rg-graph-color-l2-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-graph-color-l2-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rg-graph-color-l2-s8/tests/test.sh b/tasks/construct-rg-graph-color-l2-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-graph-color-l2-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-graph-color-l6-s0/environment/Dockerfile b/tasks/construct-rg-graph-color-l6-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-graph-color-l6-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rg-graph-color-l6-s0/environment/instance.json b/tasks/construct-rg-graph-color-l6-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a02298066304c7814045b66274d88ca3b6ba7dae --- /dev/null +++ b/tasks/construct-rg-graph-color-l6-s0/environment/instance.json @@ -0,0 +1 @@ +{"num_vertices": 40, "num_colors": 3, "edges": [[0, 1], [0, 11], [0, 18], [0, 33], [1, 6], [1, 15], [1, 27], [1, 31], [1, 37], [2, 11], [2, 26], [2, 28], [2, 31], [3, 8], [3, 11], [3, 12], [3, 14], [3, 16], [3, 32], [3, 36], [3, 38], [4, 10], [4, 20], [4, 27], [4, 32], [4, 38], [4, 39], [5, 18], [5, 31], [5, 38], [6, 9], [6, 10], [6, 13], [6, 23], [6, 33], [7, 13], [7, 19], [7, 28], [7, 39], [8, 14], [8, 22], [8, 23], [8, 33], [8, 37], [8, 39], [9, 10], [9, 22], [9, 30], [9, 33], [10, 26], [11, 13], [11, 22], [12, 13], [12, 21], [12, 24], [12, 29], [13, 18], [13, 20], [13, 29], [13, 30], [13, 36], [15, 17], [18, 25], [18, 31], [19, 22], [19, 24], [19, 38], [20, 23], [20, 27], [20, 30], [20, 38], [21, 31], [21, 35], [22, 31], [22, 33], [23, 26], [23, 34], [23, 35], [26, 34], [27, 36], [28, 30], [28, 38], [29, 35], [29, 39], [30, 32], [30, 35], [33, 36], [34, 35]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l6-s0/solution/solve.sh b/tasks/construct-rg-graph-color-l6-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d8d5176273193530f85118abc589f03181ab7d94 --- /dev/null +++ b/tasks/construct-rg-graph-color-l6-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [1, 2, 1, 1, 1, 1, 1, 1, 2, 2, 3, 2, 2, 3, 3, 1, 2, 2, 2, 2, 2, 1, 1, 3, 1, 1, 2, 3, 2, 1, 1, 3, 2, 3, 1, 2, 2, 1, 3, 3]} +RLMATH_EOF diff --git a/tasks/construct-rg-graph-color-l6-s0/tests/check.py b/tasks/construct-rg-graph-color-l6-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e9328912405d1c894970c90415be62bf9556ed36 --- /dev/null +++ b/tasks/construct-rg-graph-color-l6-s0/tests/check.py @@ -0,0 +1,13 @@ +"""Proper colouring with colours 1..k (Reasoning Gym graph_color, Apache-2.0). Any valid colouring. +Upstream note: its verifier checks `color in allowed_colors`, so True (== 1) and 1.0 were accepted as +colours, and extra keys were ignored. Here colours must be ints in 1..k, one per vertex.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_vertices"], inst["num_colors"] + c = int_list(ans.get("coloring"), n, 1, k, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"adjacent vertices {u} and {v} share colour {c[u]}") + return None, {} diff --git a/tasks/construct-rg-graph-color-l6-s0/tests/instance.json b/tasks/construct-rg-graph-color-l6-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a02298066304c7814045b66274d88ca3b6ba7dae --- /dev/null +++ b/tasks/construct-rg-graph-color-l6-s0/tests/instance.json @@ -0,0 +1 @@ +{"num_vertices": 40, "num_colors": 3, "edges": [[0, 1], [0, 11], [0, 18], [0, 33], [1, 6], [1, 15], [1, 27], [1, 31], [1, 37], [2, 11], [2, 26], [2, 28], [2, 31], [3, 8], [3, 11], [3, 12], [3, 14], [3, 16], [3, 32], [3, 36], [3, 38], [4, 10], [4, 20], [4, 27], [4, 32], [4, 38], [4, 39], [5, 18], [5, 31], [5, 38], [6, 9], [6, 10], [6, 13], [6, 23], [6, 33], [7, 13], [7, 19], [7, 28], [7, 39], [8, 14], [8, 22], [8, 23], [8, 33], [8, 37], [8, 39], [9, 10], [9, 22], [9, 30], [9, 33], [10, 26], [11, 13], [11, 22], [12, 13], [12, 21], [12, 24], [12, 29], [13, 18], [13, 20], [13, 29], [13, 30], [13, 36], [15, 17], [18, 25], [18, 31], [19, 22], [19, 24], [19, 38], [20, 23], [20, 27], [20, 30], [20, 38], [21, 31], [21, 35], [22, 31], [22, 33], [23, 26], [23, 34], [23, 35], [26, 34], [27, 36], [28, 30], [28, 38], [29, 35], [29, 39], [30, 32], [30, 35], [33, 36], [34, 35]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l6-s0/tests/run.py b/tasks/construct-rg-graph-color-l6-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-graph-color-l6-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rg-graph-color-l6-s0/tests/test.sh b/tasks/construct-rg-graph-color-l6-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-graph-color-l6-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-graph-color-l6-s7/environment/Dockerfile b/tasks/construct-rg-graph-color-l6-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-graph-color-l6-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rg-graph-color-l6-s7/environment/instance.json b/tasks/construct-rg-graph-color-l6-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3030356f0c36e4d16111430b63ef69710f1c53e4 --- /dev/null +++ b/tasks/construct-rg-graph-color-l6-s7/environment/instance.json @@ -0,0 +1 @@ +{"num_vertices": 40, "num_colors": 3, "edges": [[0, 4], [0, 5], [0, 7], [0, 10], [0, 18], [0, 23], [0, 31], [1, 39], [2, 18], [2, 37], [3, 14], [3, 22], [3, 25], [3, 32], [4, 23], [4, 25], [4, 28], [4, 35], [4, 36], [4, 37], [4, 39], [5, 7], [6, 16], [6, 30], [6, 36], [6, 38], [7, 12], [7, 18], [7, 19], [7, 21], [7, 22], [8, 20], [8, 27], [9, 32], [9, 37], [9, 39], [10, 29], [10, 39], [11, 17], [11, 19], [11, 24], [12, 19], [12, 22], [12, 24], [12, 28], [13, 20], [13, 23], [13, 39], [14, 15], [14, 37], [15, 18], [16, 36], [17, 29], [17, 30], [18, 21], [18, 39], [20, 21], [20, 27], [20, 35], [21, 22], [21, 24], [21, 30], [21, 37], [22, 23], [22, 30], [23, 26], [24, 30], [24, 34], [27, 29], [28, 31], [28, 33], [29, 31], [30, 32], [32, 35], [32, 36], [32, 37], [33, 36], [33, 37], [35, 36]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l6-s7/solution/solve.sh b/tasks/construct-rg-graph-color-l6-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..86013ec66d749cbcfd585571a41766733229a75b --- /dev/null +++ b/tasks/construct-rg-graph-color-l6-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [1, 1, 1, 1, 2, 2, 1, 3, 1, 1, 2, 1, 1, 1, 2, 1, 2, 2, 2, 2, 2, 1, 2, 3, 2, 3, 1, 3, 3, 1, 3, 2, 2, 1, 1, 1, 3, 3, 2, 3]} +RLMATH_EOF diff --git a/tasks/construct-rg-graph-color-l6-s7/tests/check.py b/tasks/construct-rg-graph-color-l6-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e9328912405d1c894970c90415be62bf9556ed36 --- /dev/null +++ b/tasks/construct-rg-graph-color-l6-s7/tests/check.py @@ -0,0 +1,13 @@ +"""Proper colouring with colours 1..k (Reasoning Gym graph_color, Apache-2.0). Any valid colouring. +Upstream note: its verifier checks `color in allowed_colors`, so True (== 1) and 1.0 were accepted as +colours, and extra keys were ignored. Here colours must be ints in 1..k, one per vertex.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_vertices"], inst["num_colors"] + c = int_list(ans.get("coloring"), n, 1, k, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"adjacent vertices {u} and {v} share colour {c[u]}") + return None, {} diff --git a/tasks/construct-rg-graph-color-l6-s7/tests/instance.json b/tasks/construct-rg-graph-color-l6-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3030356f0c36e4d16111430b63ef69710f1c53e4 --- /dev/null +++ b/tasks/construct-rg-graph-color-l6-s7/tests/instance.json @@ -0,0 +1 @@ +{"num_vertices": 40, "num_colors": 3, "edges": [[0, 4], [0, 5], [0, 7], [0, 10], [0, 18], [0, 23], [0, 31], [1, 39], [2, 18], [2, 37], [3, 14], [3, 22], [3, 25], [3, 32], [4, 23], [4, 25], [4, 28], [4, 35], [4, 36], [4, 37], [4, 39], [5, 7], [6, 16], [6, 30], [6, 36], [6, 38], [7, 12], [7, 18], [7, 19], [7, 21], [7, 22], [8, 20], [8, 27], [9, 32], [9, 37], [9, 39], [10, 29], [10, 39], [11, 17], [11, 19], [11, 24], [12, 19], [12, 22], [12, 24], [12, 28], [13, 20], [13, 23], [13, 39], [14, 15], [14, 37], [15, 18], [16, 36], [17, 29], [17, 30], [18, 21], [18, 39], [20, 21], [20, 27], [20, 35], [21, 22], [21, 24], [21, 30], [21, 37], [22, 23], [22, 30], [23, 26], [24, 30], [24, 34], [27, 29], [28, 31], [28, 33], [29, 31], [30, 32], [32, 35], [32, 36], [32, 37], [33, 36], [33, 37], [35, 36]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l6-s7/tests/run.py b/tasks/construct-rg-graph-color-l6-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-graph-color-l6-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rg-graph-color-l6-s7/tests/test.sh b/tasks/construct-rg-graph-color-l6-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-graph-color-l6-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-intermediate-integration-l4-s2/environment/Dockerfile b/tasks/construct-rg-intermediate-integration-l4-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l4-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rg-intermediate-integration-l4-s2/environment/instance.json b/tasks/construct-rg-intermediate-integration-l4-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fc9a877c647a303bf5abaf66265402096e7ab3cd --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l4-s2/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "-2*atan(2*x)", "problem_type": "log_inverse_trig", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l4-s2/solution/solve.sh b/tasks/construct-rg-intermediate-integration-l4-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..72db3bcb17e891799fd7f3579ba3b3e164e0de2e --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l4-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"antiderivative": "-2*x*atan(2*x) + log(4*x**2 + 1)/2 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-intermediate-integration-l4-s2/tests/check.py b/tasks/construct-rg-intermediate-integration-l4-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l4-s2/tests/check.py @@ -0,0 +1,158 @@ +"""Antiderivative check (Reasoning Gym simple_integration / intermediate_integration, Apache-2.0). + +The answer string is parsed with a whitelist AST walker (no eval), differentiated with SymPy and compared +with the integrand numerically (30-digit evaluation) at fixed points inside the integrand's real domain. +Any additive constant (e.g. "+ C") is allowed. + +Upstream notes: upstream scores with sympy.parse_expr, which calls eval() on the model's string (arbitrary +code execution), and it accepts an unevaluated "Integral(f, x)" since its derivative is f. Both are +rejected here: only arithmetic, whitelisted elementary functions, the variable, C, E and pi are allowed.""" +import ast +import math +import signal + +import sympy + +from run import Invalid + +MAX_LEN = 3000 +MAX_NODES = 600 +MAX_POW_NEST = 4 # nested powers with a variable exponent (x**x**x**...) blow up differentiation +TIME_LIMIT = 40 # seconds; a slower answer is rejected +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "cot": sympy.cot, "sec": sympy.sec, + "csc": sympy.csc, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "acot": sympy.acot, + "arcsin": sympy.asin, "arccos": sympy.acos, "arctan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "asinh": sympy.asinh, "acosh": sympy.acosh, + "atanh": sympy.atanh, "exp": sympy.exp, "log": sympy.log, "ln": sympy.log, "sqrt": sympy.sqrt, + "Abs": sympy.Abs, "abs": sympy.Abs} +POINTS = [0.3137, 0.5521, 0.8093, 1.1171, 1.4519, 1.9033, 2.3471, 2.8123, 3.3319, 3.9107, 4.6231, + -0.3547, -0.6529, -0.9511, -1.3027, -1.7519, -2.2013, -2.7131, -3.1397, -3.8203, -4.4111, + 0.1231, -0.1523, 0.2129, -0.2617, 0.0517, -0.0719, 5.4127, -5.3311, 6.3019, -6.2203, 7.2213, + -7.1117, 8.9021, -9.3107, 10.7129, -10.6337, 12.9011, -12.8231, 15.3113, -15.2719] +MIN_POINTS = 5 + + +def parse(s, var): + if not isinstance(s, str) or not s.strip(): + raise Invalid("antiderivative must be a non-empty string") + if len(s) > MAX_LEN: + raise Invalid("expression too long") + s = s.strip() + try: + tree = ast.parse(s, mode="eval") + except SyntaxError: + raise Invalid("expression does not parse (use ** for powers and * for products)") + if sum(1 for _ in ast.walk(tree)) > MAX_NODES: + raise Invalid("expression too large") + + def pow_nest(nd): + kids = [pow_nest(c) for c in ast.iter_child_nodes(nd)] + own = isinstance(nd, ast.BinOp) and isinstance(nd.op, ast.Pow) and any( + isinstance(c, ast.Name) and c.id == var for c in ast.walk(nd.right)) + return max(kids, default=0) + (1 if own else 0) + if pow_nest(tree) > MAX_POW_NEST: + raise Invalid("too many nested powers with a variable exponent") + x = sympy.Symbol(var, real=True) + names = {var: x, "C": sympy.Symbol("C"), "E": sympy.E, "pi": sympy.pi} + + def conv(nd): + if isinstance(nd, ast.Expression): + return conv(nd.body) + if isinstance(nd, ast.Constant): + v = nd.value + if isinstance(v, bool) or not isinstance(v, (int, float)): + raise Invalid(f"constant {v!r} not allowed") + if isinstance(v, int): + if abs(v) > 10 ** 18: + raise Invalid("integer constant too large") + return sympy.Integer(v) + if not math.isfinite(v): + raise Invalid("non-finite constant") + return sympy.Float(v, 30) + if isinstance(nd, ast.Name): + if nd.id not in names: + raise Invalid(f"unknown name {nd.id!r} (the variable is {var})") + return names[nd.id] + if isinstance(nd, ast.UnaryOp) and isinstance(nd.op, (ast.USub, ast.UAdd)): + a = conv(nd.operand) + return -a if isinstance(nd.op, ast.USub) else a + if isinstance(nd, ast.BinOp): + a, b = conv(nd.left), conv(nd.right) + if isinstance(nd.op, ast.Add): + return a + b + if isinstance(nd.op, ast.Sub): + return a - b + if isinstance(nd.op, ast.Mult): + return a * b + if isinstance(nd.op, ast.Div): + if b == 0: + raise Invalid("division by zero") + return a / b + if isinstance(nd.op, ast.Pow): + if not b.free_symbols: + bv = complex(b.evalf(20)) + if bv.imag != 0 or abs(bv.real) > 100: + raise Invalid("exponent too large") + if not a.free_symbols and abs(complex(a.evalf(20))) > 1e6: + raise Invalid("numeric power too large") + return a ** b + raise Invalid("only + - * / ** are allowed (use ** for powers)") + if isinstance(nd, ast.Call): + if not isinstance(nd.func, ast.Name) or nd.func.id not in FUNCS: + raise Invalid(f"function {ast.unparse(nd.func)!r} not allowed") + if nd.keywords or len(nd.args) != 1: + raise Invalid(f"{nd.func.id} takes exactly one argument") + return FUNCS[nd.func.id](conv(nd.args[0])) + raise Invalid(f"syntax element {type(nd).__name__} not allowed") + + return conv(tree), x + + +def value(expr, x, p): + v = expr.evalf(30, subs={x: sympy.Float(p, 30)}) + try: + z = complex(v) + except (TypeError, ValueError): + return None + if not (math.isfinite(z.real) and math.isfinite(z.imag)): + return None + return z + + +def _timeout(signum, frame): + raise Invalid(f"answer took more than {TIME_LIMIT} s to check") + + +def check(inst, ans): + if hasattr(signal, "SIGALRM"): + old = signal.signal(signal.SIGALRM, _timeout) + signal.alarm(TIME_LIMIT) + try: + return _check(inst, ans) + finally: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + return _check(inst, ans) + + +def _check(inst, ans): + var = inst["variable"] + F, x = parse(ans.get("antiderivative"), var) + f, x2 = parse(inst["integrand"], var) + if not F.has(x): + raise Invalid("antiderivative does not depend on the variable") + dF = sympy.diff(F, x) + used = 0 + for p in POINTS: + fv = value(f, x2, p) + if fv is None or abs(fv.imag) > 1e-20 * (1 + abs(fv.real)): + continue # outside the integrand's real domain + gv = value(dF, x, p) + if gv is None: + raise Invalid(f"derivative of the answer cannot be evaluated at {var} = {p}") + if abs(gv - fv) > 1e-9 * max(1.0, abs(fv)): + raise Invalid(f"derivative of the answer differs from the integrand at {var} = {p}") + used += 1 + if used < MIN_POINTS: + raise Invalid("too few evaluation points in the integrand's domain") + return None, {"points": used} diff --git a/tasks/construct-rg-intermediate-integration-l4-s2/tests/instance.json b/tasks/construct-rg-intermediate-integration-l4-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fc9a877c647a303bf5abaf66265402096e7ab3cd --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l4-s2/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "-2*atan(2*x)", "problem_type": "log_inverse_trig", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l4-s2/tests/run.py b/tasks/construct-rg-intermediate-integration-l4-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l4-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rg-intermediate-integration-l4-s2/tests/test.sh b/tasks/construct-rg-intermediate-integration-l4-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l4-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-simple-integration-l2-s9/environment/Dockerfile b/tasks/construct-rg-simple-integration-l2-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l2-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rg-simple-integration-l2-s9/environment/instance.json b/tasks/construct-rg-simple-integration-l2-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bb0356aa3d6e6ceffa7ec4395000b53304b97141 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l2-s9/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "20*x**4 + 36*x**3 + 2/3", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l2-s9/solution/solve.sh b/tasks/construct-rg-simple-integration-l2-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2d1540cef09e23912e6778e38e395ee71172c2c --- /dev/null +++ b/tasks/construct-rg-simple-integration-l2-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"antiderivative": "4*x**5 + 9*x**4 + 2*x/3 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-simple-integration-l2-s9/tests/check.py b/tasks/construct-rg-simple-integration-l2-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l2-s9/tests/check.py @@ -0,0 +1,158 @@ +"""Antiderivative check (Reasoning Gym simple_integration / intermediate_integration, Apache-2.0). + +The answer string is parsed with a whitelist AST walker (no eval), differentiated with SymPy and compared +with the integrand numerically (30-digit evaluation) at fixed points inside the integrand's real domain. +Any additive constant (e.g. "+ C") is allowed. + +Upstream notes: upstream scores with sympy.parse_expr, which calls eval() on the model's string (arbitrary +code execution), and it accepts an unevaluated "Integral(f, x)" since its derivative is f. Both are +rejected here: only arithmetic, whitelisted elementary functions, the variable, C, E and pi are allowed.""" +import ast +import math +import signal + +import sympy + +from run import Invalid + +MAX_LEN = 3000 +MAX_NODES = 600 +MAX_POW_NEST = 4 # nested powers with a variable exponent (x**x**x**...) blow up differentiation +TIME_LIMIT = 40 # seconds; a slower answer is rejected +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "cot": sympy.cot, "sec": sympy.sec, + "csc": sympy.csc, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "acot": sympy.acot, + "arcsin": sympy.asin, "arccos": sympy.acos, "arctan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "asinh": sympy.asinh, "acosh": sympy.acosh, + "atanh": sympy.atanh, "exp": sympy.exp, "log": sympy.log, "ln": sympy.log, "sqrt": sympy.sqrt, + "Abs": sympy.Abs, "abs": sympy.Abs} +POINTS = [0.3137, 0.5521, 0.8093, 1.1171, 1.4519, 1.9033, 2.3471, 2.8123, 3.3319, 3.9107, 4.6231, + -0.3547, -0.6529, -0.9511, -1.3027, -1.7519, -2.2013, -2.7131, -3.1397, -3.8203, -4.4111, + 0.1231, -0.1523, 0.2129, -0.2617, 0.0517, -0.0719, 5.4127, -5.3311, 6.3019, -6.2203, 7.2213, + -7.1117, 8.9021, -9.3107, 10.7129, -10.6337, 12.9011, -12.8231, 15.3113, -15.2719] +MIN_POINTS = 5 + + +def parse(s, var): + if not isinstance(s, str) or not s.strip(): + raise Invalid("antiderivative must be a non-empty string") + if len(s) > MAX_LEN: + raise Invalid("expression too long") + s = s.strip() + try: + tree = ast.parse(s, mode="eval") + except SyntaxError: + raise Invalid("expression does not parse (use ** for powers and * for products)") + if sum(1 for _ in ast.walk(tree)) > MAX_NODES: + raise Invalid("expression too large") + + def pow_nest(nd): + kids = [pow_nest(c) for c in ast.iter_child_nodes(nd)] + own = isinstance(nd, ast.BinOp) and isinstance(nd.op, ast.Pow) and any( + isinstance(c, ast.Name) and c.id == var for c in ast.walk(nd.right)) + return max(kids, default=0) + (1 if own else 0) + if pow_nest(tree) > MAX_POW_NEST: + raise Invalid("too many nested powers with a variable exponent") + x = sympy.Symbol(var, real=True) + names = {var: x, "C": sympy.Symbol("C"), "E": sympy.E, "pi": sympy.pi} + + def conv(nd): + if isinstance(nd, ast.Expression): + return conv(nd.body) + if isinstance(nd, ast.Constant): + v = nd.value + if isinstance(v, bool) or not isinstance(v, (int, float)): + raise Invalid(f"constant {v!r} not allowed") + if isinstance(v, int): + if abs(v) > 10 ** 18: + raise Invalid("integer constant too large") + return sympy.Integer(v) + if not math.isfinite(v): + raise Invalid("non-finite constant") + return sympy.Float(v, 30) + if isinstance(nd, ast.Name): + if nd.id not in names: + raise Invalid(f"unknown name {nd.id!r} (the variable is {var})") + return names[nd.id] + if isinstance(nd, ast.UnaryOp) and isinstance(nd.op, (ast.USub, ast.UAdd)): + a = conv(nd.operand) + return -a if isinstance(nd.op, ast.USub) else a + if isinstance(nd, ast.BinOp): + a, b = conv(nd.left), conv(nd.right) + if isinstance(nd.op, ast.Add): + return a + b + if isinstance(nd.op, ast.Sub): + return a - b + if isinstance(nd.op, ast.Mult): + return a * b + if isinstance(nd.op, ast.Div): + if b == 0: + raise Invalid("division by zero") + return a / b + if isinstance(nd.op, ast.Pow): + if not b.free_symbols: + bv = complex(b.evalf(20)) + if bv.imag != 0 or abs(bv.real) > 100: + raise Invalid("exponent too large") + if not a.free_symbols and abs(complex(a.evalf(20))) > 1e6: + raise Invalid("numeric power too large") + return a ** b + raise Invalid("only + - * / ** are allowed (use ** for powers)") + if isinstance(nd, ast.Call): + if not isinstance(nd.func, ast.Name) or nd.func.id not in FUNCS: + raise Invalid(f"function {ast.unparse(nd.func)!r} not allowed") + if nd.keywords or len(nd.args) != 1: + raise Invalid(f"{nd.func.id} takes exactly one argument") + return FUNCS[nd.func.id](conv(nd.args[0])) + raise Invalid(f"syntax element {type(nd).__name__} not allowed") + + return conv(tree), x + + +def value(expr, x, p): + v = expr.evalf(30, subs={x: sympy.Float(p, 30)}) + try: + z = complex(v) + except (TypeError, ValueError): + return None + if not (math.isfinite(z.real) and math.isfinite(z.imag)): + return None + return z + + +def _timeout(signum, frame): + raise Invalid(f"answer took more than {TIME_LIMIT} s to check") + + +def check(inst, ans): + if hasattr(signal, "SIGALRM"): + old = signal.signal(signal.SIGALRM, _timeout) + signal.alarm(TIME_LIMIT) + try: + return _check(inst, ans) + finally: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + return _check(inst, ans) + + +def _check(inst, ans): + var = inst["variable"] + F, x = parse(ans.get("antiderivative"), var) + f, x2 = parse(inst["integrand"], var) + if not F.has(x): + raise Invalid("antiderivative does not depend on the variable") + dF = sympy.diff(F, x) + used = 0 + for p in POINTS: + fv = value(f, x2, p) + if fv is None or abs(fv.imag) > 1e-20 * (1 + abs(fv.real)): + continue # outside the integrand's real domain + gv = value(dF, x, p) + if gv is None: + raise Invalid(f"derivative of the answer cannot be evaluated at {var} = {p}") + if abs(gv - fv) > 1e-9 * max(1.0, abs(fv)): + raise Invalid(f"derivative of the answer differs from the integrand at {var} = {p}") + used += 1 + if used < MIN_POINTS: + raise Invalid("too few evaluation points in the integrand's domain") + return None, {"points": used} diff --git a/tasks/construct-rg-simple-integration-l2-s9/tests/instance.json b/tasks/construct-rg-simple-integration-l2-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bb0356aa3d6e6ceffa7ec4395000b53304b97141 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l2-s9/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "20*x**4 + 36*x**3 + 2/3", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l2-s9/tests/run.py b/tasks/construct-rg-simple-integration-l2-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-simple-integration-l2-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rg-simple-integration-l2-s9/tests/test.sh b/tasks/construct-rg-simple-integration-l2-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l2-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-simple-integration-l6-s1/environment/Dockerfile b/tasks/construct-rg-simple-integration-l6-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l6-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rg-simple-integration-l6-s1/environment/instance.json b/tasks/construct-rg-simple-integration-l6-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6053a6b3f11724a8fea07dc96f46e5f539e4116d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l6-s1/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "-16*x**7/5 + 5/(3*x**2) - 4/x**3 + 2/x**5 + 60/x**7 + 20/x**11", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l6-s1/solution/solve.sh b/tasks/construct-rg-simple-integration-l6-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1d113f04495b8b3acb4b56ea00ed90e38b71bdc5 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l6-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"antiderivative": "-2*x**8/5 - 1/5 - 5/(3*x) + 2/x**2 - 1/(2*x**4) - 10/x**6 - 2/x**10 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-simple-integration-l6-s1/tests/check.py b/tasks/construct-rg-simple-integration-l6-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l6-s1/tests/check.py @@ -0,0 +1,158 @@ +"""Antiderivative check (Reasoning Gym simple_integration / intermediate_integration, Apache-2.0). + +The answer string is parsed with a whitelist AST walker (no eval), differentiated with SymPy and compared +with the integrand numerically (30-digit evaluation) at fixed points inside the integrand's real domain. +Any additive constant (e.g. "+ C") is allowed. + +Upstream notes: upstream scores with sympy.parse_expr, which calls eval() on the model's string (arbitrary +code execution), and it accepts an unevaluated "Integral(f, x)" since its derivative is f. Both are +rejected here: only arithmetic, whitelisted elementary functions, the variable, C, E and pi are allowed.""" +import ast +import math +import signal + +import sympy + +from run import Invalid + +MAX_LEN = 3000 +MAX_NODES = 600 +MAX_POW_NEST = 4 # nested powers with a variable exponent (x**x**x**...) blow up differentiation +TIME_LIMIT = 40 # seconds; a slower answer is rejected +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "cot": sympy.cot, "sec": sympy.sec, + "csc": sympy.csc, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "acot": sympy.acot, + "arcsin": sympy.asin, "arccos": sympy.acos, "arctan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "asinh": sympy.asinh, "acosh": sympy.acosh, + "atanh": sympy.atanh, "exp": sympy.exp, "log": sympy.log, "ln": sympy.log, "sqrt": sympy.sqrt, + "Abs": sympy.Abs, "abs": sympy.Abs} +POINTS = [0.3137, 0.5521, 0.8093, 1.1171, 1.4519, 1.9033, 2.3471, 2.8123, 3.3319, 3.9107, 4.6231, + -0.3547, -0.6529, -0.9511, -1.3027, -1.7519, -2.2013, -2.7131, -3.1397, -3.8203, -4.4111, + 0.1231, -0.1523, 0.2129, -0.2617, 0.0517, -0.0719, 5.4127, -5.3311, 6.3019, -6.2203, 7.2213, + -7.1117, 8.9021, -9.3107, 10.7129, -10.6337, 12.9011, -12.8231, 15.3113, -15.2719] +MIN_POINTS = 5 + + +def parse(s, var): + if not isinstance(s, str) or not s.strip(): + raise Invalid("antiderivative must be a non-empty string") + if len(s) > MAX_LEN: + raise Invalid("expression too long") + s = s.strip() + try: + tree = ast.parse(s, mode="eval") + except SyntaxError: + raise Invalid("expression does not parse (use ** for powers and * for products)") + if sum(1 for _ in ast.walk(tree)) > MAX_NODES: + raise Invalid("expression too large") + + def pow_nest(nd): + kids = [pow_nest(c) for c in ast.iter_child_nodes(nd)] + own = isinstance(nd, ast.BinOp) and isinstance(nd.op, ast.Pow) and any( + isinstance(c, ast.Name) and c.id == var for c in ast.walk(nd.right)) + return max(kids, default=0) + (1 if own else 0) + if pow_nest(tree) > MAX_POW_NEST: + raise Invalid("too many nested powers with a variable exponent") + x = sympy.Symbol(var, real=True) + names = {var: x, "C": sympy.Symbol("C"), "E": sympy.E, "pi": sympy.pi} + + def conv(nd): + if isinstance(nd, ast.Expression): + return conv(nd.body) + if isinstance(nd, ast.Constant): + v = nd.value + if isinstance(v, bool) or not isinstance(v, (int, float)): + raise Invalid(f"constant {v!r} not allowed") + if isinstance(v, int): + if abs(v) > 10 ** 18: + raise Invalid("integer constant too large") + return sympy.Integer(v) + if not math.isfinite(v): + raise Invalid("non-finite constant") + return sympy.Float(v, 30) + if isinstance(nd, ast.Name): + if nd.id not in names: + raise Invalid(f"unknown name {nd.id!r} (the variable is {var})") + return names[nd.id] + if isinstance(nd, ast.UnaryOp) and isinstance(nd.op, (ast.USub, ast.UAdd)): + a = conv(nd.operand) + return -a if isinstance(nd.op, ast.USub) else a + if isinstance(nd, ast.BinOp): + a, b = conv(nd.left), conv(nd.right) + if isinstance(nd.op, ast.Add): + return a + b + if isinstance(nd.op, ast.Sub): + return a - b + if isinstance(nd.op, ast.Mult): + return a * b + if isinstance(nd.op, ast.Div): + if b == 0: + raise Invalid("division by zero") + return a / b + if isinstance(nd.op, ast.Pow): + if not b.free_symbols: + bv = complex(b.evalf(20)) + if bv.imag != 0 or abs(bv.real) > 100: + raise Invalid("exponent too large") + if not a.free_symbols and abs(complex(a.evalf(20))) > 1e6: + raise Invalid("numeric power too large") + return a ** b + raise Invalid("only + - * / ** are allowed (use ** for powers)") + if isinstance(nd, ast.Call): + if not isinstance(nd.func, ast.Name) or nd.func.id not in FUNCS: + raise Invalid(f"function {ast.unparse(nd.func)!r} not allowed") + if nd.keywords or len(nd.args) != 1: + raise Invalid(f"{nd.func.id} takes exactly one argument") + return FUNCS[nd.func.id](conv(nd.args[0])) + raise Invalid(f"syntax element {type(nd).__name__} not allowed") + + return conv(tree), x + + +def value(expr, x, p): + v = expr.evalf(30, subs={x: sympy.Float(p, 30)}) + try: + z = complex(v) + except (TypeError, ValueError): + return None + if not (math.isfinite(z.real) and math.isfinite(z.imag)): + return None + return z + + +def _timeout(signum, frame): + raise Invalid(f"answer took more than {TIME_LIMIT} s to check") + + +def check(inst, ans): + if hasattr(signal, "SIGALRM"): + old = signal.signal(signal.SIGALRM, _timeout) + signal.alarm(TIME_LIMIT) + try: + return _check(inst, ans) + finally: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + return _check(inst, ans) + + +def _check(inst, ans): + var = inst["variable"] + F, x = parse(ans.get("antiderivative"), var) + f, x2 = parse(inst["integrand"], var) + if not F.has(x): + raise Invalid("antiderivative does not depend on the variable") + dF = sympy.diff(F, x) + used = 0 + for p in POINTS: + fv = value(f, x2, p) + if fv is None or abs(fv.imag) > 1e-20 * (1 + abs(fv.real)): + continue # outside the integrand's real domain + gv = value(dF, x, p) + if gv is None: + raise Invalid(f"derivative of the answer cannot be evaluated at {var} = {p}") + if abs(gv - fv) > 1e-9 * max(1.0, abs(fv)): + raise Invalid(f"derivative of the answer differs from the integrand at {var} = {p}") + used += 1 + if used < MIN_POINTS: + raise Invalid("too few evaluation points in the integrand's domain") + return None, {"points": used} diff --git a/tasks/construct-rg-simple-integration-l6-s1/tests/instance.json b/tasks/construct-rg-simple-integration-l6-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6053a6b3f11724a8fea07dc96f46e5f539e4116d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l6-s1/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "-16*x**7/5 + 5/(3*x**2) - 4/x**3 + 2/x**5 + 60/x**7 + 20/x**11", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l6-s1/tests/run.py b/tasks/construct-rg-simple-integration-l6-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-simple-integration-l6-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rg-simple-integration-l6-s1/tests/test.sh b/tasks/construct-rg-simple-integration-l6-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l6-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-antiderivative-l3-s7/environment/Dockerfile b/tasks/construct-rlve-antiderivative-l3-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l3-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-antiderivative-l3-s7/environment/instance.json b/tasks/construct-rlve-antiderivative-l3-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..97565508e48d88c4a537c6f7d188de49c4c91875 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l3-s7/environment/instance.json @@ -0,0 +1 @@ +{"f_prime": "-4*x*sin(2*x**2)*cos(cos(2*x**2))/3", "max_ops": 40, "max_len": 760, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l3-s7/solution/solve.sh b/tasks/construct-rlve-antiderivative-l3-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8019c53549aaf91b70dda8a3c16b0688e081c556 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l3-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"F": "sin(cos(2*x**2))/3"} +RLMATH_EOF diff --git a/tasks/construct-rlve-antiderivative-l3-s7/tests/check.py b/tasks/construct-rlve-antiderivative-l3-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c6b30b93bbbb7795b54d973e43f25b23c82cb7fc --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l3-s7/tests/check.py @@ -0,0 +1,107 @@ +"""Antiderivative check. The answer string is tokenised against a whitelist (x, integers, + - * / ** ( ) and a few +elementary functions) before sympy parses it, so no Python eval of untrusted text and no `integrate`/`Integral`.""" +import re +import signal + +import sympy +from sympy.parsing.sympy_parser import auto_number, parse_expr + +from run import Invalid + +x = sympy.Symbol("x") +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "exp": sympy.exp, "log": sympy.log, + "sqrt": sympy.sqrt, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "E": sympy.E, "pi": sympy.pi, "x": x} +TOK = re.compile(r"\s*(?:(\d+)|([A-Za-z]+)|(\*\*|[-+*/()]))") +NPTS = 40 + + +def safe_parse(s, max_len): + if not isinstance(s, str) or not s.strip(): + raise Invalid("F must be a non-empty string") + if len(s) > max_len: + raise Invalid("expression too long") + pos = 0 + while pos < len(s): + m = TOK.match(s, pos) + if not m or m.end() == pos: + if s[pos:].strip() == "": + break + raise Invalid(f"illegal character near position {pos}") + if m.group(1) and len(m.group(1)) > 12: + raise Invalid("integer literal too long") + if m.group(2) and m.group(2) not in FUNCS: + raise Invalid(f"unknown name {m.group(2)!r}") + pos = m.end() + try: + e = parse_expr(s, local_dict=dict(FUNCS), global_dict={"__builtins__": {}, "Integer": sympy.Integer}, + transformations=(auto_number,)) + except Invalid: + raise + except Exception as ex: + raise Invalid(f"cannot parse F: {type(ex).__name__}") + if not isinstance(e, sympy.Expr): + raise Invalid("F is not an expression") + if e.free_symbols - {x}: + raise Invalid("F may only contain the variable x") + return e + + +def _val(e, pt): + v = e.evalf(40, subs={x: pt}) + if not v.is_number or v.has(sympy.zoo, sympy.nan, sympy.oo, -sympy.oo): + return None + return v + + +class _Timeout(Exception): + pass + + +def _alarm(*_): + raise _Timeout() + + +def check(inst, ans): + old = None + try: + old = signal.signal(signal.SIGALRM, _alarm) + signal.alarm(40) + except ValueError: # not in main thread + old = None + try: + return _check(inst, ans) + except _Timeout: + raise Invalid("evaluation timed out") + except RecursionError: + raise Invalid("expression too deep") + finally: + if old is not None: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + + +def _check(inst, ans): + F = safe_parse(ans.get("F"), inst["max_len"]) + if sympy.count_ops(F) > inst["max_ops"]: + raise Invalid("expression too complex") + if any(isinstance(a, sympy.Rational) and max(abs(a.p), abs(a.q)) > 10 ** 12 for a in F.atoms(sympy.Rational)): + raise Invalid("numeric constants too large") + D = sympy.diff(F, x) + f = sympy.sympify(inst["f_prime"]) # trusted instance data + ok = 0 + for k in range(NPTS): + pt = sympy.Rational(2 * k + 1, NPTS // 2 * 2) * 2 - 2 + sympy.Rational(1, 997) + vf = _val(f, pt) + if vf is None: + continue + vd = _val(D, pt) + if vd is None: + continue + err = sympy.Abs(vd - vf).evalf(40) + if err > sympy.Float("1e-20", 40) * (1 + sympy.Abs(vf).evalf(40)): + raise Invalid(f"F'(x) != f(x) at x = {float(pt):.4f}") + ok += 1 + if ok < NPTS // 4: + raise Invalid("F' could not be compared with f on enough test points") + return None, {"points_checked": ok} diff --git a/tasks/construct-rlve-antiderivative-l3-s7/tests/instance.json b/tasks/construct-rlve-antiderivative-l3-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..97565508e48d88c4a537c6f7d188de49c4c91875 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l3-s7/tests/instance.json @@ -0,0 +1 @@ +{"f_prime": "-4*x*sin(2*x**2)*cos(cos(2*x**2))/3", "max_ops": 40, "max_len": 760, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l3-s7/tests/run.py b/tasks/construct-rlve-antiderivative-l3-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l3-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-antiderivative-l3-s7/tests/test.sh b/tasks/construct-rlve-antiderivative-l3-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l3-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-bezout-identity-l2-s3/environment/Dockerfile b/tasks/construct-rlve-bezout-identity-l2-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l2-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-bezout-identity-l2-s3/environment/instance.json b/tasks/construct-rlve-bezout-identity-l2-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1f6a4baaa71cfb642b4b201f1f381e11abb492df --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l2-s3/environment/instance.json @@ -0,0 +1 @@ +{"A": [128, 46, -70, 96], "target": 2, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l2-s3/solution/solve.sh b/tasks/construct-rlve-bezout-identity-l2-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ed72d92c0d788221f0e4a9216f4216866495344e --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l2-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"X": [9, -25, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-bezout-identity-l2-s3/tests/check.py b/tasks/construct-rlve-bezout-identity-l2-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b4cb860ed36974a12b71adc9a0fa3f1ad85c814a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l2-s3/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + A = inst["A"] + X = int_list(ans.get("X"), len(A), name="X") + S = sum(a * x for a, x in zip(A, X)) + if S != inst["target"]: + raise Invalid(f"S = {S}, required {inst['target']}") + return None, {} diff --git a/tasks/construct-rlve-bezout-identity-l2-s3/tests/instance.json b/tasks/construct-rlve-bezout-identity-l2-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1f6a4baaa71cfb642b4b201f1f381e11abb492df --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l2-s3/tests/instance.json @@ -0,0 +1 @@ +{"A": [128, 46, -70, 96], "target": 2, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l2-s3/tests/run.py b/tasks/construct-rlve-bezout-identity-l2-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l2-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-bezout-identity-l2-s3/tests/test.sh b/tasks/construct-rlve-bezout-identity-l2-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l2-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-bezout-identity-l6-s2/environment/Dockerfile b/tasks/construct-rlve-bezout-identity-l6-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l6-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-bezout-identity-l6-s2/environment/instance.json b/tasks/construct-rlve-bezout-identity-l6-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e1943f47e71573c518073d5a4f025b8727aaaff1 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l6-s2/environment/instance.json @@ -0,0 +1 @@ +{"A": [22225, 9884, -28021, 20027, 6314, -15148, 11403, -22351, -2660, 19040, 13755, -25613], "target": 7, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l6-s2/solution/solve.sh b/tasks/construct-rlve-bezout-identity-l6-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b96198e4d5a4d41d87af118405d3e63802e8392b --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l6-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"X": [-177, 398, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-bezout-identity-l6-s2/tests/check.py b/tasks/construct-rlve-bezout-identity-l6-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b4cb860ed36974a12b71adc9a0fa3f1ad85c814a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l6-s2/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + A = inst["A"] + X = int_list(ans.get("X"), len(A), name="X") + S = sum(a * x for a, x in zip(A, X)) + if S != inst["target"]: + raise Invalid(f"S = {S}, required {inst['target']}") + return None, {} diff --git a/tasks/construct-rlve-bezout-identity-l6-s2/tests/instance.json b/tasks/construct-rlve-bezout-identity-l6-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e1943f47e71573c518073d5a4f025b8727aaaff1 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l6-s2/tests/instance.json @@ -0,0 +1 @@ +{"A": [22225, 9884, -28021, 20027, 6314, -15148, 11403, -22351, -2660, 19040, 13755, -25613], "target": 7, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l6-s2/tests/run.py b/tasks/construct-rlve-bezout-identity-l6-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l6-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-bezout-identity-l6-s2/tests/test.sh b/tasks/construct-rlve-bezout-identity-l6-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l6-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-construct-hack-interval-l4-s1/environment/Dockerfile b/tasks/construct-rlve-construct-hack-interval-l4-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l4-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-construct-hack-interval-l4-s1/environment/instance.json b/tasks/construct-rlve-construct-hack-interval-l4-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7e7d07f8ad24ba0cdce8914f61dca9690ac97039 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l4-s1/environment/instance.json @@ -0,0 +1 @@ +{"mod": 6749972381, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l4-s1/solution/solve.sh b/tasks/construct-rlve-construct-hack-interval-l4-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c1e88fbdca2c36e3a26ee2fdd961e3b129fe157b --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l4-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"L": 6749806667, "R": 7749806666} +RLMATH_EOF diff --git a/tasks/construct-rlve-construct-hack-interval-l4-s1/tests/check.py b/tasks/construct-rlve-construct-hack-interval-l4-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..34b46e9758e3a50ed16c9c2a29cfc0abe663926b --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l4-s1/tests/check.py @@ -0,0 +1,30 @@ +from run import Invalid, as_int + + +def digit_sum_prefix(n): + """sum of digit sums of all integers in [0, n] (exact, digit DP).""" + if n <= 0: + return 0 + s = str(n) + total, prefix_sum = 0, 0 + k = len(s) + for i, ch in enumerate(s): + d = int(ch) + rest = k - i - 1 + p = 10 ** rest + # numbers with this digit < d, free suffix of `rest` digits + total += d * prefix_sum * p + (d * (d - 1) // 2) * p + d * (45 * rest * p // 10 if rest else 0) + prefix_sum += d + return total + prefix_sum # include n itself + + +def check(inst, ans): + mod = inst["mod"] + L = as_int(ans.get("L"), "L", lo=1) + R = as_int(ans.get("R"), "R", lo=1, hi=10 * mod) + if L > R: + raise Invalid("need L <= R") + total = digit_sum_prefix(R) - digit_sum_prefix(L - 1) + if total % mod: + raise Invalid(f"sum of digit sums over [L, R] is {total}, not divisible by {mod}") + return None, {} diff --git a/tasks/construct-rlve-construct-hack-interval-l4-s1/tests/instance.json b/tasks/construct-rlve-construct-hack-interval-l4-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7e7d07f8ad24ba0cdce8914f61dca9690ac97039 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l4-s1/tests/instance.json @@ -0,0 +1 @@ +{"mod": 6749972381, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l4-s1/tests/run.py b/tasks/construct-rlve-construct-hack-interval-l4-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l4-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-construct-hack-interval-l4-s1/tests/test.sh b/tasks/construct-rlve-construct-hack-interval-l4-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l4-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-construct-hack-interval-l4-s6/environment/Dockerfile b/tasks/construct-rlve-construct-hack-interval-l4-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l4-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-construct-hack-interval-l4-s6/environment/instance.json b/tasks/construct-rlve-construct-hack-interval-l4-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c7bcf98d1007059c17de84d8169055cd022eeab9 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l4-s6/environment/instance.json @@ -0,0 +1 @@ +{"mod": 527598588, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l4-s6/solution/solve.sh b/tasks/construct-rlve-construct-hack-interval-l4-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a24c257cebcb5d5ff09cae7f0134ce36293d852f --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l4-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"L": 93190116, "R": 193190115} +RLMATH_EOF diff --git a/tasks/construct-rlve-construct-hack-interval-l4-s6/tests/check.py b/tasks/construct-rlve-construct-hack-interval-l4-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..34b46e9758e3a50ed16c9c2a29cfc0abe663926b --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l4-s6/tests/check.py @@ -0,0 +1,30 @@ +from run import Invalid, as_int + + +def digit_sum_prefix(n): + """sum of digit sums of all integers in [0, n] (exact, digit DP).""" + if n <= 0: + return 0 + s = str(n) + total, prefix_sum = 0, 0 + k = len(s) + for i, ch in enumerate(s): + d = int(ch) + rest = k - i - 1 + p = 10 ** rest + # numbers with this digit < d, free suffix of `rest` digits + total += d * prefix_sum * p + (d * (d - 1) // 2) * p + d * (45 * rest * p // 10 if rest else 0) + prefix_sum += d + return total + prefix_sum # include n itself + + +def check(inst, ans): + mod = inst["mod"] + L = as_int(ans.get("L"), "L", lo=1) + R = as_int(ans.get("R"), "R", lo=1, hi=10 * mod) + if L > R: + raise Invalid("need L <= R") + total = digit_sum_prefix(R) - digit_sum_prefix(L - 1) + if total % mod: + raise Invalid(f"sum of digit sums over [L, R] is {total}, not divisible by {mod}") + return None, {} diff --git a/tasks/construct-rlve-construct-hack-interval-l4-s6/tests/instance.json b/tasks/construct-rlve-construct-hack-interval-l4-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c7bcf98d1007059c17de84d8169055cd022eeab9 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l4-s6/tests/instance.json @@ -0,0 +1 @@ +{"mod": 527598588, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l4-s6/tests/run.py b/tasks/construct-rlve-construct-hack-interval-l4-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l4-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-construct-hack-interval-l4-s6/tests/test.sh b/tasks/construct-rlve-construct-hack-interval-l4-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l4-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-construct-hack-interval-l4-s8/environment/Dockerfile b/tasks/construct-rlve-construct-hack-interval-l4-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l4-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-construct-hack-interval-l4-s8/environment/instance.json b/tasks/construct-rlve-construct-hack-interval-l4-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bea03efc2c365f5785cc2147a14109cbaa69a76e --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l4-s8/environment/instance.json @@ -0,0 +1 @@ +{"mod": 1671726020, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l4-s8/solution/solve.sh b/tasks/construct-rlve-construct-hack-interval-l4-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1dee36df096e282e089d33b7002191f2ba740285 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l4-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"L": 1293150500, "R": 2293150499} +RLMATH_EOF diff --git a/tasks/construct-rlve-construct-hack-interval-l4-s8/tests/check.py b/tasks/construct-rlve-construct-hack-interval-l4-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..34b46e9758e3a50ed16c9c2a29cfc0abe663926b --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l4-s8/tests/check.py @@ -0,0 +1,30 @@ +from run import Invalid, as_int + + +def digit_sum_prefix(n): + """sum of digit sums of all integers in [0, n] (exact, digit DP).""" + if n <= 0: + return 0 + s = str(n) + total, prefix_sum = 0, 0 + k = len(s) + for i, ch in enumerate(s): + d = int(ch) + rest = k - i - 1 + p = 10 ** rest + # numbers with this digit < d, free suffix of `rest` digits + total += d * prefix_sum * p + (d * (d - 1) // 2) * p + d * (45 * rest * p // 10 if rest else 0) + prefix_sum += d + return total + prefix_sum # include n itself + + +def check(inst, ans): + mod = inst["mod"] + L = as_int(ans.get("L"), "L", lo=1) + R = as_int(ans.get("R"), "R", lo=1, hi=10 * mod) + if L > R: + raise Invalid("need L <= R") + total = digit_sum_prefix(R) - digit_sum_prefix(L - 1) + if total % mod: + raise Invalid(f"sum of digit sums over [L, R] is {total}, not divisible by {mod}") + return None, {} diff --git a/tasks/construct-rlve-construct-hack-interval-l4-s8/tests/instance.json b/tasks/construct-rlve-construct-hack-interval-l4-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bea03efc2c365f5785cc2147a14109cbaa69a76e --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l4-s8/tests/instance.json @@ -0,0 +1 @@ +{"mod": 1671726020, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l4-s8/tests/run.py b/tasks/construct-rlve-construct-hack-interval-l4-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l4-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-construct-hack-interval-l4-s8/tests/test.sh b/tasks/construct-rlve-construct-hack-interval-l4-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l4-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-crt-l1-s1/environment/Dockerfile b/tasks/construct-rlve-crt-l1-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-crt-l1-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-crt-l1-s1/environment/instance.json b/tasks/construct-rlve-crt-l1-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..25363b36701ae5dd7aaf2795a36511798e695d59 --- /dev/null +++ b/tasks/construct-rlve-crt-l1-s1/environment/instance.json @@ -0,0 +1 @@ +{"moduli": [5, 7], "residues": [2, 0], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l1-s1/solution/solve.sh b/tasks/construct-rlve-crt-l1-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..bebbc0cbb2b921e5f052f12df7eebf0746ce16fa --- /dev/null +++ b/tasks/construct-rlve-crt-l1-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 7} +RLMATH_EOF diff --git a/tasks/construct-rlve-crt-l1-s1/tests/check.py b/tasks/construct-rlve-crt-l1-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..886d95606ef325930b24794c0959c2ba7b254ebd --- /dev/null +++ b/tasks/construct-rlve-crt-l1-s1/tests/check.py @@ -0,0 +1,11 @@ +from run import Invalid, as_int + + +def check(inst, ans): + x = as_int(ans.get("x"), "x", lo=0) + if x.bit_length() > 20000: + raise Invalid("x is unreasonably large") + for a, b in zip(inst["residues"], inst["moduli"]): + if x % b != a: + raise Invalid(f"x mod {b} = {x % b}, need {a}") + return None, {} diff --git a/tasks/construct-rlve-crt-l1-s1/tests/instance.json b/tasks/construct-rlve-crt-l1-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..25363b36701ae5dd7aaf2795a36511798e695d59 --- /dev/null +++ b/tasks/construct-rlve-crt-l1-s1/tests/instance.json @@ -0,0 +1 @@ +{"moduli": [5, 7], "residues": [2, 0], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l1-s1/tests/run.py b/tasks/construct-rlve-crt-l1-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-crt-l1-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-crt-l1-s1/tests/test.sh b/tasks/construct-rlve-crt-l1-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-crt-l1-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-crt-l1-s6/environment/Dockerfile b/tasks/construct-rlve-crt-l1-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-crt-l1-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-crt-l1-s6/environment/instance.json b/tasks/construct-rlve-crt-l1-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8f17afb3e5f4965ce9ec8e775f7a956b4730ed52 --- /dev/null +++ b/tasks/construct-rlve-crt-l1-s6/environment/instance.json @@ -0,0 +1 @@ +{"moduli": [4, 6], "residues": [2, 0], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l1-s6/solution/solve.sh b/tasks/construct-rlve-crt-l1-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..20023a5e79ceaa154e808fd5d569228080e1a8c7 --- /dev/null +++ b/tasks/construct-rlve-crt-l1-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 6} +RLMATH_EOF diff --git a/tasks/construct-rlve-crt-l1-s6/tests/check.py b/tasks/construct-rlve-crt-l1-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..886d95606ef325930b24794c0959c2ba7b254ebd --- /dev/null +++ b/tasks/construct-rlve-crt-l1-s6/tests/check.py @@ -0,0 +1,11 @@ +from run import Invalid, as_int + + +def check(inst, ans): + x = as_int(ans.get("x"), "x", lo=0) + if x.bit_length() > 20000: + raise Invalid("x is unreasonably large") + for a, b in zip(inst["residues"], inst["moduli"]): + if x % b != a: + raise Invalid(f"x mod {b} = {x % b}, need {a}") + return None, {} diff --git a/tasks/construct-rlve-crt-l1-s6/tests/instance.json b/tasks/construct-rlve-crt-l1-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8f17afb3e5f4965ce9ec8e775f7a956b4730ed52 --- /dev/null +++ b/tasks/construct-rlve-crt-l1-s6/tests/instance.json @@ -0,0 +1 @@ +{"moduli": [4, 6], "residues": [2, 0], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l1-s6/tests/run.py b/tasks/construct-rlve-crt-l1-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-crt-l1-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-crt-l1-s6/tests/test.sh b/tasks/construct-rlve-crt-l1-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-crt-l1-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-crt-l5-s9/environment/Dockerfile b/tasks/construct-rlve-crt-l5-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-crt-l5-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-crt-l5-s9/environment/instance.json b/tasks/construct-rlve-crt-l5-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8c330cfb851e1ab1d908e00a42ffacaca62c027b --- /dev/null +++ b/tasks/construct-rlve-crt-l5-s9/environment/instance.json @@ -0,0 +1 @@ +{"moduli": [5861625, 1102539645, 3469817083, 2375841535, 3227743717, 3365047002], "residues": [1406298, 269378613, 107180465, 1201156013, 349253831, 211950546], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l5-s9/solution/solve.sh b/tasks/construct-rlve-crt-l5-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..321919acf65fb2e15c642384c775554fa1695b60 --- /dev/null +++ b/tasks/construct-rlve-crt-l5-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 3576997548} +RLMATH_EOF diff --git a/tasks/construct-rlve-crt-l5-s9/tests/check.py b/tasks/construct-rlve-crt-l5-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..886d95606ef325930b24794c0959c2ba7b254ebd --- /dev/null +++ b/tasks/construct-rlve-crt-l5-s9/tests/check.py @@ -0,0 +1,11 @@ +from run import Invalid, as_int + + +def check(inst, ans): + x = as_int(ans.get("x"), "x", lo=0) + if x.bit_length() > 20000: + raise Invalid("x is unreasonably large") + for a, b in zip(inst["residues"], inst["moduli"]): + if x % b != a: + raise Invalid(f"x mod {b} = {x % b}, need {a}") + return None, {} diff --git a/tasks/construct-rlve-crt-l5-s9/tests/instance.json b/tasks/construct-rlve-crt-l5-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8c330cfb851e1ab1d908e00a42ffacaca62c027b --- /dev/null +++ b/tasks/construct-rlve-crt-l5-s9/tests/instance.json @@ -0,0 +1 @@ +{"moduli": [5861625, 1102539645, 3469817083, 2375841535, 3227743717, 3365047002], "residues": [1406298, 269378613, 107180465, 1201156013, 349253831, 211950546], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l5-s9/tests/run.py b/tasks/construct-rlve-crt-l5-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-crt-l5-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-crt-l5-s9/tests/test.sh b/tasks/construct-rlve-crt-l5-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-crt-l5-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s9/environment/Dockerfile b/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s9/environment/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..878d8b22e6edca4fb9949a62d126cabd0c59c56c --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s9/environment/instance.json @@ -0,0 +1 @@ +{"A": [21, 7, 8, 17, 13, 2, 19, 14, 4, 27, 10, 20, 26, 6], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s9/solution/solve.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d077dbd3ceee2572bac74a8df73b28af17379385 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"B": [26, 8, 10, 19, 14, 4, 20, 17, 6, 2, 13, 21, 27, 7]} +RLMATH_EOF diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s9/tests/check.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..06bbbcf872c2fca05785f40fdfdcf85a5e5a0e7c --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s9/tests/check.py @@ -0,0 +1,22 @@ +from collections import Counter + +from run import Invalid, int_list + + +def check(inst, ans): + A = inst["A"] + n = len(A) + B = int_list(ans.get("B"), n, name="B") + if Counter(B) != Counter(A): + raise Invalid("B is not a permutation of A") + d = [a - b for a, b in zip(A, B)] + # count subsets (including empty and full) with sum 0; the empty and full sets always qualify + ways = Counter({0: 1}) + for x in d: + nxt = Counter(ways) + for s, c in ways.items(): + nxt[s + x] += c + ways = nxt + if ways[0] != 2: + raise Invalid(f"{ways[0] - 2} non-empty proper subsets have equal sums in A and B") + return None, {} diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s9/tests/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..878d8b22e6edca4fb9949a62d126cabd0c59c56c --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s9/tests/instance.json @@ -0,0 +1 @@ +{"A": [21, 7, 8, 17, 13, 2, 19, 14, 4, 27, 10, 20, 26, 6], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s9/tests/run.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s9/tests/test.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-even-degree-partition-l1-s8/environment/Dockerfile b/tasks/construct-rlve-even-degree-partition-l1-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l1-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-even-degree-partition-l1-s8/environment/instance.json b/tasks/construct-rlve-even-degree-partition-l1-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..632930f3e5bb164cbe74a000b5954e13abd4392b --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l1-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 5, "edges": [[0, 1], [2, 3]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l1-s8/solution/solve.sh b/tasks/construct-rlve-even-degree-partition-l1-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2390091880ec824317ddbda098379f48b04c9bfc --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l1-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"groups": [1, 2, 1, 2, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-even-degree-partition-l1-s8/tests/check.py b/tasks/construct-rlve-even-degree-partition-l1-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9c7f0f71ea6d10264ececcc933b97a4a0e6eaf8e --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l1-s8/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + g = int_list(ans.get("groups"), n, 1, 2, "groups") + deg = [0] * n + for u, v in inst["edges"]: + if g[u] == g[v]: + deg[u] += 1 + deg[v] += 1 + for v in range(n): + if deg[v] % 2: + raise Invalid(f"vertex {v} has {deg[v]} same-group neighbours") + return None, {} diff --git a/tasks/construct-rlve-even-degree-partition-l1-s8/tests/instance.json b/tasks/construct-rlve-even-degree-partition-l1-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..632930f3e5bb164cbe74a000b5954e13abd4392b --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l1-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 5, "edges": [[0, 1], [2, 3]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l1-s8/tests/run.py b/tasks/construct-rlve-even-degree-partition-l1-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l1-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-even-degree-partition-l1-s8/tests/test.sh b/tasks/construct-rlve-even-degree-partition-l1-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l1-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-even-degree-partition-l5-s0/environment/Dockerfile b/tasks/construct-rlve-even-degree-partition-l5-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l5-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-even-degree-partition-l5-s0/environment/instance.json b/tasks/construct-rlve-even-degree-partition-l5-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ab4338b18ec36000568e84f4eafb25d3899b4252 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l5-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 28, "edges": [[0, 2], [0, 3], [0, 7], [0, 8], [0, 11], [0, 12], [0, 14], [0, 15], [0, 17], [0, 18], [0, 20], [0, 21], [0, 27], [1, 2], [1, 4], [1, 6], [1, 7], [1, 8], [1, 9], [1, 11], [1, 14], [1, 15], [1, 16], [1, 18], [1, 20], [1, 21], [1, 22], [1, 27], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 14], [2, 15], [2, 16], [2, 17], [2, 19], [2, 20], [2, 21], [2, 22], [2, 23], [2, 24], [2, 25], [2, 26], [2, 27], [3, 4], [3, 5], [3, 6], [3, 8], [3, 11], [3, 12], [3, 13], [3, 15], [3, 16], [3, 18], [3, 20], [3, 22], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 12], [4, 14], [4, 16], [4, 18], [4, 19], [4, 21], [4, 22], [4, 23], [4, 25], [4, 26], [4, 27], [5, 8], [5, 11], [5, 17], [5, 18], [5, 21], [5, 22], [6, 8], [6, 13], [6, 15], [6, 16], [6, 17], [6, 18], [6, 20], [6, 21], [6, 22], [6, 27], [7, 8], [7, 12], [7, 13], [7, 15], [7, 17], [7, 18], [7, 21], [7, 22], [7, 23], [7, 25], [7, 27], [8, 9], [8, 10], [8, 11], [8, 12], [8, 14], [8, 15], [8, 16], [8, 18], [8, 19], [8, 20], [8, 21], [8, 22], [8, 23], [8, 24], [8, 25], [8, 26], [8, 27], [9, 11], [9, 13], [9, 14], [9, 15], [9, 17], [9, 18], [9, 21], [9, 22], [9, 27], [10, 17], [11, 14], [11, 20], [11, 22], [11, 26], [11, 27], [12, 14], [12, 15], [12, 16], [12, 18], [12, 21], [12, 22], [12, 27], [13, 15], [13, 17], [13, 19], [13, 20], [13, 21], [13, 24], [13, 25], [14, 16], [14, 17], [14, 19], [14, 21], [14, 22], [14, 23], [14, 24], [14, 27], [15, 17], [15, 20], [15, 21], [15, 23], [15, 25], [15, 26], [15, 27], [16, 20], [16, 27], [17, 19], [17, 20], [17, 23], [17, 25], [18, 20], [18, 21], [18, 22], [18, 23], [18, 24], [18, 25], [18, 26], [18, 27], [19, 22], [20, 23], [20, 24], [20, 25], [20, 26], [21, 26], [21, 27], [22, 23], [22, 25], [22, 26], [22, 27], [23, 27], [25, 26]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l5-s0/solution/solve.sh b/tasks/construct-rlve-even-degree-partition-l5-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9feab227e0527a5af13c911becd913965d92b176 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l5-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"groups": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-even-degree-partition-l5-s0/tests/check.py b/tasks/construct-rlve-even-degree-partition-l5-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9c7f0f71ea6d10264ececcc933b97a4a0e6eaf8e --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l5-s0/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + g = int_list(ans.get("groups"), n, 1, 2, "groups") + deg = [0] * n + for u, v in inst["edges"]: + if g[u] == g[v]: + deg[u] += 1 + deg[v] += 1 + for v in range(n): + if deg[v] % 2: + raise Invalid(f"vertex {v} has {deg[v]} same-group neighbours") + return None, {} diff --git a/tasks/construct-rlve-even-degree-partition-l5-s0/tests/instance.json b/tasks/construct-rlve-even-degree-partition-l5-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ab4338b18ec36000568e84f4eafb25d3899b4252 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l5-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 28, "edges": [[0, 2], [0, 3], [0, 7], [0, 8], [0, 11], [0, 12], [0, 14], [0, 15], [0, 17], [0, 18], [0, 20], [0, 21], [0, 27], [1, 2], [1, 4], [1, 6], [1, 7], [1, 8], [1, 9], [1, 11], [1, 14], [1, 15], [1, 16], [1, 18], [1, 20], [1, 21], [1, 22], [1, 27], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 14], [2, 15], [2, 16], [2, 17], [2, 19], [2, 20], [2, 21], [2, 22], [2, 23], [2, 24], [2, 25], [2, 26], [2, 27], [3, 4], [3, 5], [3, 6], [3, 8], [3, 11], [3, 12], [3, 13], [3, 15], [3, 16], [3, 18], [3, 20], [3, 22], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 12], [4, 14], [4, 16], [4, 18], [4, 19], [4, 21], [4, 22], [4, 23], [4, 25], [4, 26], [4, 27], [5, 8], [5, 11], [5, 17], [5, 18], [5, 21], [5, 22], [6, 8], [6, 13], [6, 15], [6, 16], [6, 17], [6, 18], [6, 20], [6, 21], [6, 22], [6, 27], [7, 8], [7, 12], [7, 13], [7, 15], [7, 17], [7, 18], [7, 21], [7, 22], [7, 23], [7, 25], [7, 27], [8, 9], [8, 10], [8, 11], [8, 12], [8, 14], [8, 15], [8, 16], [8, 18], [8, 19], [8, 20], [8, 21], [8, 22], [8, 23], [8, 24], [8, 25], [8, 26], [8, 27], [9, 11], [9, 13], [9, 14], [9, 15], [9, 17], [9, 18], [9, 21], [9, 22], [9, 27], [10, 17], [11, 14], [11, 20], [11, 22], [11, 26], [11, 27], [12, 14], [12, 15], [12, 16], [12, 18], [12, 21], [12, 22], [12, 27], [13, 15], [13, 17], [13, 19], [13, 20], [13, 21], [13, 24], [13, 25], [14, 16], [14, 17], [14, 19], [14, 21], [14, 22], [14, 23], [14, 24], [14, 27], [15, 17], [15, 20], [15, 21], [15, 23], [15, 25], [15, 26], [15, 27], [16, 20], [16, 27], [17, 19], [17, 20], [17, 23], [17, 25], [18, 20], [18, 21], [18, 22], [18, 23], [18, 24], [18, 25], [18, 26], [18, 27], [19, 22], [20, 23], [20, 24], [20, 25], [20, 26], [21, 26], [21, 27], [22, 23], [22, 25], [22, 26], [22, 27], [23, 27], [25, 26]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l5-s0/tests/run.py b/tasks/construct-rlve-even-degree-partition-l5-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l5-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-even-degree-partition-l5-s0/tests/test.sh b/tasks/construct-rlve-even-degree-partition-l5-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l5-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-graph-isomorphism-l3-s3/environment/Dockerfile b/tasks/construct-rlve-graph-isomorphism-l3-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l3-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-graph-isomorphism-l3-s3/environment/instance.json b/tasks/construct-rlve-graph-isomorphism-l3-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5c183b7b31e1e0eca14695f3d41a729b90d3312e --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l3-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 12, "edges1": [[4, 11], [8, 10], [1, 3], [5, 9], [0, 11], [1, 7], [0, 3], [0, 10], [6, 9], [0, 6], [3, 5], [1, 8], [3, 7], [4, 6], [7, 8], [2, 11]], "edges2": [[0, 3], [3, 6], [7, 11], [0, 9], [1, 4], [3, 9], [2, 9], [4, 11], [4, 6], [10, 11], [0, 6], [5, 8], [1, 7], [2, 4], [1, 8], [5, 6]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l3-s3/solution/solve.sh b/tasks/construct-rlve-graph-isomorphism-l3-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..50051484285277274bd25899504fcd7faa2da95c --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l3-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"p": [4, 0, 10, 6, 7, 5, 1, 3, 9, 8, 2, 11]} +RLMATH_EOF diff --git a/tasks/construct-rlve-graph-isomorphism-l3-s3/tests/check.py b/tasks/construct-rlve-graph-isomorphism-l3-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..64b755f5ab12e7270811ccfc2f02d104715517b7 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l3-s3/tests/check.py @@ -0,0 +1,13 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("p"), n, 0, n - 1, "p") + if len(set(p)) != n: + raise Invalid("p is not a permutation") + e2 = {(min(u, v), max(u, v)) for u, v in inst["edges2"]} + img = {(min(p[u], p[v]), max(p[u], p[v])) for u, v in inst["edges1"]} + if img != e2: + raise Invalid(f"{len(img - e2)} edges of G1 are not mapped onto edges of G2") + return None, {} diff --git a/tasks/construct-rlve-graph-isomorphism-l3-s3/tests/instance.json b/tasks/construct-rlve-graph-isomorphism-l3-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5c183b7b31e1e0eca14695f3d41a729b90d3312e --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l3-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 12, "edges1": [[4, 11], [8, 10], [1, 3], [5, 9], [0, 11], [1, 7], [0, 3], [0, 10], [6, 9], [0, 6], [3, 5], [1, 8], [3, 7], [4, 6], [7, 8], [2, 11]], "edges2": [[0, 3], [3, 6], [7, 11], [0, 9], [1, 4], [3, 9], [2, 9], [4, 11], [4, 6], [10, 11], [0, 6], [5, 8], [1, 7], [2, 4], [1, 8], [5, 6]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l3-s3/tests/run.py b/tasks/construct-rlve-graph-isomorphism-l3-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l3-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-graph-isomorphism-l3-s3/tests/test.sh b/tasks/construct-rlve-graph-isomorphism-l3-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l3-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-grid-parity-construction-l3-s4/environment/Dockerfile b/tasks/construct-rlve-grid-parity-construction-l3-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l3-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-grid-parity-construction-l3-s4/environment/instance.json b/tasks/construct-rlve-grid-parity-construction-l3-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4ce4075a814262725f91fc319e60710218adec94 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l3-s4/environment/instance.json @@ -0,0 +1 @@ +{"parity": ["11", "01", "01", "10", "00", "11", "01"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l3-s4/solution/solve.sh b/tasks/construct-rlve-grid-parity-construction-l3-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9017d10dac30125452a344cbc999e5aa78503ff5 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l3-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"grid": ["11", "11", "10", "01", "11", "01", "11"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-grid-parity-construction-l3-s4/tests/check.py b/tasks/construct-rlve-grid-parity-construction-l3-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..89d5d286593348d0000ac10db74e1c6242be6c97 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l3-s4/tests/check.py @@ -0,0 +1,22 @@ +from run import Invalid + + +def check(inst, ans): + P = inst["parity"] + N, M = len(P), len(P[0]) + G = ans.get("grid") + if not isinstance(G, list) or len(G) != N: + raise Invalid(f"grid must be a list of {N} strings") + for r in G: + if not isinstance(r, str) or len(r) != M or set(r) - {"0", "1"}: + raise Invalid(f"each row must be a string of {M} characters '0'/'1'") + for i in range(N): + for j in range(M): + v = int(G[i][j]) + for di, dj in ((-1, 0), (1, 0), (0, -1), (0, 1)): + a, b = i + di, j + dj + if 0 <= a < N and 0 <= b < M: + v ^= int(G[a][b]) + if v != int(P[i][j]): + raise Invalid(f"parity mismatch at ({i}, {j})") + return None, {} diff --git a/tasks/construct-rlve-grid-parity-construction-l3-s4/tests/instance.json b/tasks/construct-rlve-grid-parity-construction-l3-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4ce4075a814262725f91fc319e60710218adec94 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l3-s4/tests/instance.json @@ -0,0 +1 @@ +{"parity": ["11", "01", "01", "10", "00", "11", "01"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l3-s4/tests/run.py b/tasks/construct-rlve-grid-parity-construction-l3-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l3-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-grid-parity-construction-l3-s4/tests/test.sh b/tasks/construct-rlve-grid-parity-construction-l3-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l3-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-imp-party-l1-s2/environment/Dockerfile b/tasks/construct-rlve-imp-party-l1-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l1-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-imp-party-l1-s2/environment/instance.json b/tasks/construct-rlve-imp-party-l1-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..dcd095e5e771d01bad6829bdf19e917cabb66676 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l1-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 3, "edges": [[0, 2], [0, 6], [0, 7], [0, 8], [1, 2], [1, 5], [1, 6], [1, 7], [1, 8], [2, 3], [2, 5], [2, 6], [2, 7], [2, 8], [3, 5], [3, 6], [3, 7], [3, 8], [4, 6], [5, 6], [5, 7], [5, 8], [6, 7], [6, 8], [7, 8]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l1-s2/solution/solve.sh b/tasks/construct-rlve-imp-party-l1-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c36ea20b5a5c19f7172cb7a93800610a1522fde0 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l1-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [2, 5, 6]} +RLMATH_EOF diff --git a/tasks/construct-rlve-imp-party-l1-s2/tests/check.py b/tasks/construct-rlve-imp-party-l1-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..97b5a037a2ba8bf4495cf87cc074d1c60b11311c --- /dev/null +++ b/tasks/construct-rlve-imp-party-l1-s2/tests/check.py @@ -0,0 +1,14 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + c = int_list(ans.get("clique"), n, 0, 3 * n - 1, "clique") + if len(set(c)) != n: + raise Invalid("vertices must be distinct") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for i in range(n): + for j in range(i + 1, n): + if (min(c[i], c[j]), max(c[i], c[j])) not in es: + raise Invalid(f"{c[i]} and {c[j]} are not adjacent") + return None, {} diff --git a/tasks/construct-rlve-imp-party-l1-s2/tests/instance.json b/tasks/construct-rlve-imp-party-l1-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..dcd095e5e771d01bad6829bdf19e917cabb66676 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l1-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 3, "edges": [[0, 2], [0, 6], [0, 7], [0, 8], [1, 2], [1, 5], [1, 6], [1, 7], [1, 8], [2, 3], [2, 5], [2, 6], [2, 7], [2, 8], [3, 5], [3, 6], [3, 7], [3, 8], [4, 6], [5, 6], [5, 7], [5, 8], [6, 7], [6, 8], [7, 8]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l1-s2/tests/run.py b/tasks/construct-rlve-imp-party-l1-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-imp-party-l1-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-imp-party-l1-s2/tests/test.sh b/tasks/construct-rlve-imp-party-l1-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l1-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-imp-party-l1-s5/environment/Dockerfile b/tasks/construct-rlve-imp-party-l1-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l1-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-imp-party-l1-s5/environment/instance.json b/tasks/construct-rlve-imp-party-l1-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a7cc2630f3759b37eee6ce85e41ce9154067919f --- /dev/null +++ b/tasks/construct-rlve-imp-party-l1-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 3, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [1, 4], [2, 3], [2, 4], [2, 5], [2, 7], [2, 8], [3, 4], [3, 6], [3, 7], [3, 8], [4, 6], [4, 7], [4, 8], [5, 7], [5, 8], [6, 7], [7, 8]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l1-s5/solution/solve.sh b/tasks/construct-rlve-imp-party-l1-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6124fb103c92b20bdcbaf5833feb9fe1a59427b4 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l1-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [0, 7, 8]} +RLMATH_EOF diff --git a/tasks/construct-rlve-imp-party-l1-s5/tests/check.py b/tasks/construct-rlve-imp-party-l1-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..97b5a037a2ba8bf4495cf87cc074d1c60b11311c --- /dev/null +++ b/tasks/construct-rlve-imp-party-l1-s5/tests/check.py @@ -0,0 +1,14 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + c = int_list(ans.get("clique"), n, 0, 3 * n - 1, "clique") + if len(set(c)) != n: + raise Invalid("vertices must be distinct") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for i in range(n): + for j in range(i + 1, n): + if (min(c[i], c[j]), max(c[i], c[j])) not in es: + raise Invalid(f"{c[i]} and {c[j]} are not adjacent") + return None, {} diff --git a/tasks/construct-rlve-imp-party-l1-s5/tests/instance.json b/tasks/construct-rlve-imp-party-l1-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a7cc2630f3759b37eee6ce85e41ce9154067919f --- /dev/null +++ b/tasks/construct-rlve-imp-party-l1-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 3, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [1, 4], [2, 3], [2, 4], [2, 5], [2, 7], [2, 8], [3, 4], [3, 6], [3, 7], [3, 8], [4, 6], [4, 7], [4, 8], [5, 7], [5, 8], [6, 7], [7, 8]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l1-s5/tests/run.py b/tasks/construct-rlve-imp-party-l1-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-imp-party-l1-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-imp-party-l1-s5/tests/test.sh b/tasks/construct-rlve-imp-party-l1-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l1-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-imp-party-l5-s3/environment/Dockerfile b/tasks/construct-rlve-imp-party-l5-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l5-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-imp-party-l5-s3/environment/instance.json b/tasks/construct-rlve-imp-party-l5-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..447fdee395a3d111845b44f7c9c0af2ce127c8a1 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l5-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 18, "edges": [[0, 11], [0, 17], [0, 18], [0, 21], [0, 27], [0, 28], [0, 30], [0, 31], [0, 35], [0, 41], [1, 2], [1, 3], [1, 4], [1, 5], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 23], [1, 25], [1, 26], [1, 27], [1, 28], [1, 29], [1, 30], [1, 31], [1, 33], [1, 34], [1, 35], [1, 36], [1, 38], [1, 39], [1, 41], [1, 42], [1, 43], [1, 47], [1, 48], [1, 50], [1, 51], [1, 53], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 15], [2, 17], [2, 18], [2, 19], [2, 20], [2, 21], [2, 22], [2, 23], [2, 25], [2, 26], [2, 27], [2, 28], [2, 29], [2, 30], [2, 31], [2, 33], [2, 35], [2, 36], [2, 37], [2, 38], [2, 39], [2, 41], [2, 42], [2, 43], [2, 46], [2, 47], [2, 48], [2, 50], [2, 51], [3, 5], [3, 9], [3, 13], [3, 14], [3, 19], [3, 21], [3, 23], [3, 25], [3, 29], [3, 30], [3, 31], [3, 35], [3, 41], [3, 48], [3, 51], [4, 5], [4, 6], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [4, 13], [4, 14], [4, 17], [4, 18], [4, 19], [4, 20], [4, 21], [4, 22], [4, 23], [4, 24], [4, 25], [4, 26], [4, 27], [4, 28], [4, 29], [4, 30], [4, 31], [4, 33], [4, 34], [4, 35], [4, 36], [4, 37], [4, 38], [4, 39], [4, 41], [4, 42], [4, 43], [4, 45], [4, 47], [4, 48], [4, 49], [4, 50], [4, 51], [4, 53], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 13], [5, 14], [5, 15], [5, 17], [5, 18], [5, 19], [5, 20], [5, 21], [5, 22], [5, 23], [5, 25], [5, 26], [5, 27], [5, 28], [5, 29], [5, 30], [5, 31], [5, 32], [5, 33], [5, 35], [5, 36], [5, 37], [5, 38], [5, 39], [5, 41], [5, 42], [5, 44], [5, 46], [5, 47], [5, 48], [5, 50], [5, 51], [5, 52], [6, 11], [6, 20], [6, 21], [6, 23], [6, 27], [6, 31], [6, 38], [6, 39], [6, 42], [6, 50], [7, 9], [7, 10], [7, 11], [7, 12], [7, 19], [7, 21], [7, 22], [7, 23], [7, 26], [7, 27], [7, 28], [7, 41], [7, 42], [7, 51], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [8, 14], [8, 17], [8, 18], [8, 19], [8, 20], [8, 21], [8, 22], [8, 23], [8, 24], [8, 25], [8, 26], [8, 27], [8, 28], [8, 29], [8, 30], [8, 31], [8, 32], [8, 33], [8, 34], [8, 35], [8, 36], [8, 38], [8, 39], [8, 41], [8, 42], [8, 44], [8, 46], [8, 47], [8, 48], [8, 50], [8, 51], [8, 53], [9, 10], [9, 11], [9, 12], [9, 13], [9, 14], [9, 16], [9, 17], [9, 18], [9, 19], [9, 20], [9, 21], [9, 22], [9, 23], [9, 25], [9, 26], [9, 27], [9, 28], [9, 29], [9, 30], [9, 31], [9, 32], [9, 33], [9, 35], [9, 36], [9, 38], [9, 39], [9, 40], [9, 41], [9, 42], [9, 43], [9, 45], [9, 46], [9, 47], [9, 48], [9, 49], [9, 50], [9, 51], [9, 53], [10, 11], [10, 12], [10, 13], [10, 14], [10, 17], [10, 18], [10, 19], [10, 20], [10, 21], [10, 22], [10, 23], [10, 25], [10, 26], [10, 27], [10, 28], [10, 29], [10, 30], [10, 31], [10, 33], [10, 35], [10, 36], [10, 37], [10, 38], [10, 39], [10, 40], [10, 41], [10, 42], [10, 44], [10, 45], [10, 46], [10, 47], [10, 48], [10, 50], [10, 51], [10, 52], [11, 12], [11, 13], [11, 14], [11, 17], [11, 18], [11, 19], [11, 20], [11, 21], [11, 22], [11, 23], [11, 24], [11, 25], [11, 26], [11, 27], [11, 28], [11, 29], [11, 30], [11, 31], [11, 33], [11, 34], [11, 35], [11, 36], [11, 37], [11, 38], [11, 39], [11, 40], [11, 41], [11, 42], [11, 45], [11, 47], [11, 48], [11, 49], [11, 50], [11, 51], [12, 13], [12, 14], [12, 16], [12, 17], [12, 18], [12, 19], [12, 20], [12, 21], [12, 22], [12, 23], [12, 24], [12, 25], [12, 26], [12, 27], [12, 28], [12, 29], [12, 30], [12, 31], [12, 32], [12, 33], [12, 35], [12, 36], [12, 38], [12, 39], [12, 41], [12, 42], [12, 43], [12, 45], [12, 46], [12, 47], [12, 48], [12, 50], [12, 51], [12, 52], [13, 14], [13, 17], [13, 18], [13, 19], [13, 20], [13, 21], [13, 22], [13, 23], [13, 25], [13, 26], [13, 27], [13, 28], [13, 29], [13, 30], [13, 31], [13, 32], [13, 33], [13, 35], [13, 36], [13, 38], [13, 39], [13, 40], [13, 41], [13, 42], [13, 44], [13, 46], [13, 47], [13, 48], [13, 49], [13, 50], [13, 51], [14, 16], [14, 17], [14, 18], [14, 19], [14, 20], [14, 21], [14, 22], [14, 23], [14, 24], [14, 25], [14, 26], [14, 27], [14, 28], [14, 29], [14, 30], [14, 31], [14, 33], [14, 35], [14, 36], [14, 38], [14, 39], [14, 40], [14, 41], [14, 42], [14, 46], [14, 47], [14, 48], [14, 49], [14, 50], [14, 51], [14, 52], [15, 23], [15, 26], [15, 29], [15, 30], [15, 31], [15, 33], [15, 36], [15, 38], [15, 41], [15, 42], [15, 47], [16, 17], [16, 18], [16, 22], [16, 23], [16, 27], [16, 28], [16, 29], [16, 30], [16, 31], [16, 35], [16, 36], [16, 39], [16, 42], [16, 51], [17, 18], [17, 19], [17, 20], [17, 21], [17, 22], [17, 23], [17, 24], [17, 25], [17, 26], [17, 27], [17, 28], [17, 29], [17, 30], [17, 31], [17, 32], [17, 33], [17, 34], [17, 35], [17, 36], [17, 37], [17, 38], [17, 39], [17, 41], [17, 42], [17, 44], [17, 46], [17, 47], [17, 48], [17, 49], [17, 50], [17, 51], [17, 52], [17, 53], [18, 19], [18, 20], [18, 21], [18, 22], [18, 23], [18, 25], [18, 26], [18, 27], [18, 28], [18, 29], [18, 30], [18, 31], [18, 33], [18, 35], [18, 36], [18, 38], [18, 39], [18, 41], [18, 42], [18, 44], [18, 45], [18, 47], [18, 48], [18, 50], [18, 51], [18, 53], [19, 20], [19, 21], [19, 22], [19, 23], [19, 25], [19, 26], [19, 27], [19, 28], [19, 29], [19, 30], [19, 31], [19, 32], [19, 33], [19, 34], [19, 35], [19, 36], [19, 37], [19, 38], [19, 39], [19, 41], [19, 42], [19, 45], [19, 47], [19, 48], [19, 49], [19, 50], [19, 51], [20, 21], [20, 22], [20, 23], [20, 25], [20, 26], [20, 27], [20, 28], [20, 29], [20, 30], [20, 31], [20, 33], [20, 35], [20, 36], [20, 38], [20, 39], [20, 40], [20, 41], [20, 42], [20, 44], [20, 45], [20, 46], [20, 47], [20, 48], [20, 49], [20, 50], [20, 51], [21, 22], [21, 23], [21, 25], [21, 26], [21, 27], [21, 28], [21, 29], [21, 30], [21, 31], [21, 33], [21, 35], [21, 36], [21, 37], [21, 38], [21, 39], [21, 40], [21, 41], [21, 42], [21, 43], [21, 46], [21, 47], [21, 48], [21, 49], [21, 50], [21, 51], [21, 52], [22, 23], [22, 24], [22, 25], [22, 26], [22, 27], [22, 28], [22, 29], [22, 30], [22, 31], [22, 32], [22, 33], [22, 34], [22, 35], [22, 36], [22, 38], [22, 39], [22, 41], [22, 42], [22, 46], [22, 47], [22, 48], [22, 50], [22, 51], [22, 52], [23, 24], [23, 25], [23, 26], [23, 27], [23, 28], [23, 29], [23, 30], [23, 31], [23, 33], [23, 34], [23, 35], [23, 36], [23, 38], [23, 39], [23, 41], [23, 42], [23, 44], [23, 47], [23, 48], [23, 49], [23, 50], [23, 51], [24, 25], [24, 28], [24, 35], [24, 36], [24, 50], [24, 51], [25, 26], [25, 27], [25, 28], [25, 29], [25, 30], [25, 31], [25, 32], [25, 33], [25, 35], [25, 36], [25, 37], [25, 38], [25, 39], [25, 41], [25, 42], [25, 47], [25, 48], [25, 49], [25, 50], [25, 51], [25, 52], [25, 53], [26, 27], [26, 28], [26, 29], [26, 30], [26, 31], [26, 33], [26, 35], [26, 36], [26, 38], [26, 39], [26, 41], [26, 42], [26, 43], [26, 46], [26, 47], [26, 48], [26, 49], [26, 50], [26, 51], [26, 53], [27, 28], [27, 29], [27, 30], [27, 31], [27, 32], [27, 33], [27, 34], [27, 35], [27, 36], [27, 38], [27, 39], [27, 40], [27, 41], [27, 42], [27, 43], [27, 44], [27, 47], [27, 48], [27, 49], [27, 50], [27, 51], [27, 52], [28, 29], [28, 30], [28, 31], [28, 33], [28, 34], [28, 35], [28, 36], [28, 37], [28, 38], [28, 39], [28, 40], [28, 41], [28, 42], [28, 44], [28, 47], [28, 48], [28, 50], [28, 51], [29, 30], [29, 31], [29, 32], [29, 33], [29, 35], [29, 36], [29, 38], [29, 39], [29, 40], [29, 41], [29, 42], [29, 45], [29, 47], [29, 48], [29, 49], [29, 50], [29, 51], [29, 52], [30, 31], [30, 32], [30, 33], [30, 34], [30, 35], [30, 36], [30, 38], [30, 39], [30, 40], [30, 41], [30, 42], [30, 43], [30, 44], [30, 45], [30, 46], [30, 47], [30, 48], [30, 50], [30, 51], [30, 53], [31, 32], [31, 33], [31, 34], [31, 35], [31, 36], [31, 37], [31, 38], [31, 39], [31, 41], [31, 42], [31, 47], [31, 48], [31, 50], [31, 51], [31, 52], [32, 33], [32, 35], [32, 39], [32, 41], [32, 42], [32, 47], [32, 48], [33, 35], [33, 36], [33, 37], [33, 38], [33, 39], [33, 41], [33, 42], [33, 43], [33, 44], [33, 46], [33, 47], [33, 48], [33, 49], [33, 50], [33, 51], [33, 53], [34, 38], [34, 42], [34, 48], [35, 36], [35, 38], [35, 39], [35, 41], [35, 42], [35, 47], [35, 48], [35, 50], [35, 51], [35, 53], [36, 37], [36, 38], [36, 39], [36, 40], [36, 41], [36, 42], [36, 44], [36, 45], [36, 46], [36, 47], [36, 48], [36, 49], [36, 50], [36, 51], [36, 53], [37, 42], [37, 47], [37, 50], [38, 39], [38, 40], [38, 41], [38, 42], [38, 43], [38, 45], [38, 47], [38, 48], [38, 50], [38, 51], [39, 41], [39, 42], [39, 43], [39, 44], [39, 46], [39, 47], [39, 48], [39, 50], [39, 51], [40, 42], [40, 48], [41, 42], [41, 44], [41, 45], [41, 47], [41, 48], [41, 49], [41, 50], [41, 51], [42, 43], [42, 44], [42, 47], [42, 48], [42, 49], [42, 50], [42, 51], [42, 52], [42, 53], [43, 47], [43, 48], [43, 51], [44, 47], [44, 50], [44, 51], [45, 48], [45, 51], [46, 47], [46, 48], [46, 50], [46, 51], [47, 48], [47, 50], [47, 51], [47, 52], [48, 50], [48, 51], [48, 52], [48, 53], [49, 50], [50, 51]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l5-s3/solution/solve.sh b/tasks/construct-rlve-imp-party-l5-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..87d33fc8cfa5d2978620d7788966e15493e2e5ab --- /dev/null +++ b/tasks/construct-rlve-imp-party-l5-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [4, 8, 10, 11, 12, 19, 21, 22, 25, 27, 30, 31, 33, 35, 38, 41, 42, 50]} +RLMATH_EOF diff --git a/tasks/construct-rlve-imp-party-l5-s3/tests/check.py b/tasks/construct-rlve-imp-party-l5-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..97b5a037a2ba8bf4495cf87cc074d1c60b11311c --- /dev/null +++ b/tasks/construct-rlve-imp-party-l5-s3/tests/check.py @@ -0,0 +1,14 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + c = int_list(ans.get("clique"), n, 0, 3 * n - 1, "clique") + if len(set(c)) != n: + raise Invalid("vertices must be distinct") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for i in range(n): + for j in range(i + 1, n): + if (min(c[i], c[j]), max(c[i], c[j])) not in es: + raise Invalid(f"{c[i]} and {c[j]} are not adjacent") + return None, {} diff --git a/tasks/construct-rlve-imp-party-l5-s3/tests/instance.json b/tasks/construct-rlve-imp-party-l5-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..447fdee395a3d111845b44f7c9c0af2ce127c8a1 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l5-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 18, "edges": [[0, 11], [0, 17], [0, 18], [0, 21], [0, 27], [0, 28], [0, 30], [0, 31], [0, 35], [0, 41], [1, 2], [1, 3], [1, 4], [1, 5], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 23], [1, 25], [1, 26], [1, 27], [1, 28], [1, 29], [1, 30], [1, 31], [1, 33], [1, 34], [1, 35], [1, 36], [1, 38], [1, 39], [1, 41], [1, 42], [1, 43], [1, 47], [1, 48], [1, 50], [1, 51], [1, 53], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 15], [2, 17], [2, 18], [2, 19], [2, 20], [2, 21], [2, 22], [2, 23], [2, 25], [2, 26], [2, 27], [2, 28], [2, 29], [2, 30], [2, 31], [2, 33], [2, 35], [2, 36], [2, 37], [2, 38], [2, 39], [2, 41], [2, 42], [2, 43], [2, 46], [2, 47], [2, 48], [2, 50], [2, 51], [3, 5], [3, 9], [3, 13], [3, 14], [3, 19], [3, 21], [3, 23], [3, 25], [3, 29], [3, 30], [3, 31], [3, 35], [3, 41], [3, 48], [3, 51], [4, 5], [4, 6], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [4, 13], [4, 14], [4, 17], [4, 18], [4, 19], [4, 20], [4, 21], [4, 22], [4, 23], [4, 24], [4, 25], [4, 26], [4, 27], [4, 28], [4, 29], [4, 30], [4, 31], [4, 33], [4, 34], [4, 35], [4, 36], [4, 37], [4, 38], [4, 39], [4, 41], [4, 42], [4, 43], [4, 45], [4, 47], [4, 48], [4, 49], [4, 50], [4, 51], [4, 53], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 13], [5, 14], [5, 15], [5, 17], [5, 18], [5, 19], [5, 20], [5, 21], [5, 22], [5, 23], [5, 25], [5, 26], [5, 27], [5, 28], [5, 29], [5, 30], [5, 31], [5, 32], [5, 33], [5, 35], [5, 36], [5, 37], [5, 38], [5, 39], [5, 41], [5, 42], [5, 44], [5, 46], [5, 47], [5, 48], [5, 50], [5, 51], [5, 52], [6, 11], [6, 20], [6, 21], [6, 23], [6, 27], [6, 31], [6, 38], [6, 39], [6, 42], [6, 50], [7, 9], [7, 10], [7, 11], [7, 12], [7, 19], [7, 21], [7, 22], [7, 23], [7, 26], [7, 27], [7, 28], [7, 41], [7, 42], [7, 51], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [8, 14], [8, 17], [8, 18], [8, 19], [8, 20], [8, 21], [8, 22], [8, 23], [8, 24], [8, 25], [8, 26], [8, 27], [8, 28], [8, 29], [8, 30], [8, 31], [8, 32], [8, 33], [8, 34], [8, 35], [8, 36], [8, 38], [8, 39], [8, 41], [8, 42], [8, 44], [8, 46], [8, 47], [8, 48], [8, 50], [8, 51], [8, 53], [9, 10], [9, 11], [9, 12], [9, 13], [9, 14], [9, 16], [9, 17], [9, 18], [9, 19], [9, 20], [9, 21], [9, 22], [9, 23], [9, 25], [9, 26], [9, 27], [9, 28], [9, 29], [9, 30], [9, 31], [9, 32], [9, 33], [9, 35], [9, 36], [9, 38], [9, 39], [9, 40], [9, 41], [9, 42], [9, 43], [9, 45], [9, 46], [9, 47], [9, 48], [9, 49], [9, 50], [9, 51], [9, 53], [10, 11], [10, 12], [10, 13], [10, 14], [10, 17], [10, 18], [10, 19], [10, 20], [10, 21], [10, 22], [10, 23], [10, 25], [10, 26], [10, 27], [10, 28], [10, 29], [10, 30], [10, 31], [10, 33], [10, 35], [10, 36], [10, 37], [10, 38], [10, 39], [10, 40], [10, 41], [10, 42], [10, 44], [10, 45], [10, 46], [10, 47], [10, 48], [10, 50], [10, 51], [10, 52], [11, 12], [11, 13], [11, 14], [11, 17], [11, 18], [11, 19], [11, 20], [11, 21], [11, 22], [11, 23], [11, 24], [11, 25], [11, 26], [11, 27], [11, 28], [11, 29], [11, 30], [11, 31], [11, 33], [11, 34], [11, 35], [11, 36], [11, 37], [11, 38], [11, 39], [11, 40], [11, 41], [11, 42], [11, 45], [11, 47], [11, 48], [11, 49], [11, 50], [11, 51], [12, 13], [12, 14], [12, 16], [12, 17], [12, 18], [12, 19], [12, 20], [12, 21], [12, 22], [12, 23], [12, 24], [12, 25], [12, 26], [12, 27], [12, 28], [12, 29], [12, 30], [12, 31], [12, 32], [12, 33], [12, 35], [12, 36], [12, 38], [12, 39], [12, 41], [12, 42], [12, 43], [12, 45], [12, 46], [12, 47], [12, 48], [12, 50], [12, 51], [12, 52], [13, 14], [13, 17], [13, 18], [13, 19], [13, 20], [13, 21], [13, 22], [13, 23], [13, 25], [13, 26], [13, 27], [13, 28], [13, 29], [13, 30], [13, 31], [13, 32], [13, 33], [13, 35], [13, 36], [13, 38], [13, 39], [13, 40], [13, 41], [13, 42], [13, 44], [13, 46], [13, 47], [13, 48], [13, 49], [13, 50], [13, 51], [14, 16], [14, 17], [14, 18], [14, 19], [14, 20], [14, 21], [14, 22], [14, 23], [14, 24], [14, 25], [14, 26], [14, 27], [14, 28], [14, 29], [14, 30], [14, 31], [14, 33], [14, 35], [14, 36], [14, 38], [14, 39], [14, 40], [14, 41], [14, 42], [14, 46], [14, 47], [14, 48], [14, 49], [14, 50], [14, 51], [14, 52], [15, 23], [15, 26], [15, 29], [15, 30], [15, 31], [15, 33], [15, 36], [15, 38], [15, 41], [15, 42], [15, 47], [16, 17], [16, 18], [16, 22], [16, 23], [16, 27], [16, 28], [16, 29], [16, 30], [16, 31], [16, 35], [16, 36], [16, 39], [16, 42], [16, 51], [17, 18], [17, 19], [17, 20], [17, 21], [17, 22], [17, 23], [17, 24], [17, 25], [17, 26], [17, 27], [17, 28], [17, 29], [17, 30], [17, 31], [17, 32], [17, 33], [17, 34], [17, 35], [17, 36], [17, 37], [17, 38], [17, 39], [17, 41], [17, 42], [17, 44], [17, 46], [17, 47], [17, 48], [17, 49], [17, 50], [17, 51], [17, 52], [17, 53], [18, 19], [18, 20], [18, 21], [18, 22], [18, 23], [18, 25], [18, 26], [18, 27], [18, 28], [18, 29], [18, 30], [18, 31], [18, 33], [18, 35], [18, 36], [18, 38], [18, 39], [18, 41], [18, 42], [18, 44], [18, 45], [18, 47], [18, 48], [18, 50], [18, 51], [18, 53], [19, 20], [19, 21], [19, 22], [19, 23], [19, 25], [19, 26], [19, 27], [19, 28], [19, 29], [19, 30], [19, 31], [19, 32], [19, 33], [19, 34], [19, 35], [19, 36], [19, 37], [19, 38], [19, 39], [19, 41], [19, 42], [19, 45], [19, 47], [19, 48], [19, 49], [19, 50], [19, 51], [20, 21], [20, 22], [20, 23], [20, 25], [20, 26], [20, 27], [20, 28], [20, 29], [20, 30], [20, 31], [20, 33], [20, 35], [20, 36], [20, 38], [20, 39], [20, 40], [20, 41], [20, 42], [20, 44], [20, 45], [20, 46], [20, 47], [20, 48], [20, 49], [20, 50], [20, 51], [21, 22], [21, 23], [21, 25], [21, 26], [21, 27], [21, 28], [21, 29], [21, 30], [21, 31], [21, 33], [21, 35], [21, 36], [21, 37], [21, 38], [21, 39], [21, 40], [21, 41], [21, 42], [21, 43], [21, 46], [21, 47], [21, 48], [21, 49], [21, 50], [21, 51], [21, 52], [22, 23], [22, 24], [22, 25], [22, 26], [22, 27], [22, 28], [22, 29], [22, 30], [22, 31], [22, 32], [22, 33], [22, 34], [22, 35], [22, 36], [22, 38], [22, 39], [22, 41], [22, 42], [22, 46], [22, 47], [22, 48], [22, 50], [22, 51], [22, 52], [23, 24], [23, 25], [23, 26], [23, 27], [23, 28], [23, 29], [23, 30], [23, 31], [23, 33], [23, 34], [23, 35], [23, 36], [23, 38], [23, 39], [23, 41], [23, 42], [23, 44], [23, 47], [23, 48], [23, 49], [23, 50], [23, 51], [24, 25], [24, 28], [24, 35], [24, 36], [24, 50], [24, 51], [25, 26], [25, 27], [25, 28], [25, 29], [25, 30], [25, 31], [25, 32], [25, 33], [25, 35], [25, 36], [25, 37], [25, 38], [25, 39], [25, 41], [25, 42], [25, 47], [25, 48], [25, 49], [25, 50], [25, 51], [25, 52], [25, 53], [26, 27], [26, 28], [26, 29], [26, 30], [26, 31], [26, 33], [26, 35], [26, 36], [26, 38], [26, 39], [26, 41], [26, 42], [26, 43], [26, 46], [26, 47], [26, 48], [26, 49], [26, 50], [26, 51], [26, 53], [27, 28], [27, 29], [27, 30], [27, 31], [27, 32], [27, 33], [27, 34], [27, 35], [27, 36], [27, 38], [27, 39], [27, 40], [27, 41], [27, 42], [27, 43], [27, 44], [27, 47], [27, 48], [27, 49], [27, 50], [27, 51], [27, 52], [28, 29], [28, 30], [28, 31], [28, 33], [28, 34], [28, 35], [28, 36], [28, 37], [28, 38], [28, 39], [28, 40], [28, 41], [28, 42], [28, 44], [28, 47], [28, 48], [28, 50], [28, 51], [29, 30], [29, 31], [29, 32], [29, 33], [29, 35], [29, 36], [29, 38], [29, 39], [29, 40], [29, 41], [29, 42], [29, 45], [29, 47], [29, 48], [29, 49], [29, 50], [29, 51], [29, 52], [30, 31], [30, 32], [30, 33], [30, 34], [30, 35], [30, 36], [30, 38], [30, 39], [30, 40], [30, 41], [30, 42], [30, 43], [30, 44], [30, 45], [30, 46], [30, 47], [30, 48], [30, 50], [30, 51], [30, 53], [31, 32], [31, 33], [31, 34], [31, 35], [31, 36], [31, 37], [31, 38], [31, 39], [31, 41], [31, 42], [31, 47], [31, 48], [31, 50], [31, 51], [31, 52], [32, 33], [32, 35], [32, 39], [32, 41], [32, 42], [32, 47], [32, 48], [33, 35], [33, 36], [33, 37], [33, 38], [33, 39], [33, 41], [33, 42], [33, 43], [33, 44], [33, 46], [33, 47], [33, 48], [33, 49], [33, 50], [33, 51], [33, 53], [34, 38], [34, 42], [34, 48], [35, 36], [35, 38], [35, 39], [35, 41], [35, 42], [35, 47], [35, 48], [35, 50], [35, 51], [35, 53], [36, 37], [36, 38], [36, 39], [36, 40], [36, 41], [36, 42], [36, 44], [36, 45], [36, 46], [36, 47], [36, 48], [36, 49], [36, 50], [36, 51], [36, 53], [37, 42], [37, 47], [37, 50], [38, 39], [38, 40], [38, 41], [38, 42], [38, 43], [38, 45], [38, 47], [38, 48], [38, 50], [38, 51], [39, 41], [39, 42], [39, 43], [39, 44], [39, 46], [39, 47], [39, 48], [39, 50], [39, 51], [40, 42], [40, 48], [41, 42], [41, 44], [41, 45], [41, 47], [41, 48], [41, 49], [41, 50], [41, 51], [42, 43], [42, 44], [42, 47], [42, 48], [42, 49], [42, 50], [42, 51], [42, 52], [42, 53], [43, 47], [43, 48], [43, 51], [44, 47], [44, 50], [44, 51], [45, 48], [45, 51], [46, 47], [46, 48], [46, 50], [46, 51], [47, 48], [47, 50], [47, 51], [47, 52], [48, 50], [48, 51], [48, 52], [48, 53], [49, 50], [50, 51]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l5-s3/tests/run.py b/tasks/construct-rlve-imp-party-l5-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-imp-party-l5-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-imp-party-l5-s3/tests/test.sh b/tasks/construct-rlve-imp-party-l5-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l5-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-imp-party-l5-s4/environment/Dockerfile b/tasks/construct-rlve-imp-party-l5-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l5-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-imp-party-l5-s4/environment/instance.json b/tasks/construct-rlve-imp-party-l5-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b9f15ee25d931f49bb2b9740ba07112c6363e988 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l5-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 18, "edges": [[0, 5], [0, 16], [0, 17], [0, 33], [0, 43], [1, 2], [1, 3], [1, 5], [1, 6], [1, 7], [1, 9], [1, 12], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 19], [1, 22], [1, 23], [1, 25], [1, 26], [1, 27], [1, 28], [1, 29], [1, 31], [1, 33], [1, 38], [1, 40], [1, 41], [1, 42], [1, 43], [1, 44], [1, 45], [1, 46], [1, 47], [1, 48], [1, 49], [1, 51], [1, 52], [1, 53], [2, 3], [2, 5], [2, 6], [2, 7], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 15], [2, 16], [2, 17], [2, 19], [2, 22], [2, 23], [2, 25], [2, 26], [2, 27], [2, 28], [2, 29], [2, 31], [2, 32], [2, 33], [2, 38], [2, 40], [2, 41], [2, 42], [2, 43], [2, 44], [2, 45], [2, 46], [2, 47], [2, 48], [2, 49], [2, 51], [2, 52], [2, 53], [3, 4], [3, 5], [3, 6], [3, 7], [3, 9], [3, 12], [3, 13], [3, 14], [3, 15], [3, 16], [3, 17], [3, 19], [3, 20], [3, 22], [3, 23], [3, 25], [3, 26], [3, 27], [3, 28], [3, 29], [3, 30], [3, 31], [3, 33], [3, 36], [3, 38], [3, 40], [3, 41], [3, 42], [3, 43], [3, 44], [3, 45], [3, 46], [3, 48], [3, 49], [3, 51], [3, 52], [3, 53], [4, 16], [4, 22], [4, 25], [4, 33], [4, 49], [4, 51], [5, 6], [5, 7], [5, 9], [5, 12], [5, 13], [5, 14], [5, 15], [5, 16], [5, 17], [5, 19], [5, 22], [5, 23], [5, 25], [5, 26], [5, 27], [5, 28], [5, 29], [5, 30], [5, 31], [5, 33], [5, 35], [5, 38], [5, 40], [5, 41], [5, 42], [5, 43], [5, 44], [5, 45], [5, 46], [5, 48], [5, 49], [5, 50], [5, 51], [5, 52], [5, 53], [6, 7], [6, 9], [6, 12], [6, 13], [6, 14], [6, 15], [6, 16], [6, 17], [6, 19], [6, 22], [6, 23], [6, 25], [6, 26], [6, 27], [6, 28], [6, 29], [6, 31], [6, 32], [6, 33], [6, 38], [6, 39], [6, 40], [6, 41], [6, 42], [6, 43], [6, 44], [6, 45], [6, 46], [6, 48], [6, 49], [6, 51], [6, 52], [6, 53], [7, 9], [7, 12], [7, 13], [7, 14], [7, 15], [7, 16], [7, 17], [7, 19], [7, 21], [7, 22], [7, 23], [7, 25], [7, 26], [7, 27], [7, 28], [7, 29], [7, 31], [7, 32], [7, 33], [7, 36], [7, 37], [7, 38], [7, 39], [7, 40], [7, 41], [7, 42], [7, 43], [7, 44], [7, 45], [7, 46], [7, 48], [7, 49], [7, 51], [7, 52], [7, 53], [8, 13], [8, 22], [8, 25], [8, 42], [8, 45], [8, 49], [9, 12], [9, 13], [9, 14], [9, 15], [9, 16], [9, 17], [9, 18], [9, 19], [9, 21], [9, 22], [9, 23], [9, 25], [9, 26], [9, 27], [9, 28], [9, 29], [9, 31], [9, 33], [9, 34], [9, 36], [9, 38], [9, 39], [9, 40], [9, 41], [9, 42], [9, 43], [9, 44], [9, 45], [9, 46], [9, 47], [9, 48], [9, 49], [9, 51], [9, 52], [9, 53], [10, 14], [10, 15], [10, 29], [10, 43], [10, 45], [11, 14], [11, 17], [11, 19], [11, 22], [11, 29], [11, 31], [11, 38], [11, 41], [11, 43], [11, 46], [11, 51], [11, 53], [12, 13], [12, 14], [12, 15], [12, 16], [12, 17], [12, 19], [12, 20], [12, 22], [12, 23], [12, 25], [12, 26], [12, 27], [12, 28], [12, 29], [12, 31], [12, 33], [12, 38], [12, 39], [12, 40], [12, 41], [12, 42], [12, 43], [12, 44], [12, 45], [12, 46], [12, 48], [12, 49], [12, 51], [12, 52], [12, 53], [13, 14], [13, 15], [13, 16], [13, 17], [13, 19], [13, 20], [13, 22], [13, 23], [13, 25], [13, 26], [13, 27], [13, 28], [13, 29], [13, 30], [13, 31], [13, 33], [13, 38], [13, 39], [13, 40], [13, 41], [13, 42], [13, 43], [13, 44], [13, 45], [13, 46], [13, 47], [13, 48], [13, 49], [13, 51], [13, 52], [13, 53], [14, 15], [14, 16], [14, 17], [14, 19], [14, 21], [14, 22], [14, 23], [14, 25], [14, 26], [14, 27], [14, 28], [14, 29], [14, 31], [14, 33], [14, 34], [14, 37], [14, 38], [14, 39], [14, 40], [14, 41], [14, 42], [14, 43], [14, 44], [14, 45], [14, 46], [14, 48], [14, 49], [14, 50], [14, 51], [14, 52], [14, 53], [15, 16], [15, 17], [15, 19], [15, 22], [15, 23], [15, 25], [15, 26], [15, 27], [15, 28], [15, 29], [15, 30], [15, 31], [15, 33], [15, 38], [15, 40], [15, 41], [15, 42], [15, 43], [15, 44], [15, 45], [15, 46], [15, 48], [15, 49], [15, 51], [15, 52], [15, 53], [16, 17], [16, 19], [16, 21], [16, 22], [16, 23], [16, 25], [16, 26], [16, 27], [16, 28], [16, 29], [16, 31], [16, 33], [16, 38], [16, 40], [16, 41], [16, 42], [16, 43], [16, 44], [16, 45], [16, 46], [16, 48], [16, 49], [16, 51], [16, 52], [16, 53], [17, 19], [17, 22], [17, 23], [17, 24], [17, 25], [17, 26], [17, 27], [17, 28], [17, 29], [17, 31], [17, 33], [17, 38], [17, 39], [17, 40], [17, 41], [17, 42], [17, 43], [17, 44], [17, 45], [17, 46], [17, 48], [17, 49], [17, 51], [17, 52], [17, 53], [18, 23], [18, 26], [18, 41], [18, 43], [18, 48], [19, 22], [19, 23], [19, 25], [19, 26], [19, 27], [19, 28], [19, 29], [19, 31], [19, 33], [19, 38], [19, 40], [19, 41], [19, 42], [19, 43], [19, 44], [19, 45], [19, 46], [19, 48], [19, 49], [19, 51], [19, 52], [19, 53], [20, 28], [20, 38], [20, 40], [20, 41], [20, 44], [21, 52], [22, 23], [22, 25], [22, 26], [22, 27], [22, 28], [22, 29], [22, 31], [22, 33], [22, 38], [22, 40], [22, 41], [22, 42], [22, 43], [22, 44], [22, 45], [22, 46], [22, 47], [22, 48], [22, 49], [22, 50], [22, 51], [22, 52], [22, 53], [23, 25], [23, 26], [23, 27], [23, 28], [23, 29], [23, 31], [23, 33], [23, 38], [23, 40], [23, 41], [23, 42], [23, 43], [23, 44], [23, 45], [23, 46], [23, 47], [23, 48], [23, 49], [23, 50], [23, 51], [23, 52], [23, 53], [24, 28], [24, 29], [24, 41], [24, 45], [24, 51], [24, 53], [25, 26], [25, 27], [25, 28], [25, 29], [25, 31], [25, 33], [25, 35], [25, 38], [25, 40], [25, 41], [25, 42], [25, 43], [25, 44], [25, 45], [25, 46], [25, 47], [25, 48], [25, 49], [25, 51], [25, 52], [25, 53], [26, 27], [26, 28], [26, 29], [26, 31], [26, 33], [26, 35], [26, 38], [26, 40], [26, 41], [26, 42], [26, 43], [26, 44], [26, 45], [26, 46], [26, 48], [26, 49], [26, 51], [26, 52], [26, 53], [27, 28], [27, 29], [27, 31], [27, 33], [27, 34], [27, 36], [27, 38], [27, 39], [27, 40], [27, 41], [27, 42], [27, 43], [27, 44], [27, 45], [27, 46], [27, 48], [27, 49], [27, 51], [27, 52], [27, 53], [28, 29], [28, 31], [28, 33], [28, 34], [28, 36], [28, 38], [28, 40], [28, 41], [28, 42], [28, 43], [28, 44], [28, 45], [28, 46], [28, 48], [28, 49], [28, 51], [28, 52], [28, 53], [29, 31], [29, 33], [29, 34], [29, 38], [29, 40], [29, 41], [29, 42], [29, 43], [29, 44], [29, 45], [29, 46], [29, 48], [29, 49], [29, 51], [29, 52], [29, 53], [30, 51], [31, 33], [31, 38], [31, 40], [31, 41], [31, 42], [31, 43], [31, 44], [31, 45], [31, 46], [31, 48], [31, 49], [31, 51], [31, 52], [31, 53], [32, 38], [32, 52], [33, 36], [33, 38], [33, 39], [33, 40], [33, 41], [33, 42], [33, 43], [33, 44], [33, 45], [33, 46], [33, 48], [33, 49], [33, 51], [33, 52], [33, 53], [34, 41], [34, 53], [35, 40], [35, 41], [35, 48], [35, 53], [36, 38], [36, 41], [37, 38], [37, 40], [37, 41], [37, 44], [38, 40], [38, 41], [38, 42], [38, 43], [38, 44], [38, 45], [38, 46], [38, 48], [38, 49], [38, 51], [38, 52], [38, 53], [39, 45], [39, 49], [39, 51], [40, 41], [40, 42], [40, 43], [40, 44], [40, 45], [40, 46], [40, 48], [40, 49], [40, 50], [40, 51], [40, 52], [40, 53], [41, 42], [41, 43], [41, 44], [41, 45], [41, 46], [41, 48], [41, 49], [41, 51], [41, 52], [41, 53], [42, 43], [42, 44], [42, 45], [42, 46], [42, 48], [42, 49], [42, 51], [42, 52], [42, 53], [43, 44], [43, 45], [43, 46], [43, 48], [43, 49], [43, 50], [43, 51], [43, 52], [43, 53], [44, 45], [44, 46], [44, 48], [44, 49], [44, 51], [44, 52], [44, 53], [45, 46], [45, 48], [45, 49], [45, 51], [45, 52], [45, 53], [46, 48], [46, 49], [46, 51], [46, 52], [46, 53], [47, 51], [48, 49], [48, 51], [48, 52], [48, 53], [49, 51], [49, 52], [49, 53], [51, 52], [51, 53], [52, 53]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l5-s4/solution/solve.sh b/tasks/construct-rlve-imp-party-l5-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..302bb496cd63512cb7c8fa15ab3ae5fd2830f4c1 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l5-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [2, 9, 14, 15, 16, 17, 19, 22, 23, 26, 28, 38, 41, 43, 45, 46, 49, 51]} +RLMATH_EOF diff --git a/tasks/construct-rlve-imp-party-l5-s4/tests/check.py b/tasks/construct-rlve-imp-party-l5-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..97b5a037a2ba8bf4495cf87cc074d1c60b11311c --- /dev/null +++ b/tasks/construct-rlve-imp-party-l5-s4/tests/check.py @@ -0,0 +1,14 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + c = int_list(ans.get("clique"), n, 0, 3 * n - 1, "clique") + if len(set(c)) != n: + raise Invalid("vertices must be distinct") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for i in range(n): + for j in range(i + 1, n): + if (min(c[i], c[j]), max(c[i], c[j])) not in es: + raise Invalid(f"{c[i]} and {c[j]} are not adjacent") + return None, {} diff --git a/tasks/construct-rlve-imp-party-l5-s4/tests/instance.json b/tasks/construct-rlve-imp-party-l5-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b9f15ee25d931f49bb2b9740ba07112c6363e988 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l5-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 18, "edges": [[0, 5], [0, 16], [0, 17], [0, 33], [0, 43], [1, 2], [1, 3], [1, 5], [1, 6], [1, 7], [1, 9], [1, 12], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 19], [1, 22], [1, 23], [1, 25], [1, 26], [1, 27], [1, 28], [1, 29], [1, 31], [1, 33], [1, 38], [1, 40], [1, 41], [1, 42], [1, 43], [1, 44], [1, 45], [1, 46], [1, 47], [1, 48], [1, 49], [1, 51], [1, 52], [1, 53], [2, 3], [2, 5], [2, 6], [2, 7], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 15], [2, 16], [2, 17], [2, 19], [2, 22], [2, 23], [2, 25], [2, 26], [2, 27], [2, 28], [2, 29], [2, 31], [2, 32], [2, 33], [2, 38], [2, 40], [2, 41], [2, 42], [2, 43], [2, 44], [2, 45], [2, 46], [2, 47], [2, 48], [2, 49], [2, 51], [2, 52], [2, 53], [3, 4], [3, 5], [3, 6], [3, 7], [3, 9], [3, 12], [3, 13], [3, 14], [3, 15], [3, 16], [3, 17], [3, 19], [3, 20], [3, 22], [3, 23], [3, 25], [3, 26], [3, 27], [3, 28], [3, 29], [3, 30], [3, 31], [3, 33], [3, 36], [3, 38], [3, 40], [3, 41], [3, 42], [3, 43], [3, 44], [3, 45], [3, 46], [3, 48], [3, 49], [3, 51], [3, 52], [3, 53], [4, 16], [4, 22], [4, 25], [4, 33], [4, 49], [4, 51], [5, 6], [5, 7], [5, 9], [5, 12], [5, 13], [5, 14], [5, 15], [5, 16], [5, 17], [5, 19], [5, 22], [5, 23], [5, 25], [5, 26], [5, 27], [5, 28], [5, 29], [5, 30], [5, 31], [5, 33], [5, 35], [5, 38], [5, 40], [5, 41], [5, 42], [5, 43], [5, 44], [5, 45], [5, 46], [5, 48], [5, 49], [5, 50], [5, 51], [5, 52], [5, 53], [6, 7], [6, 9], [6, 12], [6, 13], [6, 14], [6, 15], [6, 16], [6, 17], [6, 19], [6, 22], [6, 23], [6, 25], [6, 26], [6, 27], [6, 28], [6, 29], [6, 31], [6, 32], [6, 33], [6, 38], [6, 39], [6, 40], [6, 41], [6, 42], [6, 43], [6, 44], [6, 45], [6, 46], [6, 48], [6, 49], [6, 51], [6, 52], [6, 53], [7, 9], [7, 12], [7, 13], [7, 14], [7, 15], [7, 16], [7, 17], [7, 19], [7, 21], [7, 22], [7, 23], [7, 25], [7, 26], [7, 27], [7, 28], [7, 29], [7, 31], [7, 32], [7, 33], [7, 36], [7, 37], [7, 38], [7, 39], [7, 40], [7, 41], [7, 42], [7, 43], [7, 44], [7, 45], [7, 46], [7, 48], [7, 49], [7, 51], [7, 52], [7, 53], [8, 13], [8, 22], [8, 25], [8, 42], [8, 45], [8, 49], [9, 12], [9, 13], [9, 14], [9, 15], [9, 16], [9, 17], [9, 18], [9, 19], [9, 21], [9, 22], [9, 23], [9, 25], [9, 26], [9, 27], [9, 28], [9, 29], [9, 31], [9, 33], [9, 34], [9, 36], [9, 38], [9, 39], [9, 40], [9, 41], [9, 42], [9, 43], [9, 44], [9, 45], [9, 46], [9, 47], [9, 48], [9, 49], [9, 51], [9, 52], [9, 53], [10, 14], [10, 15], [10, 29], [10, 43], [10, 45], [11, 14], [11, 17], [11, 19], [11, 22], [11, 29], [11, 31], [11, 38], [11, 41], [11, 43], [11, 46], [11, 51], [11, 53], [12, 13], [12, 14], [12, 15], [12, 16], [12, 17], [12, 19], [12, 20], [12, 22], [12, 23], [12, 25], [12, 26], [12, 27], [12, 28], [12, 29], [12, 31], [12, 33], [12, 38], [12, 39], [12, 40], [12, 41], [12, 42], [12, 43], [12, 44], [12, 45], [12, 46], [12, 48], [12, 49], [12, 51], [12, 52], [12, 53], [13, 14], [13, 15], [13, 16], [13, 17], [13, 19], [13, 20], [13, 22], [13, 23], [13, 25], [13, 26], [13, 27], [13, 28], [13, 29], [13, 30], [13, 31], [13, 33], [13, 38], [13, 39], [13, 40], [13, 41], [13, 42], [13, 43], [13, 44], [13, 45], [13, 46], [13, 47], [13, 48], [13, 49], [13, 51], [13, 52], [13, 53], [14, 15], [14, 16], [14, 17], [14, 19], [14, 21], [14, 22], [14, 23], [14, 25], [14, 26], [14, 27], [14, 28], [14, 29], [14, 31], [14, 33], [14, 34], [14, 37], [14, 38], [14, 39], [14, 40], [14, 41], [14, 42], [14, 43], [14, 44], [14, 45], [14, 46], [14, 48], [14, 49], [14, 50], [14, 51], [14, 52], [14, 53], [15, 16], [15, 17], [15, 19], [15, 22], [15, 23], [15, 25], [15, 26], [15, 27], [15, 28], [15, 29], [15, 30], [15, 31], [15, 33], [15, 38], [15, 40], [15, 41], [15, 42], [15, 43], [15, 44], [15, 45], [15, 46], [15, 48], [15, 49], [15, 51], [15, 52], [15, 53], [16, 17], [16, 19], [16, 21], [16, 22], [16, 23], [16, 25], [16, 26], [16, 27], [16, 28], [16, 29], [16, 31], [16, 33], [16, 38], [16, 40], [16, 41], [16, 42], [16, 43], [16, 44], [16, 45], [16, 46], [16, 48], [16, 49], [16, 51], [16, 52], [16, 53], [17, 19], [17, 22], [17, 23], [17, 24], [17, 25], [17, 26], [17, 27], [17, 28], [17, 29], [17, 31], [17, 33], [17, 38], [17, 39], [17, 40], [17, 41], [17, 42], [17, 43], [17, 44], [17, 45], [17, 46], [17, 48], [17, 49], [17, 51], [17, 52], [17, 53], [18, 23], [18, 26], [18, 41], [18, 43], [18, 48], [19, 22], [19, 23], [19, 25], [19, 26], [19, 27], [19, 28], [19, 29], [19, 31], [19, 33], [19, 38], [19, 40], [19, 41], [19, 42], [19, 43], [19, 44], [19, 45], [19, 46], [19, 48], [19, 49], [19, 51], [19, 52], [19, 53], [20, 28], [20, 38], [20, 40], [20, 41], [20, 44], [21, 52], [22, 23], [22, 25], [22, 26], [22, 27], [22, 28], [22, 29], [22, 31], [22, 33], [22, 38], [22, 40], [22, 41], [22, 42], [22, 43], [22, 44], [22, 45], [22, 46], [22, 47], [22, 48], [22, 49], [22, 50], [22, 51], [22, 52], [22, 53], [23, 25], [23, 26], [23, 27], [23, 28], [23, 29], [23, 31], [23, 33], [23, 38], [23, 40], [23, 41], [23, 42], [23, 43], [23, 44], [23, 45], [23, 46], [23, 47], [23, 48], [23, 49], [23, 50], [23, 51], [23, 52], [23, 53], [24, 28], [24, 29], [24, 41], [24, 45], [24, 51], [24, 53], [25, 26], [25, 27], [25, 28], [25, 29], [25, 31], [25, 33], [25, 35], [25, 38], [25, 40], [25, 41], [25, 42], [25, 43], [25, 44], [25, 45], [25, 46], [25, 47], [25, 48], [25, 49], [25, 51], [25, 52], [25, 53], [26, 27], [26, 28], [26, 29], [26, 31], [26, 33], [26, 35], [26, 38], [26, 40], [26, 41], [26, 42], [26, 43], [26, 44], [26, 45], [26, 46], [26, 48], [26, 49], [26, 51], [26, 52], [26, 53], [27, 28], [27, 29], [27, 31], [27, 33], [27, 34], [27, 36], [27, 38], [27, 39], [27, 40], [27, 41], [27, 42], [27, 43], [27, 44], [27, 45], [27, 46], [27, 48], [27, 49], [27, 51], [27, 52], [27, 53], [28, 29], [28, 31], [28, 33], [28, 34], [28, 36], [28, 38], [28, 40], [28, 41], [28, 42], [28, 43], [28, 44], [28, 45], [28, 46], [28, 48], [28, 49], [28, 51], [28, 52], [28, 53], [29, 31], [29, 33], [29, 34], [29, 38], [29, 40], [29, 41], [29, 42], [29, 43], [29, 44], [29, 45], [29, 46], [29, 48], [29, 49], [29, 51], [29, 52], [29, 53], [30, 51], [31, 33], [31, 38], [31, 40], [31, 41], [31, 42], [31, 43], [31, 44], [31, 45], [31, 46], [31, 48], [31, 49], [31, 51], [31, 52], [31, 53], [32, 38], [32, 52], [33, 36], [33, 38], [33, 39], [33, 40], [33, 41], [33, 42], [33, 43], [33, 44], [33, 45], [33, 46], [33, 48], [33, 49], [33, 51], [33, 52], [33, 53], [34, 41], [34, 53], [35, 40], [35, 41], [35, 48], [35, 53], [36, 38], [36, 41], [37, 38], [37, 40], [37, 41], [37, 44], [38, 40], [38, 41], [38, 42], [38, 43], [38, 44], [38, 45], [38, 46], [38, 48], [38, 49], [38, 51], [38, 52], [38, 53], [39, 45], [39, 49], [39, 51], [40, 41], [40, 42], [40, 43], [40, 44], [40, 45], [40, 46], [40, 48], [40, 49], [40, 50], [40, 51], [40, 52], [40, 53], [41, 42], [41, 43], [41, 44], [41, 45], [41, 46], [41, 48], [41, 49], [41, 51], [41, 52], [41, 53], [42, 43], [42, 44], [42, 45], [42, 46], [42, 48], [42, 49], [42, 51], [42, 52], [42, 53], [43, 44], [43, 45], [43, 46], [43, 48], [43, 49], [43, 50], [43, 51], [43, 52], [43, 53], [44, 45], [44, 46], [44, 48], [44, 49], [44, 51], [44, 52], [44, 53], [45, 46], [45, 48], [45, 49], [45, 51], [45, 52], [45, 53], [46, 48], [46, 49], [46, 51], [46, 52], [46, 53], [47, 51], [48, 49], [48, 51], [48, 52], [48, 53], [49, 51], [49, 52], [49, 53], [51, 52], [51, 53], [52, 53]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l5-s4/tests/run.py b/tasks/construct-rlve-imp-party-l5-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-imp-party-l5-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-imp-party-l5-s4/tests/test.sh b/tasks/construct-rlve-imp-party-l5-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l5-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-integer-linear-system-l2-s3/environment/Dockerfile b/tasks/construct-rlve-integer-linear-system-l2-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l2-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-integer-linear-system-l2-s3/environment/instance.json b/tasks/construct-rlve-integer-linear-system-l2-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..374bda2bed6a3bf4c22b8408570b477fee4c0dd1 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l2-s3/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [[1, 1, 0, 1, 0], [0, 1, 1, 1, 0], [1, 0, 1, 1, 1], [0, 1, 1, 1, 1], [1, 0, 1, 0, 0], [0, 0, 1, 0, 1], [1, 0, 1, 1, 1], [0, 1, 1, 0, 1], [1, 1, 0, 1, 1], [1, 0, 0, 1, 0], [0, 1, 0, 0, 1]], "rhs": [10, 7, 15, 12, 5, 6, 15, 7, 15, 9, 6], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l2-s3/solution/solve.sh b/tasks/construct-rlve-integer-linear-system-l2-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2e8cb0ba37836f294f24cd76b2add8cc75e2119f --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l2-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [4, 1, 1, 5, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-integer-linear-system-l2-s3/tests/check.py b/tasks/construct-rlve-integer-linear-system-l2-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..ff19002b3fddc9597f84ee31ef5ffbee5d3fac32 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l2-s3/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = len(inst["coeffs"][0]) + x = int_list(ans.get("x"), n, name="x") + for k, (e, r) in enumerate(zip(inst["coeffs"], inst["rhs"])): + if sum(c * v for c, v in zip(e, x)) != r: + raise Invalid(f"equation {k} is violated") + return None, {} diff --git a/tasks/construct-rlve-integer-linear-system-l2-s3/tests/instance.json b/tasks/construct-rlve-integer-linear-system-l2-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..374bda2bed6a3bf4c22b8408570b477fee4c0dd1 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l2-s3/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [[1, 1, 0, 1, 0], [0, 1, 1, 1, 0], [1, 0, 1, 1, 1], [0, 1, 1, 1, 1], [1, 0, 1, 0, 0], [0, 0, 1, 0, 1], [1, 0, 1, 1, 1], [0, 1, 1, 0, 1], [1, 1, 0, 1, 1], [1, 0, 0, 1, 0], [0, 1, 0, 0, 1]], "rhs": [10, 7, 15, 12, 5, 6, 15, 7, 15, 9, 6], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l2-s3/tests/run.py b/tasks/construct-rlve-integer-linear-system-l2-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l2-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-integer-linear-system-l2-s3/tests/test.sh b/tasks/construct-rlve-integer-linear-system-l2-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l2-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-integer-linear-system-l2-s4/environment/Dockerfile b/tasks/construct-rlve-integer-linear-system-l2-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l2-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-integer-linear-system-l2-s4/environment/instance.json b/tasks/construct-rlve-integer-linear-system-l2-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..633e25a575ad918220bbcb2a650182e05a4638dd --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l2-s4/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [[0, 1, 0, 1, 0], [1, 0, 1, 0, 0], [1, 0, 0, 0, 1], [1, 1, 0, 0, 1], [0, 1, 1, 0, 0], [1, 0, 1, 1, 1], [0, 0, 1, 1, 1], [0, 1, 0, 0, 0], [1, 1, 1, 1, 1], [1, 1, 0, 0, 1]], "rhs": [6, 7, 6, 10, 8, 12, 9, 4, 16, 10], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l2-s4/solution/solve.sh b/tasks/construct-rlve-integer-linear-system-l2-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c1a627b36ded0a4dd32048a012885dd1452362a4 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l2-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [3, 4, 4, 2, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-integer-linear-system-l2-s4/tests/check.py b/tasks/construct-rlve-integer-linear-system-l2-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..ff19002b3fddc9597f84ee31ef5ffbee5d3fac32 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l2-s4/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = len(inst["coeffs"][0]) + x = int_list(ans.get("x"), n, name="x") + for k, (e, r) in enumerate(zip(inst["coeffs"], inst["rhs"])): + if sum(c * v for c, v in zip(e, x)) != r: + raise Invalid(f"equation {k} is violated") + return None, {} diff --git a/tasks/construct-rlve-integer-linear-system-l2-s4/tests/instance.json b/tasks/construct-rlve-integer-linear-system-l2-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..633e25a575ad918220bbcb2a650182e05a4638dd --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l2-s4/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [[0, 1, 0, 1, 0], [1, 0, 1, 0, 0], [1, 0, 0, 0, 1], [1, 1, 0, 0, 1], [0, 1, 1, 0, 0], [1, 0, 1, 1, 1], [0, 0, 1, 1, 1], [0, 1, 0, 0, 0], [1, 1, 1, 1, 1], [1, 1, 0, 0, 1]], "rhs": [6, 7, 6, 10, 8, 12, 9, 4, 16, 10], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l2-s4/tests/run.py b/tasks/construct-rlve-integer-linear-system-l2-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l2-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-integer-linear-system-l2-s4/tests/test.sh b/tasks/construct-rlve-integer-linear-system-l2-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l2-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-integer-linear-system-l6-s2/environment/Dockerfile b/tasks/construct-rlve-integer-linear-system-l6-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l6-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-integer-linear-system-l6-s2/environment/instance.json b/tasks/construct-rlve-integer-linear-system-l6-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..927affc94c121c4d93e1343af529fa210cede3b4 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l6-s2/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [[5, 3, 0, 1, 0, 1, 0, 1, 1, 4, 2, 0, 4, 0, 0, 5, 0, 0, 0, 1, 0, 0, 0, 3, 0, 1], [0, 3, 0, 0, 0, 4, 0, 1, 5, 1, 5, 0, 0, 5, 5, 0, 2, 4, 0, 4, 4, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 3, 5, 1, 0, 0, 0, 0, 1, 0, 0, 5, 5, 0, 2, 0, 5, 2, 0, 0, 0, 0], [1, 1, 0, 4, 4, 0, 0, 0, 4, 1, 0, 0, 0, 2, 4, 0, 4, 0, 0, 4, 5, 0, 0, 3, 0, 5], [0, 0, 0, 0, 2, 1, 4, 0, 0, 0, 4, 0, 4, 0, 0, 2, 1, 0, 0, 0, 0, 0, 4, 1, 0, 1], [1, 3, 0, 5, 3, 0, 3, 0, 0, 0, 3, 0, 0, 1, 0, 4, 0, 0, 0, 1, 0, 2, 0, 0, 1, 2], [0, 4, 2, 5, 0, 0, 0, 0, 4, 0, 3, 3, 0, 5, 3, 5, 1, 3, 0, 0, 0, 3, 4, 2, 0, 2], [2, 3, 0, 0, 0, 0, 0, 0, 5, 0, 4, 2, 0, 5, 0, 2, 1, 4, 0, 0, 1, 0, 0, 0, 0, 2], [0, 0, 4, 0, 0, 2, 0, 2, 0, 3, 3, 3, 0, 1, 1, 0, 0, 0, 3, 1, 1, 0, 0, 0, 5, 0], [2, 4, 0, 3, 3, 1, 0, 5, 0, 0, 0, 0, 0, 2, 3, 0, 5, 3, 4, 4, 1, 4, 5, 0, 2, 0], [5, 0, 3, 0, 3, 0, 3, 0, 5, 4, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 5, 3, 3], [0, 0, 3, 1, 4, 1, 0, 0, 0, 1, 0, 0, 2, 3, 3, 5, 0, 0, 2, 5, 1, 5, 0, 1, 0, 5], [2, 0, 2, 5, 0, 4, 0, 4, 0, 0, 4, 3, 2, 0, 0, 0, 3, 0, 2, 0, 0, 0, 0, 0, 0, 2], [0, 0, 3, 1, 4, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 2, 0, 1, 5, 2, 3, 0, 4], [0, 1, 0, 0, 4, 1, 0, 4, 0, 0, 3, 0, 1, 1, 1, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 1, 0, 0, 4, 0, 3, 4, 0, 1, 0, 4, 3, 0, 0, 5, 2, 1, 0, 5, 0, 1, 2, 0], [0, 2, 0, 0, 0, 1, 4, 0, 1, 0, 0, 0, 1, 0, 0, 5, 0, 0, 0, 0, 2, 0, 0, 0, 4, 0], [0, 1, 0, 4, 3, 0, 3, 5, 0, 0, 0, 0, 0, 4, 0, 0, 0, 1, 4, 5, 0, 0, 0, 0, 0, 0], [5, 0, 0, 4, 0, 0, 1, 4, 4, 4, 3, 0, 0, 5, 1, 5, 5, 0, 1, 0, 1, 3, 5, 0, 5, 3], [0, 0, 3, 0, 1, 0, 1, 4, 3, 2, 2, 0, 5, 0, 5, 0, 0, 0, 4, 3, 2, 0, 5, 4, 0, 3], [0, 2, 5, 0, 2, 1, 0, 5, 2, 0, 1, 0, 0, 0, 2, 0, 0, 5, 4, 5, 3, 5, 0, 3, 0, 2], [3, 0, 0, 1, 3, 0, 3, 1, 5, 0, 2, 4, 0, 1, 4, 0, 2, 0, 5, 0, 0, 0, 0, 4, 0, 0], [2, 0, 0, 5, 5, 0, 0, 0, 3, 0, 0, 0, 0, 4, 0, 2, 0, 0, 1, 1, 2, 0, 1, 0, 4, 4], [0, 0, 0, 0, 1, 0, 0, 2, 0, 2, 0, 3, 0, 0, 3, 5, 4, 0, 0, 2, 0, 0, 1, 1, 0, 0], [1, 5, 0, 4, 0, 0, 1, 4, 1, 2, 0, 0, 0, 1, 4, 0, 2, 0, 1, 3, 0, 5, 1, 2, 4, 4], [4, 0, 1, 0, 0, 1, 0, 0, 0, 0, 2, 5, 0, 1, 4, 0, 4, 2, 1, 1, 2, 5, 5, 0, 0, 4], [2, 0, 0, 5, 0, 0, 0, 5, 0, 2, 0, 0, 0, 0, 2, 0, 5, 0, 0, 3, 0, 3, 5, 0, 0, 0], [4, 5, 0, 4, 0, 3, 0, 2, 0, 4, 0, 3, 0, 0, 0, 5, 1, 0, 0, 0, 4, 0, 4, 0, 2, 0], [0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 2, 0, 1, 2, 4, 4, 1, 0, 0, 3, 0, 0, 0, 4, 2, 3], [0, 0, 0, 1, 5, 0, 0, 4, 4, 5, 0, 0, 3, 4, 2, 0, 0, 0, 0, 0, 4, 0, 0, 0, 4, 0], [0, 5, 5, 4, 1, 0, 0, 3, 4, 2, 0, 0, 0, 0, 4, 0, 2, 1, 0, 0, 0, 1, 0, 0, 4, 0], [3, 0, 1, 1, 5, 1, 0, 2, 1, 5, 0, 1, 5, 2, 5, 1, 0, 2, 5, 3, 5, 2, 0, 5, 0, 0], [0, 0, 4, 0, 0, 5, 0, 0, 2, 2, 0, 1, 0, 0, 0, 5, 0, 5, 0, 5, 0, 4, 0, 5, 2, 3], [1, 5, 1, 1, 0, 0, 1, 0, 0, 0, 0, 2, 3, 4, 1, 0, 5, 0, 0, 5, 2, 0, 5, 0, 0, 0], [5, 1, 3, 0, 4, 0, 3, 0, 4, 1, 0, 2, 3, 0, 0, 0, 0, 0, 0, 3, 2, 0, 2, 3, 0, 0], [5, 2, 0, 3, 0, 0, 5, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 5], [0, 5, 0, 0, 0, 5, 4, 0, 0, 3, 0, 0, 1, 0, 0, 0, 0, 2, 0, 0, 0, 5, 0, 0, 1, 2], [0, 0, 3, 5, 0, 0, 0, 2, 0, 0, 0, 1, 0, 3, 2, 0, 3, 0, 0, 0, 0, 1, 3, 0, 0, 0], [5, 3, 4, 3, 5, 0, 4, 0, 0, 4, 0, 0, 4, 0, 0, 1, 3, 0, 0, 4, 0, 0, 3, 0, 2, 0], [0, 2, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 2, 1, 0, 2], [0, 0, 2, 4, 0, 2, 0, 2, 2, 0, 1, 5, 1, 2, 0, 4, 0, 0, 0, 2, 1, 0, 0, 5, 1, 5], [0, 0, 5, 2, 1, 2, 0, 4, 2, 5, 0, 0, 0, 0, 0, 5, 0, 4, 2, 2, 3, 5, 0, 0, 4, 5], [4, 0, 0, 3, 5, 4, 3, 5, 1, 0, 0, 0, 2, 0, 0, 0, 5, 0, 1, 0, 0, 0, 0, 2, 0, 0], [5, 0, 0, 3, 0, 3, 5, 5, 0, 2, 0, 2, 4, 1, 0, 0, 2, 0, 2, 0, 0, 4, 0, 2, 3, 0], [2, 0, 1, 0, 0, 5, 0, 2, 0, 0, 0, 5, 4, 0, 0, 0, 4, 0, 2, 0, 2, 0, 3, 1, 5, 0], [4, 0, 1, 0, 5, 4, 0, 3, 0, 4, 0, 5, 3, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0], [5, 3, 0, 0, 0, 0, 5, 2, 3, 0, 5, 0, 5, 1, 2, 0, 0, 4, 3, 0, 0, 2, 0, 0, 0, 0], [4, 3, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 5, 0, 4, 3, 3, 1, 0, 0, 4, 0, 0], [4, 4, 0, 0, 3, 2, 1, 0, 4, 4, 2, 2, 0, 0, 4, 0, 2, 1, 4, 0, 4, 0, 0, 3, 0, 2], [4, 5, 0, 5, 0, 1, 0, 0, 0, 0, 0, 4, 0, 2, 1, 0, 2, 0, 0, 0, 0, 0, 0, 1, 0, 0], [5, 0, 0, 2, 0, 1, 0, 4, 0, 2, 0, 0, 3, 4, 0, 0, 3, 3, 1, 4, 0, 3, 1, 0, 5, 0], [3, 0, 4, 0, 1, 3, 1, 0, 3, 0, 3, 0, 2, 5, 0, 2, 5, 3, 0, 2, 1, 0, 4, 1, 4, 5], [0, 1, 0, 2, 0, 2, 2, 4, 0, 4, 0, 0, 2, 0, 4, 1, 1, 3, 4, 5, 3, 0, 4, 4, 0, 0], [0, 2, 3, 3, 0, 5, 0, 0, 0, 0, 0, 4, 5, 3, 0, 1, 0, 5, 0, 0, 3, 1, 5, 3, 0, 0], [1, 0, 0, 0, 2, 5, 0, 2, 0, 1, 0, 5, 1, 0, 3, 0, 4, 5, 2, 0, 3, 0, 0, 0, 1, 0], [0, 0, 1, 0, 0, 0, 0, 2, 3, 0, 0, 3, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 4, 0, 0, 4], [0, 5, 0, 0, 1, 0, 3, 2, 0, 0, 4, 2, 4, 0, 0, 0, 5, 3, 0, 0, 2, 0, 1, 5, 4, 0], [0, 0, 3, 0, 0, 5, 0, 0, 0, 5, 2, 0, 0, 1, 5, 2, 0, 0, 2, 0, 0, 5, 1, 3, 3, 2], [3, 0, 0, 0, 0, 5, 3, 0, 5, 0, 2, 3, 3, 3, 1, 3, 0, 2, 0, 0, 5, 4, 0, 4, 0, 0], [4, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 5, 0, 0, 0, 0, 1, 1, 0, 0, 0, 3, 2, 0, 0, 0], [2, 5, 0, 0, 2, 0, 4, 2, 3, 3, 5, 1, 5, 2, 3, 3, 2, 3, 5, 0, 1, 5, 1, 0, 2, 0], [0, 0, 2, 0, 4, 3, 0, 0, 0, 0, 5, 3, 0, 5, 5, 4, 3, 0, 2, 0, 4, 0, 0, 0, 5, 3]], "rhs": [240, 561, 347, 500, 219, 276, 560, 360, 292, 634, 218, 385, 385, 226, 182, 411, 203, 363, 704, 445, 503, 233, 424, 228, 506, 477, 434, 510, 272, 446, 356, 536, 467, 443, 238, 233, 303, 329, 369, 285, 442, 613, 360, 443, 445, 290, 324, 291, 391, 267, 542, 639, 568, 623, 483, 243, 469, 372, 494, 181, 513, 553], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l6-s2/solution/solve.sh b/tasks/construct-rlve-integer-linear-system-l6-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a191a95d98fb91cfc39889ba3e18070e414a73df --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l6-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [2, 6, 2, 20, 3, 17, 5, 18, 2, 9, 6, 7, 8, 21, 7, 6, 14, 26, 2, 9, 25, 7, 18, 7, 16, 15]} +RLMATH_EOF diff --git a/tasks/construct-rlve-integer-linear-system-l6-s2/tests/check.py b/tasks/construct-rlve-integer-linear-system-l6-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..ff19002b3fddc9597f84ee31ef5ffbee5d3fac32 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l6-s2/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = len(inst["coeffs"][0]) + x = int_list(ans.get("x"), n, name="x") + for k, (e, r) in enumerate(zip(inst["coeffs"], inst["rhs"])): + if sum(c * v for c, v in zip(e, x)) != r: + raise Invalid(f"equation {k} is violated") + return None, {} diff --git a/tasks/construct-rlve-integer-linear-system-l6-s2/tests/instance.json b/tasks/construct-rlve-integer-linear-system-l6-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..927affc94c121c4d93e1343af529fa210cede3b4 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l6-s2/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [[5, 3, 0, 1, 0, 1, 0, 1, 1, 4, 2, 0, 4, 0, 0, 5, 0, 0, 0, 1, 0, 0, 0, 3, 0, 1], [0, 3, 0, 0, 0, 4, 0, 1, 5, 1, 5, 0, 0, 5, 5, 0, 2, 4, 0, 4, 4, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 3, 5, 1, 0, 0, 0, 0, 1, 0, 0, 5, 5, 0, 2, 0, 5, 2, 0, 0, 0, 0], [1, 1, 0, 4, 4, 0, 0, 0, 4, 1, 0, 0, 0, 2, 4, 0, 4, 0, 0, 4, 5, 0, 0, 3, 0, 5], [0, 0, 0, 0, 2, 1, 4, 0, 0, 0, 4, 0, 4, 0, 0, 2, 1, 0, 0, 0, 0, 0, 4, 1, 0, 1], [1, 3, 0, 5, 3, 0, 3, 0, 0, 0, 3, 0, 0, 1, 0, 4, 0, 0, 0, 1, 0, 2, 0, 0, 1, 2], [0, 4, 2, 5, 0, 0, 0, 0, 4, 0, 3, 3, 0, 5, 3, 5, 1, 3, 0, 0, 0, 3, 4, 2, 0, 2], [2, 3, 0, 0, 0, 0, 0, 0, 5, 0, 4, 2, 0, 5, 0, 2, 1, 4, 0, 0, 1, 0, 0, 0, 0, 2], [0, 0, 4, 0, 0, 2, 0, 2, 0, 3, 3, 3, 0, 1, 1, 0, 0, 0, 3, 1, 1, 0, 0, 0, 5, 0], [2, 4, 0, 3, 3, 1, 0, 5, 0, 0, 0, 0, 0, 2, 3, 0, 5, 3, 4, 4, 1, 4, 5, 0, 2, 0], [5, 0, 3, 0, 3, 0, 3, 0, 5, 4, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 5, 3, 3], [0, 0, 3, 1, 4, 1, 0, 0, 0, 1, 0, 0, 2, 3, 3, 5, 0, 0, 2, 5, 1, 5, 0, 1, 0, 5], [2, 0, 2, 5, 0, 4, 0, 4, 0, 0, 4, 3, 2, 0, 0, 0, 3, 0, 2, 0, 0, 0, 0, 0, 0, 2], [0, 0, 3, 1, 4, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 2, 0, 1, 5, 2, 3, 0, 4], [0, 1, 0, 0, 4, 1, 0, 4, 0, 0, 3, 0, 1, 1, 1, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 1, 0, 0, 4, 0, 3, 4, 0, 1, 0, 4, 3, 0, 0, 5, 2, 1, 0, 5, 0, 1, 2, 0], [0, 2, 0, 0, 0, 1, 4, 0, 1, 0, 0, 0, 1, 0, 0, 5, 0, 0, 0, 0, 2, 0, 0, 0, 4, 0], [0, 1, 0, 4, 3, 0, 3, 5, 0, 0, 0, 0, 0, 4, 0, 0, 0, 1, 4, 5, 0, 0, 0, 0, 0, 0], [5, 0, 0, 4, 0, 0, 1, 4, 4, 4, 3, 0, 0, 5, 1, 5, 5, 0, 1, 0, 1, 3, 5, 0, 5, 3], [0, 0, 3, 0, 1, 0, 1, 4, 3, 2, 2, 0, 5, 0, 5, 0, 0, 0, 4, 3, 2, 0, 5, 4, 0, 3], [0, 2, 5, 0, 2, 1, 0, 5, 2, 0, 1, 0, 0, 0, 2, 0, 0, 5, 4, 5, 3, 5, 0, 3, 0, 2], [3, 0, 0, 1, 3, 0, 3, 1, 5, 0, 2, 4, 0, 1, 4, 0, 2, 0, 5, 0, 0, 0, 0, 4, 0, 0], [2, 0, 0, 5, 5, 0, 0, 0, 3, 0, 0, 0, 0, 4, 0, 2, 0, 0, 1, 1, 2, 0, 1, 0, 4, 4], [0, 0, 0, 0, 1, 0, 0, 2, 0, 2, 0, 3, 0, 0, 3, 5, 4, 0, 0, 2, 0, 0, 1, 1, 0, 0], [1, 5, 0, 4, 0, 0, 1, 4, 1, 2, 0, 0, 0, 1, 4, 0, 2, 0, 1, 3, 0, 5, 1, 2, 4, 4], [4, 0, 1, 0, 0, 1, 0, 0, 0, 0, 2, 5, 0, 1, 4, 0, 4, 2, 1, 1, 2, 5, 5, 0, 0, 4], [2, 0, 0, 5, 0, 0, 0, 5, 0, 2, 0, 0, 0, 0, 2, 0, 5, 0, 0, 3, 0, 3, 5, 0, 0, 0], [4, 5, 0, 4, 0, 3, 0, 2, 0, 4, 0, 3, 0, 0, 0, 5, 1, 0, 0, 0, 4, 0, 4, 0, 2, 0], [0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 2, 0, 1, 2, 4, 4, 1, 0, 0, 3, 0, 0, 0, 4, 2, 3], [0, 0, 0, 1, 5, 0, 0, 4, 4, 5, 0, 0, 3, 4, 2, 0, 0, 0, 0, 0, 4, 0, 0, 0, 4, 0], [0, 5, 5, 4, 1, 0, 0, 3, 4, 2, 0, 0, 0, 0, 4, 0, 2, 1, 0, 0, 0, 1, 0, 0, 4, 0], [3, 0, 1, 1, 5, 1, 0, 2, 1, 5, 0, 1, 5, 2, 5, 1, 0, 2, 5, 3, 5, 2, 0, 5, 0, 0], [0, 0, 4, 0, 0, 5, 0, 0, 2, 2, 0, 1, 0, 0, 0, 5, 0, 5, 0, 5, 0, 4, 0, 5, 2, 3], [1, 5, 1, 1, 0, 0, 1, 0, 0, 0, 0, 2, 3, 4, 1, 0, 5, 0, 0, 5, 2, 0, 5, 0, 0, 0], [5, 1, 3, 0, 4, 0, 3, 0, 4, 1, 0, 2, 3, 0, 0, 0, 0, 0, 0, 3, 2, 0, 2, 3, 0, 0], [5, 2, 0, 3, 0, 0, 5, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 5], [0, 5, 0, 0, 0, 5, 4, 0, 0, 3, 0, 0, 1, 0, 0, 0, 0, 2, 0, 0, 0, 5, 0, 0, 1, 2], [0, 0, 3, 5, 0, 0, 0, 2, 0, 0, 0, 1, 0, 3, 2, 0, 3, 0, 0, 0, 0, 1, 3, 0, 0, 0], [5, 3, 4, 3, 5, 0, 4, 0, 0, 4, 0, 0, 4, 0, 0, 1, 3, 0, 0, 4, 0, 0, 3, 0, 2, 0], [0, 2, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 2, 1, 0, 2], [0, 0, 2, 4, 0, 2, 0, 2, 2, 0, 1, 5, 1, 2, 0, 4, 0, 0, 0, 2, 1, 0, 0, 5, 1, 5], [0, 0, 5, 2, 1, 2, 0, 4, 2, 5, 0, 0, 0, 0, 0, 5, 0, 4, 2, 2, 3, 5, 0, 0, 4, 5], [4, 0, 0, 3, 5, 4, 3, 5, 1, 0, 0, 0, 2, 0, 0, 0, 5, 0, 1, 0, 0, 0, 0, 2, 0, 0], [5, 0, 0, 3, 0, 3, 5, 5, 0, 2, 0, 2, 4, 1, 0, 0, 2, 0, 2, 0, 0, 4, 0, 2, 3, 0], [2, 0, 1, 0, 0, 5, 0, 2, 0, 0, 0, 5, 4, 0, 0, 0, 4, 0, 2, 0, 2, 0, 3, 1, 5, 0], [4, 0, 1, 0, 5, 4, 0, 3, 0, 4, 0, 5, 3, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0], [5, 3, 0, 0, 0, 0, 5, 2, 3, 0, 5, 0, 5, 1, 2, 0, 0, 4, 3, 0, 0, 2, 0, 0, 0, 0], [4, 3, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 5, 0, 4, 3, 3, 1, 0, 0, 4, 0, 0], [4, 4, 0, 0, 3, 2, 1, 0, 4, 4, 2, 2, 0, 0, 4, 0, 2, 1, 4, 0, 4, 0, 0, 3, 0, 2], [4, 5, 0, 5, 0, 1, 0, 0, 0, 0, 0, 4, 0, 2, 1, 0, 2, 0, 0, 0, 0, 0, 0, 1, 0, 0], [5, 0, 0, 2, 0, 1, 0, 4, 0, 2, 0, 0, 3, 4, 0, 0, 3, 3, 1, 4, 0, 3, 1, 0, 5, 0], [3, 0, 4, 0, 1, 3, 1, 0, 3, 0, 3, 0, 2, 5, 0, 2, 5, 3, 0, 2, 1, 0, 4, 1, 4, 5], [0, 1, 0, 2, 0, 2, 2, 4, 0, 4, 0, 0, 2, 0, 4, 1, 1, 3, 4, 5, 3, 0, 4, 4, 0, 0], [0, 2, 3, 3, 0, 5, 0, 0, 0, 0, 0, 4, 5, 3, 0, 1, 0, 5, 0, 0, 3, 1, 5, 3, 0, 0], [1, 0, 0, 0, 2, 5, 0, 2, 0, 1, 0, 5, 1, 0, 3, 0, 4, 5, 2, 0, 3, 0, 0, 0, 1, 0], [0, 0, 1, 0, 0, 0, 0, 2, 3, 0, 0, 3, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 4, 0, 0, 4], [0, 5, 0, 0, 1, 0, 3, 2, 0, 0, 4, 2, 4, 0, 0, 0, 5, 3, 0, 0, 2, 0, 1, 5, 4, 0], [0, 0, 3, 0, 0, 5, 0, 0, 0, 5, 2, 0, 0, 1, 5, 2, 0, 0, 2, 0, 0, 5, 1, 3, 3, 2], [3, 0, 0, 0, 0, 5, 3, 0, 5, 0, 2, 3, 3, 3, 1, 3, 0, 2, 0, 0, 5, 4, 0, 4, 0, 0], [4, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 5, 0, 0, 0, 0, 1, 1, 0, 0, 0, 3, 2, 0, 0, 0], [2, 5, 0, 0, 2, 0, 4, 2, 3, 3, 5, 1, 5, 2, 3, 3, 2, 3, 5, 0, 1, 5, 1, 0, 2, 0], [0, 0, 2, 0, 4, 3, 0, 0, 0, 0, 5, 3, 0, 5, 5, 4, 3, 0, 2, 0, 4, 0, 0, 0, 5, 3]], "rhs": [240, 561, 347, 500, 219, 276, 560, 360, 292, 634, 218, 385, 385, 226, 182, 411, 203, 363, 704, 445, 503, 233, 424, 228, 506, 477, 434, 510, 272, 446, 356, 536, 467, 443, 238, 233, 303, 329, 369, 285, 442, 613, 360, 443, 445, 290, 324, 291, 391, 267, 542, 639, 568, 623, 483, 243, 469, 372, 494, 181, 513, 553], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l6-s2/tests/run.py b/tasks/construct-rlve-integer-linear-system-l6-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l6-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-integer-linear-system-l6-s2/tests/test.sh b/tasks/construct-rlve-integer-linear-system-l6-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l6-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-integer-linear-system-l6-s5/environment/Dockerfile b/tasks/construct-rlve-integer-linear-system-l6-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l6-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-integer-linear-system-l6-s5/environment/instance.json b/tasks/construct-rlve-integer-linear-system-l6-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8a4f8125057558ac65bb94eb2828c7fd3d964f9c --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l6-s5/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [[0, 1, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 4, 0, 2, 2, 0, 0, 4, 3, 3, 0, 0, 5, 0], [1, 0, 5, 0, 0, 5, 2, 2, 0, 0, 0, 2, 3, 0, 0, 0, 0, 0, 0, 2, 0, 0, 3, 2, 1, 2], [0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 2, 3, 0, 0, 0, 0, 5, 0, 1, 0, 5, 1, 0, 0, 0, 0], [0, 5, 0, 4, 5, 2, 5, 0, 0, 2, 0, 4, 3, 4, 0, 0, 2, 0, 3, 4, 0, 3, 0, 4, 5, 2], [3, 0, 0, 0, 0, 0, 0, 0, 2, 1, 3, 5, 3, 5, 4, 0, 0, 5, 0, 4, 0, 0, 0, 0, 0, 0], [0, 0, 2, 4, 5, 0, 0, 0, 5, 0, 0, 2, 3, 0, 2, 0, 0, 5, 0, 0, 2, 5, 4, 2, 3, 0], [0, 3, 0, 3, 2, 1, 0, 0, 0, 2, 3, 0, 0, 3, 2, 0, 0, 5, 2, 3, 5, 0, 0, 0, 0, 0], [2, 5, 4, 4, 0, 0, 2, 0, 4, 1, 0, 2, 4, 4, 2, 3, 5, 0, 3, 1, 0, 0, 3, 0, 2, 0], [0, 0, 0, 5, 5, 4, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 4, 5, 0, 5, 0, 5, 3, 0, 5, 2], [0, 0, 5, 2, 2, 0, 0, 0, 3, 5, 4, 0, 3, 5, 4, 3, 0, 0, 1, 0, 0, 5, 5, 0, 0, 0], [0, 0, 2, 0, 0, 0, 0, 0, 2, 5, 3, 2, 0, 3, 3, 1, 5, 4, 0, 0, 0, 1, 4, 3, 4, 0], [0, 3, 1, 0, 2, 3, 5, 0, 5, 2, 0, 5, 1, 1, 5, 0, 1, 0, 0, 0, 2, 1, 0, 0, 0, 4], [0, 2, 0, 5, 0, 0, 2, 1, 3, 3, 0, 0, 4, 0, 0, 0, 0, 5, 0, 0, 0, 2, 4, 0, 0, 0], [0, 3, 5, 0, 0, 0, 1, 4, 0, 1, 0, 3, 0, 0, 4, 0, 0, 0, 4, 0, 0, 5, 0, 2, 0, 1], [0, 0, 5, 0, 4, 2, 4, 0, 0, 1, 4, 4, 0, 0, 2, 3, 4, 3, 5, 0, 3, 0, 0, 0, 0, 4], [0, 1, 0, 4, 4, 4, 0, 1, 2, 1, 0, 1, 0, 5, 0, 3, 0, 0, 4, 0, 0, 3, 0, 3, 2, 0], [5, 2, 0, 0, 4, 2, 0, 2, 0, 0, 4, 2, 5, 0, 0, 0, 0, 3, 5, 3, 1, 0, 0, 0, 3, 0], [0, 2, 3, 0, 5, 0, 0, 3, 4, 1, 0, 4, 0, 3, 2, 5, 5, 5, 3, 3, 0, 2, 0, 5, 5, 4], [1, 0, 0, 1, 0, 4, 5, 0, 0, 4, 0, 0, 2, 4, 0, 0, 3, 2, 0, 0, 5, 3, 0, 0, 0, 0], [2, 0, 0, 5, 0, 1, 1, 0, 3, 0, 2, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 3, 0, 2, 0, 0], [4, 1, 5, 3, 0, 0, 0, 0, 4, 2, 0, 0, 0, 0, 4, 4, 5, 5, 3, 1, 0, 1, 2, 0, 2, 2], [5, 4, 0, 5, 0, 3, 3, 5, 0, 0, 0, 0, 0, 0, 5, 0, 4, 1, 5, 4, 0, 0, 5, 0, 2, 0], [1, 4, 1, 4, 0, 3, 4, 3, 0, 1, 5, 5, 0, 0, 0, 2, 0, 1, 0, 0, 0, 4, 1, 2, 0, 0], [0, 4, 0, 0, 0, 0, 0, 5, 4, 0, 2, 3, 0, 0, 1, 5, 3, 5, 4, 0, 0, 1, 4, 0, 0, 0], [0, 5, 0, 3, 0, 4, 0, 4, 3, 5, 0, 5, 0, 0, 0, 2, 4, 0, 5, 0, 2, 1, 0, 2, 0, 0], [4, 0, 0, 4, 0, 4, 0, 4, 0, 0, 0, 0, 5, 5, 4, 0, 2, 3, 0, 0, 0, 1, 2, 0, 2, 3], [1, 3, 0, 5, 1, 5, 0, 0, 0, 0, 0, 2, 3, 0, 0, 1, 0, 3, 2, 0, 5, 0, 0, 3, 2, 0], [0, 4, 5, 3, 0, 1, 0, 0, 1, 0, 5, 1, 2, 5, 1, 0, 0, 5, 4, 5, 3, 0, 0, 1, 0, 0], [1, 1, 3, 2, 1, 5, 1, 4, 2, 1, 0, 0, 0, 0, 5, 0, 0, 2, 0, 0, 0, 0, 0, 5, 3, 2], [0, 0, 1, 3, 5, 4, 4, 5, 0, 0, 0, 0, 0, 5, 4, 3, 0, 2, 0, 0, 0, 0, 5, 2, 0, 1], [1, 0, 5, 5, 0, 4, 0, 0, 2, 0, 5, 2, 0, 0, 2, 5, 3, 2, 4, 0, 0, 5, 0, 3, 4, 2], [0, 0, 4, 5, 5, 0, 3, 2, 0, 3, 0, 0, 0, 2, 5, 0, 0, 0, 5, 2, 2, 0, 0, 2, 1, 3], [0, 0, 2, 0, 2, 4, 3, 0, 0, 0, 1, 2, 1, 4, 5, 2, 0, 0, 1, 0, 0, 0, 4, 0, 5, 0], [3, 4, 0, 0, 5, 0, 0, 5, 1, 3, 0, 0, 0, 0, 5, 0, 0, 5, 0, 0, 0, 2, 0, 0, 0, 2], [0, 0, 0, 1, 3, 0, 0, 2, 0, 5, 3, 0, 1, 0, 4, 0, 0, 2, 0, 2, 2, 1, 0, 0, 2, 2], [0, 3, 4, 0, 5, 3, 0, 2, 5, 0, 0, 5, 1, 0, 2, 0, 2, 0, 3, 0, 2, 0, 0, 4, 5, 0], [0, 1, 0, 5, 3, 0, 0, 4, 2, 3, 1, 0, 0, 0, 2, 3, 1, 0, 3, 0, 0, 1, 0, 0, 0, 0], [0, 0, 4, 0, 0, 0, 3, 5, 0, 1, 1, 2, 0, 0, 0, 0, 0, 2, 5, 0, 0, 5, 0, 0, 0, 0], [0, 0, 0, 5, 0, 1, 4, 3, 1, 4, 4, 5, 5, 5, 0, 0, 2, 1, 0, 0, 4, 1, 0, 5, 5, 4], [4, 1, 0, 5, 2, 0, 3, 0, 2, 2, 2, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 5, 4, 0, 0, 0], [0, 0, 1, 0, 0, 3, 5, 0, 0, 0, 3, 3, 4, 4, 0, 3, 5, 2, 3, 4, 0, 5, 5, 0, 2, 0], [1, 0, 0, 0, 2, 0, 1, 4, 1, 0, 0, 1, 5, 0, 2, 3, 5, 0, 0, 2, 0, 2, 2, 0, 0, 0], [0, 0, 4, 3, 3, 0, 1, 0, 0, 0, 4, 0, 3, 2, 0, 0, 0, 4, 0, 1, 0, 0, 0, 3, 5, 5], [0, 1, 1, 0, 0, 4, 0, 1, 0, 0, 0, 5, 2, 0, 0, 0, 0, 0, 1, 1, 0, 0, 5, 0, 0, 0], [0, 0, 3, 3, 3, 0, 3, 0, 1, 0, 0, 1, 0, 0, 3, 0, 4, 0, 0, 5, 4, 0, 5, 0, 4, 0], [5, 0, 2, 0, 5, 0, 5, 0, 5, 2, 5, 5, 0, 3, 5, 0, 0, 1, 0, 0, 0, 3, 0, 5, 1, 4], [0, 2, 3, 2, 3, 0, 3, 0, 0, 0, 0, 0, 2, 4, 0, 3, 1, 0, 0, 0, 5, 0, 0, 2, 0, 0], [5, 3, 0, 0, 2, 0, 0, 3, 0, 0, 0, 0, 4, 4, 0, 4, 4, 4, 0, 0, 5, 0, 0, 1, 1, 4], [5, 4, 1, 1, 0, 1, 0, 1, 2, 0, 1, 0, 0, 4, 0, 2, 1, 2, 2, 3, 1, 2, 4, 4, 0, 0], [0, 3, 0, 4, 0, 4, 5, 0, 1, 4, 2, 0, 0, 4, 4, 0, 3, 0, 4, 2, 0, 3, 0, 0, 2, 0], [0, 0, 4, 1, 0, 4, 1, 0, 0, 3, 0, 3, 0, 1, 2, 0, 0, 5, 2, 0, 0, 0, 0, 0, 0, 2], [1, 2, 0, 4, 0, 0, 4, 2, 0, 0, 5, 1, 3, 0, 0, 1, 0, 0, 0, 0, 1, 4, 3, 1, 0, 5], [0, 0, 1, 3, 0, 0, 0, 0, 5, 1, 4, 0, 3, 3, 4, 3, 3, 0, 0, 3, 3, 0, 0, 1, 0, 0], [1, 2, 3, 0, 0, 0, 1, 2, 1, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0], [2, 4, 0, 5, 4, 0, 2, 1, 0, 0, 0, 1, 2, 1, 4, 4, 0, 0, 0, 1, 0, 0, 0, 0, 4, 2], [0, 2, 3, 1, 2, 0, 0, 4, 4, 0, 0, 5, 2, 0, 0, 0, 0, 0, 1, 0, 0, 4, 1, 3, 0, 5], [0, 2, 0, 0, 2, 0, 2, 2, 0, 0, 0, 0, 5, 3, 3, 4, 0, 0, 5, 1, 0, 0, 0, 0, 0, 4], [2, 0, 0, 1, 4, 0, 4, 1, 2, 2, 0, 4, 0, 2, 0, 2, 1, 0, 0, 0, 0, 0, 5, 0, 5, 0], [2, 0, 5, 5, 1, 0, 4, 1, 2, 0, 2, 4, 0, 0, 0, 5, 5, 3, 3, 0, 0, 0, 0, 5, 5, 3], [3, 3, 0, 5, 4, 4, 1, 0, 0, 0, 0, 0, 0, 4, 4, 0, 0, 0, 5, 0, 4, 0, 4, 2, 2, 5], [3, 0, 0, 0, 0, 3, 5, 0, 5, 3, 5, 0, 0, 3, 0, 3, 0, 5, 0, 0, 0, 0, 0, 0, 2, 0], [5, 1, 0, 5, 0, 5, 4, 2, 3, 1, 3, 1, 0, 1, 4, 0, 0, 4, 4, 3, 1, 0, 3, 5, 1, 0], [0, 0, 1, 0, 4, 0, 0, 0, 1, 0, 1, 5, 1, 0, 0, 0, 2, 1, 2, 5, 0, 0, 0, 0, 0, 4], [0, 3, 0, 1, 0, 0, 1, 2, 4, 0, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 4, 1], [0, 0, 0, 0, 5, 0, 0, 2, 1, 0, 2, 3, 1, 3, 0, 0, 5, 4, 3, 0, 0, 3, 1, 5, 2, 4], [1, 3, 3, 0, 0, 0, 0, 4, 0, 3, 2, 1, 0, 3, 0, 2, 0, 2, 3, 4, 2, 0, 0, 5, 0, 0], [1, 3, 0, 0, 0, 2, 0, 0, 4, 0, 5, 4, 0, 0, 0, 4, 0, 0, 2, 0, 4, 0, 0, 0, 5, 0], [1, 0, 0, 2, 0, 3, 0, 2, 4, 0, 2, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 5, 0, 0], [4, 0, 5, 0, 0, 4, 0, 0, 0, 2, 0, 0, 0, 0, 3, 5, 2, 0, 0, 4, 2, 2, 3, 0, 3, 2], [3, 2, 0, 4, 4, 4, 0, 0, 0, 4, 0, 5, 1, 4, 0, 2, 0, 2, 3, 3, 1, 0, 4, 4, 4, 2], [1, 2, 0, 5, 3, 2, 5, 1, 0, 0, 5, 0, 3, 3, 2, 0, 2, 0, 0, 0, 2, 0, 5, 0, 0, 0], [3, 0, 0, 5, 0, 0, 5, 4, 5, 1, 4, 0, 0, 3, 2, 5, 1, 4, 1, 2, 0, 0, 0, 0, 0, 5]], "rhs": [325, 338, 315, 758, 340, 444, 445, 581, 590, 453, 574, 463, 337, 442, 713, 404, 529, 891, 409, 254, 617, 735, 508, 532, 560, 505, 366, 594, 523, 545, 686, 661, 390, 492, 446, 566, 400, 447, 823, 367, 627, 379, 603, 140, 542, 708, 342, 565, 450, 620, 334, 525, 414, 199, 448, 452, 418, 422, 823, 618, 476, 715, 371, 363, 678, 539, 382, 279, 433, 612, 535, 734], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l6-s5/solution/solve.sh b/tasks/construct-rlve-integer-linear-system-l6-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..da85f9c59c44a402b8101c212c9fa74398073f1e --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l6-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [7, 12, 13, 12, 13, 3, 23, 26, 6, 13, 22, 2, 2, 8, 9, 2, 25, 16, 19, 14, 10, 6, 6, 15, 21, 23]} +RLMATH_EOF diff --git a/tasks/construct-rlve-integer-linear-system-l6-s5/tests/check.py b/tasks/construct-rlve-integer-linear-system-l6-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..ff19002b3fddc9597f84ee31ef5ffbee5d3fac32 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l6-s5/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = len(inst["coeffs"][0]) + x = int_list(ans.get("x"), n, name="x") + for k, (e, r) in enumerate(zip(inst["coeffs"], inst["rhs"])): + if sum(c * v for c, v in zip(e, x)) != r: + raise Invalid(f"equation {k} is violated") + return None, {} diff --git a/tasks/construct-rlve-integer-linear-system-l6-s5/tests/instance.json b/tasks/construct-rlve-integer-linear-system-l6-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8a4f8125057558ac65bb94eb2828c7fd3d964f9c --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l6-s5/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [[0, 1, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 4, 0, 2, 2, 0, 0, 4, 3, 3, 0, 0, 5, 0], [1, 0, 5, 0, 0, 5, 2, 2, 0, 0, 0, 2, 3, 0, 0, 0, 0, 0, 0, 2, 0, 0, 3, 2, 1, 2], [0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 2, 3, 0, 0, 0, 0, 5, 0, 1, 0, 5, 1, 0, 0, 0, 0], [0, 5, 0, 4, 5, 2, 5, 0, 0, 2, 0, 4, 3, 4, 0, 0, 2, 0, 3, 4, 0, 3, 0, 4, 5, 2], [3, 0, 0, 0, 0, 0, 0, 0, 2, 1, 3, 5, 3, 5, 4, 0, 0, 5, 0, 4, 0, 0, 0, 0, 0, 0], [0, 0, 2, 4, 5, 0, 0, 0, 5, 0, 0, 2, 3, 0, 2, 0, 0, 5, 0, 0, 2, 5, 4, 2, 3, 0], [0, 3, 0, 3, 2, 1, 0, 0, 0, 2, 3, 0, 0, 3, 2, 0, 0, 5, 2, 3, 5, 0, 0, 0, 0, 0], [2, 5, 4, 4, 0, 0, 2, 0, 4, 1, 0, 2, 4, 4, 2, 3, 5, 0, 3, 1, 0, 0, 3, 0, 2, 0], [0, 0, 0, 5, 5, 4, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 4, 5, 0, 5, 0, 5, 3, 0, 5, 2], [0, 0, 5, 2, 2, 0, 0, 0, 3, 5, 4, 0, 3, 5, 4, 3, 0, 0, 1, 0, 0, 5, 5, 0, 0, 0], [0, 0, 2, 0, 0, 0, 0, 0, 2, 5, 3, 2, 0, 3, 3, 1, 5, 4, 0, 0, 0, 1, 4, 3, 4, 0], [0, 3, 1, 0, 2, 3, 5, 0, 5, 2, 0, 5, 1, 1, 5, 0, 1, 0, 0, 0, 2, 1, 0, 0, 0, 4], [0, 2, 0, 5, 0, 0, 2, 1, 3, 3, 0, 0, 4, 0, 0, 0, 0, 5, 0, 0, 0, 2, 4, 0, 0, 0], [0, 3, 5, 0, 0, 0, 1, 4, 0, 1, 0, 3, 0, 0, 4, 0, 0, 0, 4, 0, 0, 5, 0, 2, 0, 1], [0, 0, 5, 0, 4, 2, 4, 0, 0, 1, 4, 4, 0, 0, 2, 3, 4, 3, 5, 0, 3, 0, 0, 0, 0, 4], [0, 1, 0, 4, 4, 4, 0, 1, 2, 1, 0, 1, 0, 5, 0, 3, 0, 0, 4, 0, 0, 3, 0, 3, 2, 0], [5, 2, 0, 0, 4, 2, 0, 2, 0, 0, 4, 2, 5, 0, 0, 0, 0, 3, 5, 3, 1, 0, 0, 0, 3, 0], [0, 2, 3, 0, 5, 0, 0, 3, 4, 1, 0, 4, 0, 3, 2, 5, 5, 5, 3, 3, 0, 2, 0, 5, 5, 4], [1, 0, 0, 1, 0, 4, 5, 0, 0, 4, 0, 0, 2, 4, 0, 0, 3, 2, 0, 0, 5, 3, 0, 0, 0, 0], [2, 0, 0, 5, 0, 1, 1, 0, 3, 0, 2, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 3, 0, 2, 0, 0], [4, 1, 5, 3, 0, 0, 0, 0, 4, 2, 0, 0, 0, 0, 4, 4, 5, 5, 3, 1, 0, 1, 2, 0, 2, 2], [5, 4, 0, 5, 0, 3, 3, 5, 0, 0, 0, 0, 0, 0, 5, 0, 4, 1, 5, 4, 0, 0, 5, 0, 2, 0], [1, 4, 1, 4, 0, 3, 4, 3, 0, 1, 5, 5, 0, 0, 0, 2, 0, 1, 0, 0, 0, 4, 1, 2, 0, 0], [0, 4, 0, 0, 0, 0, 0, 5, 4, 0, 2, 3, 0, 0, 1, 5, 3, 5, 4, 0, 0, 1, 4, 0, 0, 0], [0, 5, 0, 3, 0, 4, 0, 4, 3, 5, 0, 5, 0, 0, 0, 2, 4, 0, 5, 0, 2, 1, 0, 2, 0, 0], [4, 0, 0, 4, 0, 4, 0, 4, 0, 0, 0, 0, 5, 5, 4, 0, 2, 3, 0, 0, 0, 1, 2, 0, 2, 3], [1, 3, 0, 5, 1, 5, 0, 0, 0, 0, 0, 2, 3, 0, 0, 1, 0, 3, 2, 0, 5, 0, 0, 3, 2, 0], [0, 4, 5, 3, 0, 1, 0, 0, 1, 0, 5, 1, 2, 5, 1, 0, 0, 5, 4, 5, 3, 0, 0, 1, 0, 0], [1, 1, 3, 2, 1, 5, 1, 4, 2, 1, 0, 0, 0, 0, 5, 0, 0, 2, 0, 0, 0, 0, 0, 5, 3, 2], [0, 0, 1, 3, 5, 4, 4, 5, 0, 0, 0, 0, 0, 5, 4, 3, 0, 2, 0, 0, 0, 0, 5, 2, 0, 1], [1, 0, 5, 5, 0, 4, 0, 0, 2, 0, 5, 2, 0, 0, 2, 5, 3, 2, 4, 0, 0, 5, 0, 3, 4, 2], [0, 0, 4, 5, 5, 0, 3, 2, 0, 3, 0, 0, 0, 2, 5, 0, 0, 0, 5, 2, 2, 0, 0, 2, 1, 3], [0, 0, 2, 0, 2, 4, 3, 0, 0, 0, 1, 2, 1, 4, 5, 2, 0, 0, 1, 0, 0, 0, 4, 0, 5, 0], [3, 4, 0, 0, 5, 0, 0, 5, 1, 3, 0, 0, 0, 0, 5, 0, 0, 5, 0, 0, 0, 2, 0, 0, 0, 2], [0, 0, 0, 1, 3, 0, 0, 2, 0, 5, 3, 0, 1, 0, 4, 0, 0, 2, 0, 2, 2, 1, 0, 0, 2, 2], [0, 3, 4, 0, 5, 3, 0, 2, 5, 0, 0, 5, 1, 0, 2, 0, 2, 0, 3, 0, 2, 0, 0, 4, 5, 0], [0, 1, 0, 5, 3, 0, 0, 4, 2, 3, 1, 0, 0, 0, 2, 3, 1, 0, 3, 0, 0, 1, 0, 0, 0, 0], [0, 0, 4, 0, 0, 0, 3, 5, 0, 1, 1, 2, 0, 0, 0, 0, 0, 2, 5, 0, 0, 5, 0, 0, 0, 0], [0, 0, 0, 5, 0, 1, 4, 3, 1, 4, 4, 5, 5, 5, 0, 0, 2, 1, 0, 0, 4, 1, 0, 5, 5, 4], [4, 1, 0, 5, 2, 0, 3, 0, 2, 2, 2, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 5, 4, 0, 0, 0], [0, 0, 1, 0, 0, 3, 5, 0, 0, 0, 3, 3, 4, 4, 0, 3, 5, 2, 3, 4, 0, 5, 5, 0, 2, 0], [1, 0, 0, 0, 2, 0, 1, 4, 1, 0, 0, 1, 5, 0, 2, 3, 5, 0, 0, 2, 0, 2, 2, 0, 0, 0], [0, 0, 4, 3, 3, 0, 1, 0, 0, 0, 4, 0, 3, 2, 0, 0, 0, 4, 0, 1, 0, 0, 0, 3, 5, 5], [0, 1, 1, 0, 0, 4, 0, 1, 0, 0, 0, 5, 2, 0, 0, 0, 0, 0, 1, 1, 0, 0, 5, 0, 0, 0], [0, 0, 3, 3, 3, 0, 3, 0, 1, 0, 0, 1, 0, 0, 3, 0, 4, 0, 0, 5, 4, 0, 5, 0, 4, 0], [5, 0, 2, 0, 5, 0, 5, 0, 5, 2, 5, 5, 0, 3, 5, 0, 0, 1, 0, 0, 0, 3, 0, 5, 1, 4], [0, 2, 3, 2, 3, 0, 3, 0, 0, 0, 0, 0, 2, 4, 0, 3, 1, 0, 0, 0, 5, 0, 0, 2, 0, 0], [5, 3, 0, 0, 2, 0, 0, 3, 0, 0, 0, 0, 4, 4, 0, 4, 4, 4, 0, 0, 5, 0, 0, 1, 1, 4], [5, 4, 1, 1, 0, 1, 0, 1, 2, 0, 1, 0, 0, 4, 0, 2, 1, 2, 2, 3, 1, 2, 4, 4, 0, 0], [0, 3, 0, 4, 0, 4, 5, 0, 1, 4, 2, 0, 0, 4, 4, 0, 3, 0, 4, 2, 0, 3, 0, 0, 2, 0], [0, 0, 4, 1, 0, 4, 1, 0, 0, 3, 0, 3, 0, 1, 2, 0, 0, 5, 2, 0, 0, 0, 0, 0, 0, 2], [1, 2, 0, 4, 0, 0, 4, 2, 0, 0, 5, 1, 3, 0, 0, 1, 0, 0, 0, 0, 1, 4, 3, 1, 0, 5], [0, 0, 1, 3, 0, 0, 0, 0, 5, 1, 4, 0, 3, 3, 4, 3, 3, 0, 0, 3, 3, 0, 0, 1, 0, 0], [1, 2, 3, 0, 0, 0, 1, 2, 1, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0], [2, 4, 0, 5, 4, 0, 2, 1, 0, 0, 0, 1, 2, 1, 4, 4, 0, 0, 0, 1, 0, 0, 0, 0, 4, 2], [0, 2, 3, 1, 2, 0, 0, 4, 4, 0, 0, 5, 2, 0, 0, 0, 0, 0, 1, 0, 0, 4, 1, 3, 0, 5], [0, 2, 0, 0, 2, 0, 2, 2, 0, 0, 0, 0, 5, 3, 3, 4, 0, 0, 5, 1, 0, 0, 0, 0, 0, 4], [2, 0, 0, 1, 4, 0, 4, 1, 2, 2, 0, 4, 0, 2, 0, 2, 1, 0, 0, 0, 0, 0, 5, 0, 5, 0], [2, 0, 5, 5, 1, 0, 4, 1, 2, 0, 2, 4, 0, 0, 0, 5, 5, 3, 3, 0, 0, 0, 0, 5, 5, 3], [3, 3, 0, 5, 4, 4, 1, 0, 0, 0, 0, 0, 0, 4, 4, 0, 0, 0, 5, 0, 4, 0, 4, 2, 2, 5], [3, 0, 0, 0, 0, 3, 5, 0, 5, 3, 5, 0, 0, 3, 0, 3, 0, 5, 0, 0, 0, 0, 0, 0, 2, 0], [5, 1, 0, 5, 0, 5, 4, 2, 3, 1, 3, 1, 0, 1, 4, 0, 0, 4, 4, 3, 1, 0, 3, 5, 1, 0], [0, 0, 1, 0, 4, 0, 0, 0, 1, 0, 1, 5, 1, 0, 0, 0, 2, 1, 2, 5, 0, 0, 0, 0, 0, 4], [0, 3, 0, 1, 0, 0, 1, 2, 4, 0, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 4, 1], [0, 0, 0, 0, 5, 0, 0, 2, 1, 0, 2, 3, 1, 3, 0, 0, 5, 4, 3, 0, 0, 3, 1, 5, 2, 4], [1, 3, 3, 0, 0, 0, 0, 4, 0, 3, 2, 1, 0, 3, 0, 2, 0, 2, 3, 4, 2, 0, 0, 5, 0, 0], [1, 3, 0, 0, 0, 2, 0, 0, 4, 0, 5, 4, 0, 0, 0, 4, 0, 0, 2, 0, 4, 0, 0, 0, 5, 0], [1, 0, 0, 2, 0, 3, 0, 2, 4, 0, 2, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 5, 0, 0], [4, 0, 5, 0, 0, 4, 0, 0, 0, 2, 0, 0, 0, 0, 3, 5, 2, 0, 0, 4, 2, 2, 3, 0, 3, 2], [3, 2, 0, 4, 4, 4, 0, 0, 0, 4, 0, 5, 1, 4, 0, 2, 0, 2, 3, 3, 1, 0, 4, 4, 4, 2], [1, 2, 0, 5, 3, 2, 5, 1, 0, 0, 5, 0, 3, 3, 2, 0, 2, 0, 0, 0, 2, 0, 5, 0, 0, 0], [3, 0, 0, 5, 0, 0, 5, 4, 5, 1, 4, 0, 0, 3, 2, 5, 1, 4, 1, 2, 0, 0, 0, 0, 0, 5]], "rhs": [325, 338, 315, 758, 340, 444, 445, 581, 590, 453, 574, 463, 337, 442, 713, 404, 529, 891, 409, 254, 617, 735, 508, 532, 560, 505, 366, 594, 523, 545, 686, 661, 390, 492, 446, 566, 400, 447, 823, 367, 627, 379, 603, 140, 542, 708, 342, 565, 450, 620, 334, 525, 414, 199, 448, 452, 418, 422, 823, 618, 476, 715, 371, 363, 678, 539, 382, 279, 433, 612, 535, 734], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l6-s5/tests/run.py b/tasks/construct-rlve-integer-linear-system-l6-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l6-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-integer-linear-system-l6-s5/tests/test.sh b/tasks/construct-rlve-integer-linear-system-l6-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l6-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-largest-convex-polygon-l5-s5/environment/Dockerfile b/tasks/construct-rlve-largest-convex-polygon-l5-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l5-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-largest-convex-polygon-l5-s5/environment/instance.json b/tasks/construct-rlve-largest-convex-polygon-l5-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9fafb106c588cc158da94eead17f7d5eb6df4616 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l5-s5/environment/instance.json @@ -0,0 +1 @@ +{"points": [[7, 17], [23, 16], [5, 1], [22, 23], [8, 12], [8, 21], [15, 5], [1, 15], [12, 9], [16, 25], [20, 19], [3, 18], [15, 7], [0, 22], [25, 21], [12, 2], [23, 11], [20, 18], [3, 5], [19, 10], [13, 0], [2, 3], [2, 6], [24, 12], [10, 25]], "k": 12, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l5-s5/solution/solve.sh b/tasks/construct-rlve-largest-convex-polygon-l5-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1a7af85563cf9a78a8bfeb01fd71e78025684f13 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l5-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [7, 11, 5, 9, 3, 14, 1, 19, 6, 15, 2, 18]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-convex-polygon-l5-s5/tests/check.py b/tasks/construct-rlve-largest-convex-polygon-l5-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3a09cc858f41ce5745e4e491188cd42360c65dae --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l5-s5/tests/check.py @@ -0,0 +1,27 @@ +from run import Invalid, int_list + + +def _cross(o, a, b): + return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]) + + +def check(inst, ans): + P, k = inst["points"], inst["k"] + idx = int_list(ans.get("indices"), None, 0, len(P) - 1, "indices") + if len(set(idx)) != len(idx): + raise Invalid("indices must be distinct") + if len(idx) < k: + raise Invalid(f"{len(idx)} points given, need {k}") + pts = sorted(tuple(P[i]) for i in idx) + lower, upper = [], [] + for p in pts: # monotone chain, strict (collinear points dropped) + while len(lower) >= 2 and _cross(lower[-2], lower[-1], p) <= 0: + lower.pop() + lower.append(p) + for p in reversed(pts): + while len(upper) >= 2 and _cross(upper[-2], upper[-1], p) <= 0: + upper.pop() + upper.append(p) + if len(lower) + len(upper) - 2 != len(pts): + raise Invalid("the chosen points are not in convex position") + return None, {} diff --git a/tasks/construct-rlve-largest-convex-polygon-l5-s5/tests/instance.json b/tasks/construct-rlve-largest-convex-polygon-l5-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9fafb106c588cc158da94eead17f7d5eb6df4616 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l5-s5/tests/instance.json @@ -0,0 +1 @@ +{"points": [[7, 17], [23, 16], [5, 1], [22, 23], [8, 12], [8, 21], [15, 5], [1, 15], [12, 9], [16, 25], [20, 19], [3, 18], [15, 7], [0, 22], [25, 21], [12, 2], [23, 11], [20, 18], [3, 5], [19, 10], [13, 0], [2, 3], [2, 6], [24, 12], [10, 25]], "k": 12, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l5-s5/tests/run.py b/tasks/construct-rlve-largest-convex-polygon-l5-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l5-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-largest-convex-polygon-l5-s5/tests/test.sh b/tasks/construct-rlve-largest-convex-polygon-l5-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l5-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l4-s1/environment/Dockerfile b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l4-s1/environment/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..75efa14edd5f7e17f5e8c133976aa1ebd77b0257 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s1/environment/instance.json @@ -0,0 +1 @@ +{"A": ["01111110", "11110111", "01111111", "11111111", "11110011", "10111111", "11101101", "11111111", "00111111", "11110111"], "B": ["11011011", "10111111", "11110011", "10101111", "11111111", "11111011", "10111111", "11111111", "11111100", "11110111"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l4-s1/solution/solve.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d1464aa0b8f9a23b01ef3ee2832f460b8156226f --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"a": [0, 1, 8, 4, 3, 2, 9, 7, 6, 5], "b": [2, 4, 7, 5, 1, 0, 3, 6]} +RLMATH_EOF diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l4-s1/tests/check.py b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..310a1d2c8b6afd7a82a35ba2a4c802c1ce289d03 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s1/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + A, B = inst["A"], inst["B"] + N, M = len(A), len(A[0]) + a = int_list(ans.get("a"), N, 0, N - 1, "a") + b = int_list(ans.get("b"), M, 0, M - 1, "b") + if len(set(a)) != N or len(set(b)) != M: + raise Invalid("a and b must be permutations") + for i in range(N): + for j in range(M): + if A[a[i]][b[j]] != B[i][j]: + raise Invalid(f"mismatch at ({i}, {j})") + return None, {} diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l4-s1/tests/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..75efa14edd5f7e17f5e8c133976aa1ebd77b0257 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s1/tests/instance.json @@ -0,0 +1 @@ +{"A": ["01111110", "11110111", "01111111", "11111111", "11110011", "10111111", "11101101", "11111111", "00111111", "11110111"], "B": ["11011011", "10111111", "11110011", "10101111", "11111111", "11111011", "10111111", "11111111", "11111100", "11110111"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l4-s1/tests/run.py b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l4-s1/tests/test.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l4-s6/environment/Dockerfile b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l4-s6/environment/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..dbd0750b66d92cba80ae2e2d46610fbdbd3be8df --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s6/environment/instance.json @@ -0,0 +1 @@ +{"A": ["010000100", "000000000", "100000000", "000000000", "000000000", "000000000"], "B": ["000000000", "000000000", "000000000", "000000100", "101000000", "000000000"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l4-s6/solution/solve.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c276be1d69ab5378092a0f36388f667d07791490 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"a": [1, 3, 4, 2, 0, 5], "b": [6, 7, 1, 5, 4, 3, 0, 8, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l4-s6/tests/check.py b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..310a1d2c8b6afd7a82a35ba2a4c802c1ce289d03 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s6/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + A, B = inst["A"], inst["B"] + N, M = len(A), len(A[0]) + a = int_list(ans.get("a"), N, 0, N - 1, "a") + b = int_list(ans.get("b"), M, 0, M - 1, "b") + if len(set(a)) != N or len(set(b)) != M: + raise Invalid("a and b must be permutations") + for i in range(N): + for j in range(M): + if A[a[i]][b[j]] != B[i][j]: + raise Invalid(f"mismatch at ({i}, {j})") + return None, {} diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l4-s6/tests/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..dbd0750b66d92cba80ae2e2d46610fbdbd3be8df --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s6/tests/instance.json @@ -0,0 +1 @@ +{"A": ["010000100", "000000000", "100000000", "000000000", "000000000", "000000000"], "B": ["000000000", "000000000", "000000000", "000000100", "101000000", "000000000"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l4-s6/tests/run.py b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l4-s6/tests/test.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l4-s8/environment/Dockerfile b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l4-s8/environment/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e5b67692378bc54a445a8c6de64308df3d27eb57 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s8/environment/instance.json @@ -0,0 +1 @@ +{"A": ["0001110011", "1011010001", "1011011111", "1011110110", "0111111111", "1011111010", "1111101110", "1011110111", "1011101110", "1101101001", "0101111111", "0000111111"], "B": ["0110111111", "1111110101", "0011011111", "0111100100", "1011011111", "0011101111", "0101110101", "0111101111", "0011111110", "0110101010", "1111011000", "1111110111"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l4-s8/solution/solve.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..901512b43f6630841260d1400197921464da16d5 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"a": [2, 10, 8, 0, 6, 3, 11, 7, 5, 1, 9, 4], "b": [1, 9, 3, 4, 5, 6, 0, 8, 2, 7]} +RLMATH_EOF diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l4-s8/tests/check.py b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..310a1d2c8b6afd7a82a35ba2a4c802c1ce289d03 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s8/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + A, B = inst["A"], inst["B"] + N, M = len(A), len(A[0]) + a = int_list(ans.get("a"), N, 0, N - 1, "a") + b = int_list(ans.get("b"), M, 0, M - 1, "b") + if len(set(a)) != N or len(set(b)) != M: + raise Invalid("a and b must be permutations") + for i in range(N): + for j in range(M): + if A[a[i]][b[j]] != B[i][j]: + raise Invalid(f"mismatch at ({i}, {j})") + return None, {} diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l4-s8/tests/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e5b67692378bc54a445a8c6de64308df3d27eb57 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s8/tests/instance.json @@ -0,0 +1 @@ +{"A": ["0001110011", "1011010001", "1011011111", "1011110110", "0111111111", "1011111010", "1111101110", "1011110111", "1011101110", "1101101001", "0101111111", "0000111111"], "B": ["0110111111", "1111110101", "0011011111", "0111100100", "1011011111", "0011101111", "0101110101", "0111101111", "0011111110", "0110101010", "1111011000", "1111110111"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l4-s8/tests/run.py b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l4-s8/tests/test.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-max-achromatic-coloring-l5-s4/environment/Dockerfile b/tasks/construct-rlve-max-achromatic-coloring-l5-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l5-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-max-achromatic-coloring-l5-s4/environment/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l5-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fb99456d91481ee96d1e12c021abe5de7cb9c5a9 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l5-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 13, "k": 8, "edges": [[0, 1], [0, 3], [0, 4], [0, 5], [0, 7], [0, 9], [0, 11], [0, 12], [1, 2], [1, 4], [1, 7], [1, 9], [1, 11], [1, 12], [2, 4], [2, 5], [2, 7], [2, 9], [2, 10], [2, 11], [3, 4], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 12], [4, 5], [4, 6], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [6, 7], [6, 8], [6, 11], [6, 12], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [8, 9], [8, 10], [8, 12], [9, 11], [9, 12], [10, 12]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l5-s4/solution/solve.sh b/tasks/construct-rlve-max-achromatic-coloring-l5-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d4c4f61675f938f3409dd508ae5558b77bf52f37 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l5-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 1, 0, 1, 2, 3, 0, 3, 4, 5, 6, 6, 7]} +RLMATH_EOF diff --git a/tasks/construct-rlve-max-achromatic-coloring-l5-s4/tests/check.py b/tasks/construct-rlve-max-achromatic-coloring-l5-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bb676a518264e5db4fb0964e27ccffccf6980807 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l5-s4/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + if len(set(c)) != k: + raise Invalid(f"uses {len(set(c))} colours, need all {k}") + pairs = set() + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + pairs.add((min(c[u], c[v]), max(c[u], c[v]))) + if len(pairs) != k * (k - 1) // 2: + raise Invalid("some pair of colours is not joined by an edge") + return None, {} diff --git a/tasks/construct-rlve-max-achromatic-coloring-l5-s4/tests/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l5-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fb99456d91481ee96d1e12c021abe5de7cb9c5a9 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l5-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 13, "k": 8, "edges": [[0, 1], [0, 3], [0, 4], [0, 5], [0, 7], [0, 9], [0, 11], [0, 12], [1, 2], [1, 4], [1, 7], [1, 9], [1, 11], [1, 12], [2, 4], [2, 5], [2, 7], [2, 9], [2, 10], [2, 11], [3, 4], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 12], [4, 5], [4, 6], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [6, 7], [6, 8], [6, 11], [6, 12], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [8, 9], [8, 10], [8, 12], [9, 11], [9, 12], [10, 12]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l5-s4/tests/run.py b/tasks/construct-rlve-max-achromatic-coloring-l5-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l5-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-max-achromatic-coloring-l5-s4/tests/test.sh b/tasks/construct-rlve-max-achromatic-coloring-l5-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l5-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-maximum-clique-l3-s1/environment/Dockerfile b/tasks/construct-rlve-maximum-clique-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l3-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-maximum-clique-l3-s1/environment/instance.json b/tasks/construct-rlve-maximum-clique-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c94d09d8629d6ad6535854dc23a74c2fb7536f90 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 22, "k": 7, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 9], [0, 10], [0, 11], [0, 12], [0, 14], [0, 16], [0, 17], [0, 19], [0, 20], [1, 3], [1, 4], [1, 5], [1, 8], [1, 9], [1, 10], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [2, 3], [2, 6], [2, 7], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 16], [2, 17], [2, 18], [2, 21], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 10], [3, 11], [3, 17], [3, 20], [3, 21], [4, 5], [4, 6], [4, 9], [4, 10], [4, 13], [4, 16], [4, 17], [4, 19], [4, 20], [5, 6], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 13], [5, 14], [5, 15], [5, 16], [5, 17], [5, 21], [6, 7], [6, 8], [6, 10], [6, 11], [6, 13], [6, 14], [6, 15], [6, 16], [6, 17], [6, 20], [6, 21], [7, 8], [7, 9], [7, 10], [7, 14], [7, 16], [7, 18], [7, 19], [7, 21], [8, 9], [8, 10], [8, 11], [8, 12], [8, 17], [8, 18], [8, 19], [8, 20], [9, 10], [9, 12], [9, 14], [9, 16], [9, 17], [9, 18], [9, 19], [9, 20], [10, 11], [10, 12], [10, 13], [10, 15], [10, 17], [10, 18], [10, 19], [10, 21], [11, 13], [11, 14], [11, 16], [11, 17], [11, 18], [11, 19], [11, 21], [12, 14], [12, 16], [12, 17], [12, 20], [12, 21], [13, 15], [13, 17], [13, 18], [13, 20], [13, 21], [14, 15], [14, 16], [14, 19], [14, 20], [15, 16], [15, 17], [15, 19], [15, 20], [16, 17], [16, 18], [16, 19], [16, 21], [17, 18], [17, 20], [17, 21], [18, 19], [18, 20], [18, 21], [19, 20], [19, 21], [20, 21]], "family": "rlve_maximum_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-maximum-clique-l3-s1/solution/solve.sh b/tasks/construct-rlve-maximum-clique-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5f15e994468f103badcc0a2699b79465a24cf998 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l3-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [0, 1, 3, 4, 5, 10, 17]} +RLMATH_EOF diff --git a/tasks/construct-rlve-maximum-clique-l3-s1/tests/check.py b/tasks/construct-rlve-maximum-clique-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..95e00c78f7c986ba3aecbdc8af3cf8ed221abd05 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l3-s1/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("clique"), None, 0, n - 1, "clique") + if len(set(c)) != len(c): + raise Invalid("vertices must be distinct") + if len(c) < k: + raise Invalid(f"clique has {len(c)} vertices, need {k}") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for i in range(len(c)): + for j in range(i + 1, len(c)): + if (min(c[i], c[j]), max(c[i], c[j])) not in es: + raise Invalid(f"{c[i]} and {c[j]} are not adjacent") + return None, {} diff --git a/tasks/construct-rlve-maximum-clique-l3-s1/tests/instance.json b/tasks/construct-rlve-maximum-clique-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c94d09d8629d6ad6535854dc23a74c2fb7536f90 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 22, "k": 7, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 9], [0, 10], [0, 11], [0, 12], [0, 14], [0, 16], [0, 17], [0, 19], [0, 20], [1, 3], [1, 4], [1, 5], [1, 8], [1, 9], [1, 10], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [2, 3], [2, 6], [2, 7], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 16], [2, 17], [2, 18], [2, 21], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 10], [3, 11], [3, 17], [3, 20], [3, 21], [4, 5], [4, 6], [4, 9], [4, 10], [4, 13], [4, 16], [4, 17], [4, 19], [4, 20], [5, 6], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 13], [5, 14], [5, 15], [5, 16], [5, 17], [5, 21], [6, 7], [6, 8], [6, 10], [6, 11], [6, 13], [6, 14], [6, 15], [6, 16], [6, 17], [6, 20], [6, 21], [7, 8], [7, 9], [7, 10], [7, 14], [7, 16], [7, 18], [7, 19], [7, 21], [8, 9], [8, 10], [8, 11], [8, 12], [8, 17], [8, 18], [8, 19], [8, 20], [9, 10], [9, 12], [9, 14], [9, 16], [9, 17], [9, 18], [9, 19], [9, 20], [10, 11], [10, 12], [10, 13], [10, 15], [10, 17], [10, 18], [10, 19], [10, 21], [11, 13], [11, 14], [11, 16], [11, 17], [11, 18], [11, 19], [11, 21], [12, 14], [12, 16], [12, 17], [12, 20], [12, 21], [13, 15], [13, 17], [13, 18], [13, 20], [13, 21], [14, 15], [14, 16], [14, 19], [14, 20], [15, 16], [15, 17], [15, 19], [15, 20], [16, 17], [16, 18], [16, 19], [16, 21], [17, 18], [17, 20], [17, 21], [18, 19], [18, 20], [18, 21], [19, 20], [19, 21], [20, 21]], "family": "rlve_maximum_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-maximum-clique-l3-s1/tests/run.py b/tasks/construct-rlve-maximum-clique-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l3-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-maximum-clique-l3-s1/tests/test.sh b/tasks/construct-rlve-maximum-clique-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l3-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-maximum-clique-l3-s8/environment/Dockerfile b/tasks/construct-rlve-maximum-clique-l3-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l3-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-maximum-clique-l3-s8/environment/instance.json b/tasks/construct-rlve-maximum-clique-l3-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cfaa65bffefe92b5f866f812e3e29e3c33ee04c3 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l3-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 22, "k": 5, "edges": [[0, 1], [0, 2], [0, 5], [0, 9], [0, 11], [0, 12], [0, 13], [0, 17], [0, 18], [0, 20], [1, 5], [1, 7], [1, 9], [1, 10], [1, 15], [1, 19], [2, 3], [2, 4], [2, 5], [2, 9], [2, 12], [2, 13], [2, 17], [2, 18], [3, 7], [3, 8], [3, 9], [3, 10], [3, 12], [3, 13], [3, 18], [3, 19], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 16], [4, 17], [4, 18], [4, 19], [4, 21], [5, 7], [5, 12], [5, 13], [5, 15], [5, 17], [5, 19], [5, 21], [6, 10], [6, 11], [6, 12], [6, 13], [6, 14], [6, 17], [6, 18], [6, 19], [6, 20], [6, 21], [7, 8], [7, 9], [7, 13], [7, 19], [7, 21], [8, 12], [8, 13], [8, 20], [8, 21], [9, 10], [9, 16], [9, 18], [9, 20], [10, 12], [10, 13], [10, 14], [10, 15], [10, 17], [11, 13], [11, 20], [12, 13], [12, 14], [12, 18], [12, 19], [12, 20], [12, 21], [13, 16], [13, 17], [13, 19], [13, 20], [13, 21], [14, 18], [14, 20], [14, 21], [15, 20], [15, 21], [16, 20], [16, 21], [17, 18], [17, 19], [17, 20], [18, 20], [18, 21], [19, 21]], "family": "rlve_maximum_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-maximum-clique-l3-s8/solution/solve.sh b/tasks/construct-rlve-maximum-clique-l3-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9f5362220045473c57d89413908cfd3ec19c6ebe --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l3-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [0, 2, 5, 12, 13]} +RLMATH_EOF diff --git a/tasks/construct-rlve-maximum-clique-l3-s8/tests/check.py b/tasks/construct-rlve-maximum-clique-l3-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..95e00c78f7c986ba3aecbdc8af3cf8ed221abd05 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l3-s8/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("clique"), None, 0, n - 1, "clique") + if len(set(c)) != len(c): + raise Invalid("vertices must be distinct") + if len(c) < k: + raise Invalid(f"clique has {len(c)} vertices, need {k}") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for i in range(len(c)): + for j in range(i + 1, len(c)): + if (min(c[i], c[j]), max(c[i], c[j])) not in es: + raise Invalid(f"{c[i]} and {c[j]} are not adjacent") + return None, {} diff --git a/tasks/construct-rlve-maximum-clique-l3-s8/tests/instance.json b/tasks/construct-rlve-maximum-clique-l3-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cfaa65bffefe92b5f866f812e3e29e3c33ee04c3 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l3-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 22, "k": 5, "edges": [[0, 1], [0, 2], [0, 5], [0, 9], [0, 11], [0, 12], [0, 13], [0, 17], [0, 18], [0, 20], [1, 5], [1, 7], [1, 9], [1, 10], [1, 15], [1, 19], [2, 3], [2, 4], [2, 5], [2, 9], [2, 12], [2, 13], [2, 17], [2, 18], [3, 7], [3, 8], [3, 9], [3, 10], [3, 12], [3, 13], [3, 18], [3, 19], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 16], [4, 17], [4, 18], [4, 19], [4, 21], [5, 7], [5, 12], [5, 13], [5, 15], [5, 17], [5, 19], [5, 21], [6, 10], [6, 11], [6, 12], [6, 13], [6, 14], [6, 17], [6, 18], [6, 19], [6, 20], [6, 21], [7, 8], [7, 9], [7, 13], [7, 19], [7, 21], [8, 12], [8, 13], [8, 20], [8, 21], [9, 10], [9, 16], [9, 18], [9, 20], [10, 12], [10, 13], [10, 14], [10, 15], [10, 17], [11, 13], [11, 20], [12, 13], [12, 14], [12, 18], [12, 19], [12, 20], [12, 21], [13, 16], [13, 17], [13, 19], [13, 20], [13, 21], [14, 18], [14, 20], [14, 21], [15, 20], [15, 21], [16, 20], [16, 21], [17, 18], [17, 19], [17, 20], [18, 20], [18, 21], [19, 21]], "family": "rlve_maximum_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-maximum-clique-l3-s8/tests/run.py b/tasks/construct-rlve-maximum-clique-l3-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l3-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-maximum-clique-l3-s8/tests/test.sh b/tasks/construct-rlve-maximum-clique-l3-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l3-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-min-harmonious-coloring-l4-s0/environment/Dockerfile b/tasks/construct-rlve-min-harmonious-coloring-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l4-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-min-harmonious-coloring-l4-s0/environment/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..dfe58bae1e16e2dff488bf11499490cd3d4214f6 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 12, "k": 5, "edges": [[1, 6], [3, 6], [3, 9], [3, 10], [4, 11], [5, 8], [6, 7], [9, 11], [10, 11]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l4-s0/solution/solve.sh b/tasks/construct-rlve-min-harmonious-coloring-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..cc9f0ef8885f6388e570fa70c055a92cc29b170f --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l4-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 0, 0, 1, 1, 0, 2, 3, 3, 0, 3, 4]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-harmonious-coloring-l4-s0/tests/check.py b/tasks/construct-rlve-min-harmonious-coloring-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..91282a31c765b6103e6575180adb47abddb6a506 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l4-s0/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + seen = set() + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + pair = (min(c[u], c[v]), max(c[u], c[v])) + if pair in seen: + raise Invalid(f"colour pair {pair} appears on two edges") + seen.add(pair) + return None, {} diff --git a/tasks/construct-rlve-min-harmonious-coloring-l4-s0/tests/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..dfe58bae1e16e2dff488bf11499490cd3d4214f6 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 12, "k": 5, "edges": [[1, 6], [3, 6], [3, 9], [3, 10], [4, 11], [5, 8], [6, 7], [9, 11], [10, 11]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l4-s0/tests/run.py b/tasks/construct-rlve-min-harmonious-coloring-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l4-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-min-harmonious-coloring-l4-s0/tests/test.sh b/tasks/construct-rlve-min-harmonious-coloring-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l4-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-min-harmonious-coloring-l4-s7/environment/Dockerfile b/tasks/construct-rlve-min-harmonious-coloring-l4-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l4-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-min-harmonious-coloring-l4-s7/environment/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l4-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6033269e41ca75436d341263685c5a467fa665ce --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l4-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 12, "k": 4, "edges": [[1, 11], [3, 4], [3, 10], [4, 5], [7, 10], [8, 11]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l4-s7/solution/solve.sh b/tasks/construct-rlve-min-harmonious-coloring-l4-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a7e118ca9af891f5c9b9f5d2bba278feb21486dc --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l4-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 0, 0, 0, 1, 2, 0, 1, 3, 0, 3, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-harmonious-coloring-l4-s7/tests/check.py b/tasks/construct-rlve-min-harmonious-coloring-l4-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..91282a31c765b6103e6575180adb47abddb6a506 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l4-s7/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + seen = set() + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + pair = (min(c[u], c[v]), max(c[u], c[v])) + if pair in seen: + raise Invalid(f"colour pair {pair} appears on two edges") + seen.add(pair) + return None, {} diff --git a/tasks/construct-rlve-min-harmonious-coloring-l4-s7/tests/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l4-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6033269e41ca75436d341263685c5a467fa665ce --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l4-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 12, "k": 4, "edges": [[1, 11], [3, 4], [3, 10], [4, 5], [7, 10], [8, 11]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l4-s7/tests/run.py b/tasks/construct-rlve-min-harmonious-coloring-l4-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l4-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-min-harmonious-coloring-l4-s7/tests/test.sh b/tasks/construct-rlve-min-harmonious-coloring-l4-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l4-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l2-s1/environment/Dockerfile b/tasks/construct-rlve-pairwise-sums-recovery-l2-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l2-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l2-s1/environment/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l2-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f25c2ccf78f5e051ea5f2a47421faa2e4310e3ef --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l2-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 5, "sums": [5, 12, 11, 6, 9, 7, 7, 8, 9, 10], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l2-s1/solution/solve.sh b/tasks/construct-rlve-pairwise-sums-recovery-l2-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1b81e0facc639c4eb00b3cf2fe0ca7d026aed256 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l2-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"numbers": [2, 3, 4, 5, 7]} +RLMATH_EOF diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l2-s1/tests/check.py b/tasks/construct-rlve-pairwise-sums-recovery-l2-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..01b5b475e927688c0209fb93478a95f6dd1d3407 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l2-s1/tests/check.py @@ -0,0 +1,14 @@ +from collections import Counter + +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("numbers"), n, 1, None, "numbers") + if len(set(x)) != n: + raise Invalid("numbers must be distinct") + got = Counter(x[i] + x[j] for i in range(n) for j in range(i + 1, n)) + if got != Counter(inst["sums"]): + raise Invalid("pairwise sums do not match") + return None, {} diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l2-s1/tests/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l2-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f25c2ccf78f5e051ea5f2a47421faa2e4310e3ef --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l2-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 5, "sums": [5, 12, 11, 6, 9, 7, 7, 8, 9, 10], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l2-s1/tests/run.py b/tasks/construct-rlve-pairwise-sums-recovery-l2-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l2-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l2-s1/tests/test.sh b/tasks/construct-rlve-pairwise-sums-recovery-l2-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l2-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l6-s0/environment/Dockerfile b/tasks/construct-rlve-pairwise-sums-recovery-l6-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l6-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l6-s0/environment/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l6-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..67ac7ac0acf89df2f2142e1f30a284d5b9853e68 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l6-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 26, "sums": [50, 81, 80, 38, 36, 68, 63, 64, 47, 61, 61, 31, 71, 36, 48, 64, 101, 48, 31, 77, 64, 74, 56, 69, 38, 10, 44, 78, 93, 74, 73, 44, 42, 60, 50, 43, 79, 54, 85, 86, 50, 39, 26, 83, 31, 24, 75, 51, 68, 38, 72, 65, 33, 48, 51, 32, 53, 65, 68, 40, 68, 79, 49, 76, 45, 47, 53, 71, 70, 71, 23, 51, 11, 78, 75, 35, 71, 62, 43, 56, 55, 35, 64, 54, 62, 72, 97, 50, 76, 54, 57, 48, 44, 45, 70, 38, 28, 74, 34, 90, 53, 46, 68, 48, 86, 34, 64, 51, 75, 62, 19, 58, 71, 93, 53, 91, 70, 63, 78, 30, 85, 83, 39, 41, 41, 64, 46, 81, 89, 76, 71, 76, 39, 34, 67, 45, 75, 96, 61, 89, 28, 82, 76, 15, 61, 66, 41, 81, 57, 50, 30, 68, 62, 65, 59, 61, 69, 33, 25, 43, 94, 79, 23, 70, 60, 57, 57, 55, 58, 55, 7, 80, 40, 80, 84, 46, 63, 57, 77, 66, 47, 33, 37, 28, 22, 47, 20, 59, 22, 73, 53, 66, 57, 37, 54, 37, 59, 58, 41, 27, 65, 35, 65, 53, 95, 61, 60, 82, 60, 83, 17, 14, 40, 91, 42, 66, 52, 63, 56, 40, 34, 36, 27, 50, 60, 46, 6, 26, 36, 58, 58, 67, 59, 86, 69, 72, 78, 74, 44, 56, 73, 59, 55, 61, 32, 67, 63, 49, 66, 52, 98, 73, 37, 62, 67, 40, 84, 46, 88, 51, 80, 71, 37, 74, 55, 40, 52, 50, 47, 87, 54, 83, 66, 62, 21, 21, 51, 69, 54, 47, 59, 49, 84, 79, 52, 67, 55, 27, 52, 43, 49, 76, 56, 24, 24, 25, 64, 30, 46, 36, 77, 60, 46, 42, 45, 67, 16, 81, 45, 52, 50, 87, 56, 90, 35, 40, 50, 73, 20, 31, 70, 66, 49, 43, 53], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l6-s0/solution/solve.sh b/tasks/construct-rlve-pairwise-sums-recovery-l6-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9f675616cb09e18a6df438eeadce784293c6ad1e --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l6-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"numbers": [1, 5, 6, 9, 15, 16, 18, 19, 21, 22, 25, 27, 29, 30, 31, 32, 34, 35, 37, 39, 41, 44, 45, 46, 49, 52]} +RLMATH_EOF diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l6-s0/tests/check.py b/tasks/construct-rlve-pairwise-sums-recovery-l6-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..01b5b475e927688c0209fb93478a95f6dd1d3407 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l6-s0/tests/check.py @@ -0,0 +1,14 @@ +from collections import Counter + +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("numbers"), n, 1, None, "numbers") + if len(set(x)) != n: + raise Invalid("numbers must be distinct") + got = Counter(x[i] + x[j] for i in range(n) for j in range(i + 1, n)) + if got != Counter(inst["sums"]): + raise Invalid("pairwise sums do not match") + return None, {} diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l6-s0/tests/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l6-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..67ac7ac0acf89df2f2142e1f30a284d5b9853e68 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l6-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 26, "sums": [50, 81, 80, 38, 36, 68, 63, 64, 47, 61, 61, 31, 71, 36, 48, 64, 101, 48, 31, 77, 64, 74, 56, 69, 38, 10, 44, 78, 93, 74, 73, 44, 42, 60, 50, 43, 79, 54, 85, 86, 50, 39, 26, 83, 31, 24, 75, 51, 68, 38, 72, 65, 33, 48, 51, 32, 53, 65, 68, 40, 68, 79, 49, 76, 45, 47, 53, 71, 70, 71, 23, 51, 11, 78, 75, 35, 71, 62, 43, 56, 55, 35, 64, 54, 62, 72, 97, 50, 76, 54, 57, 48, 44, 45, 70, 38, 28, 74, 34, 90, 53, 46, 68, 48, 86, 34, 64, 51, 75, 62, 19, 58, 71, 93, 53, 91, 70, 63, 78, 30, 85, 83, 39, 41, 41, 64, 46, 81, 89, 76, 71, 76, 39, 34, 67, 45, 75, 96, 61, 89, 28, 82, 76, 15, 61, 66, 41, 81, 57, 50, 30, 68, 62, 65, 59, 61, 69, 33, 25, 43, 94, 79, 23, 70, 60, 57, 57, 55, 58, 55, 7, 80, 40, 80, 84, 46, 63, 57, 77, 66, 47, 33, 37, 28, 22, 47, 20, 59, 22, 73, 53, 66, 57, 37, 54, 37, 59, 58, 41, 27, 65, 35, 65, 53, 95, 61, 60, 82, 60, 83, 17, 14, 40, 91, 42, 66, 52, 63, 56, 40, 34, 36, 27, 50, 60, 46, 6, 26, 36, 58, 58, 67, 59, 86, 69, 72, 78, 74, 44, 56, 73, 59, 55, 61, 32, 67, 63, 49, 66, 52, 98, 73, 37, 62, 67, 40, 84, 46, 88, 51, 80, 71, 37, 74, 55, 40, 52, 50, 47, 87, 54, 83, 66, 62, 21, 21, 51, 69, 54, 47, 59, 49, 84, 79, 52, 67, 55, 27, 52, 43, 49, 76, 56, 24, 24, 25, 64, 30, 46, 36, 77, 60, 46, 42, 45, 67, 16, 81, 45, 52, 50, 87, 56, 90, 35, 40, 50, 73, 20, 31, 70, 66, 49, 43, 53], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l6-s0/tests/run.py b/tasks/construct-rlve-pairwise-sums-recovery-l6-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l6-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l6-s0/tests/test.sh b/tasks/construct-rlve-pairwise-sums-recovery-l6-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l6-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-global-minimum-l2-s0/environment/Dockerfile b/tasks/construct-rlve-polynomial-global-minimum-l2-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l2-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-global-minimum-l2-s0/environment/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l2-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5316ea1725bef72f3cbc4f3d59209ee8c4eec35f --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l2-s0/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [1, 2, 1, 0, 2], "fmin": "0.375000000000000000000000000000000000000000000", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l2-s0/solution/solve.sh b/tasks/construct-rlve-polynomial-global-minimum-l2-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..94d4fbcd4d082b61460ecfc602ffdeaabfa57a89 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l2-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x0": -0.5} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-global-minimum-l2-s0/tests/check.py b/tasks/construct-rlve-polynomial-global-minimum-l2-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3be068f4391ad0838c29a4f7d521b8072cf39991 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l2-s0/tests/check.py @@ -0,0 +1,19 @@ +from fractions import Fraction + +from run import Invalid, num + + +def check(inst, ans): + x0 = Fraction(num(ans.get("x0"), "x0")) + if abs(x0) > 10 ** 6: + raise Invalid("x0 out of range") + v = Fraction(0) + for a in reversed(inst["coeffs"]): + v = v * x0 + a + fmin = Fraction(inst["fmin"]) + tol = Fraction(1, 10 ** 9) * max(Fraction(1), abs(fmin)) + if v > fmin + tol: + raise Invalid(f"f(x0) = {float(v)} is above the global minimum {float(fmin)}") + if v < fmin - tol: # cannot happen for a correct f_min; guards against a bad instance + raise Invalid("internal: f(x0) below recorded minimum") + return None, {"f_x0": float(v)} diff --git a/tasks/construct-rlve-polynomial-global-minimum-l2-s0/tests/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l2-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5316ea1725bef72f3cbc4f3d59209ee8c4eec35f --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l2-s0/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [1, 2, 1, 0, 2], "fmin": "0.375000000000000000000000000000000000000000000", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l2-s0/tests/run.py b/tasks/construct-rlve-polynomial-global-minimum-l2-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l2-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-global-minimum-l2-s0/tests/test.sh b/tasks/construct-rlve-polynomial-global-minimum-l2-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l2-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-global-minimum-l2-s7/environment/Dockerfile b/tasks/construct-rlve-polynomial-global-minimum-l2-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l2-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-global-minimum-l2-s7/environment/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l2-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..36a81fb9cc562c8e5bb99837a4374bdb7fa032f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l2-s7/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [40, -56, 50, -16, 2], "fmin": "19.7346895646033218508698818641353958279729113", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l2-s7/solution/solve.sh b/tasks/construct-rlve-polynomial-global-minimum-l2-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b9d176cfd507cfb46ea7881b1951c987d2c8444b --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l2-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x0": 0.8718261016382063} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-global-minimum-l2-s7/tests/check.py b/tasks/construct-rlve-polynomial-global-minimum-l2-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3be068f4391ad0838c29a4f7d521b8072cf39991 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l2-s7/tests/check.py @@ -0,0 +1,19 @@ +from fractions import Fraction + +from run import Invalid, num + + +def check(inst, ans): + x0 = Fraction(num(ans.get("x0"), "x0")) + if abs(x0) > 10 ** 6: + raise Invalid("x0 out of range") + v = Fraction(0) + for a in reversed(inst["coeffs"]): + v = v * x0 + a + fmin = Fraction(inst["fmin"]) + tol = Fraction(1, 10 ** 9) * max(Fraction(1), abs(fmin)) + if v > fmin + tol: + raise Invalid(f"f(x0) = {float(v)} is above the global minimum {float(fmin)}") + if v < fmin - tol: # cannot happen for a correct f_min; guards against a bad instance + raise Invalid("internal: f(x0) below recorded minimum") + return None, {"f_x0": float(v)} diff --git a/tasks/construct-rlve-polynomial-global-minimum-l2-s7/tests/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l2-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..36a81fb9cc562c8e5bb99837a4374bdb7fa032f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l2-s7/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [40, -56, 50, -16, 2], "fmin": "19.7346895646033218508698818641353958279729113", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l2-s7/tests/run.py b/tasks/construct-rlve-polynomial-global-minimum-l2-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l2-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-global-minimum-l2-s7/tests/test.sh b/tasks/construct-rlve-polynomial-global-minimum-l2-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l2-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-global-minimum-l6-s8/environment/Dockerfile b/tasks/construct-rlve-polynomial-global-minimum-l6-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l6-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-global-minimum-l6-s8/environment/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l6-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a38b8a274deaa4c690f0f7b8b0a7c29bb8527eb8 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l6-s8/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [33413, 231790, 749715, 1494528, 2053610, 2049636, 1539820, 877160, 385421, 127698, 32165, 5800, 730, 56, 2], "fmin": "804.264456026734478923457362303020999634080037", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l6-s8/solution/solve.sh b/tasks/construct-rlve-polynomial-global-minimum-l6-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..bedac2a92daf7004e98fc8dd4cc225e2fe496da3 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l6-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x0": -0.565365562277958} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-global-minimum-l6-s8/tests/check.py b/tasks/construct-rlve-polynomial-global-minimum-l6-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3be068f4391ad0838c29a4f7d521b8072cf39991 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l6-s8/tests/check.py @@ -0,0 +1,19 @@ +from fractions import Fraction + +from run import Invalid, num + + +def check(inst, ans): + x0 = Fraction(num(ans.get("x0"), "x0")) + if abs(x0) > 10 ** 6: + raise Invalid("x0 out of range") + v = Fraction(0) + for a in reversed(inst["coeffs"]): + v = v * x0 + a + fmin = Fraction(inst["fmin"]) + tol = Fraction(1, 10 ** 9) * max(Fraction(1), abs(fmin)) + if v > fmin + tol: + raise Invalid(f"f(x0) = {float(v)} is above the global minimum {float(fmin)}") + if v < fmin - tol: # cannot happen for a correct f_min; guards against a bad instance + raise Invalid("internal: f(x0) below recorded minimum") + return None, {"f_x0": float(v)} diff --git a/tasks/construct-rlve-polynomial-global-minimum-l6-s8/tests/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l6-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a38b8a274deaa4c690f0f7b8b0a7c29bb8527eb8 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l6-s8/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [33413, 231790, 749715, 1494528, 2053610, 2049636, 1539820, 877160, 385421, 127698, 32165, 5800, 730, 56, 2], "fmin": "804.264456026734478923457362303020999634080037", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l6-s8/tests/run.py b/tasks/construct-rlve-polynomial-global-minimum-l6-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l6-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-global-minimum-l6-s8/tests/test.sh b/tasks/construct-rlve-polynomial-global-minimum-l6-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l6-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-integer-roots-l5-s2/environment/Dockerfile b/tasks/construct-rlve-polynomial-integer-roots-l5-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l5-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-integer-roots-l5-s2/environment/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l5-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..def1550fda22b8db4fa2bc9ca3e14b079edcef3c --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l5-s2/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [226663557120000, 324065798784000, 89491910947200, -16351303539840, -8986501876184, -305552970180, 270912904410, 28498183857, -2973198603, -532044096, 6655012, 4241682, 88746, -15444, -582, 21, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l5-s2/solution/solve.sh b/tasks/construct-rlve-polynomial-integer-roots-l5-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5adb0514788973634bfbad6c324f191bffa7bab6 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l5-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"roots": [-15, -12, -11, -10, -9, -8, -7, -7, -4, -1, 5, 6, 10, 13, 13, 16]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-integer-roots-l5-s2/tests/check.py b/tasks/construct-rlve-polynomial-integer-roots-l5-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2d30553cb884c5e03c8afe73ef652efc483ab791 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l5-s2/tests/check.py @@ -0,0 +1,20 @@ +from run import Invalid, int_list + + +def check(inst, ans): + c = inst["coeffs"] # c[i] = coefficient of x^i, monic of degree len(c) - 1 + n = len(c) - 1 + r = int_list(ans.get("roots"), n, name="roots") + bound = 1 + max(abs(v) for v in c) # Cauchy bound on roots + if any(abs(a) > bound for a in r): # any integer root divides the constant term / is bounded by max|c_i| + raise Invalid("root out of range") + prod = [1] + for a in r: # multiply by (x - a) + nxt = [0] * (len(prod) + 1) + for i, v in enumerate(prod): + nxt[i + 1] += v + nxt[i] -= a * v + prod = nxt + if prod != c: + raise Invalid("the product does not expand to P(x)") + return None, {} diff --git a/tasks/construct-rlve-polynomial-integer-roots-l5-s2/tests/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l5-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..def1550fda22b8db4fa2bc9ca3e14b079edcef3c --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l5-s2/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [226663557120000, 324065798784000, 89491910947200, -16351303539840, -8986501876184, -305552970180, 270912904410, 28498183857, -2973198603, -532044096, 6655012, 4241682, 88746, -15444, -582, 21, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l5-s2/tests/run.py b/tasks/construct-rlve-polynomial-integer-roots-l5-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l5-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-integer-roots-l5-s2/tests/test.sh b/tasks/construct-rlve-polynomial-integer-roots-l5-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l5-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-interpolation-l6-s2/tests/instance.json b/tasks/construct-rlve-polynomial-interpolation-l6-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0ddbddd3eeb101425f7a884dbb552c70837ef7f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l6-s2/tests/instance.json @@ -0,0 +1 @@ +{"X": [16, -15, 2, 5, -9, 8, 12, 6, -12, 1, 11, -17, -11, 14, -13, 3, 13, 7, 17], "Y": [22984652334144338783230, 7573371106088914393723, 929990, 17244921778523, 780116823665180755, 85006576829218046, 128309895603341528830, 468331090999990, 137183918001259586686, -5, 26696864093202199235, 71872561310905048577971, 28718516398686658267, 2069057298843034121942, 578246458095618448355, 1595741731, 543645991581742010011, 7610540807807635, 68563639607499959582075], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l6-s3/environment/Dockerfile b/tasks/construct-rlve-polynomial-interpolation-l6-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l6-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-interpolation-l6-s3/environment/instance.json b/tasks/construct-rlve-polynomial-interpolation-l6-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3995b5ce49aaa49295d4665161b32cd3e3c391c8 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l6-s3/environment/instance.json @@ -0,0 +1 @@ +{"X": [-12, 17, 9, -15, -11, 12, 2, 3, 1, 4, 13, -10, 6, -14, -16, -5, -1, 15, -17], "Y": [74698078822391405235, 43649794214300099405319, 476326279877929167, 4210461041507507211303, 15486482568262947827, 83573171142477652659, 893439, 1274336985, 23, 224676198707, 352022120891395654235, 2760372561182670303, 327609121674783, 1210984275454873306943, 13503292151267620356867, 9329113941953, -3, 4604577289142538955053, 40340773465346910331085], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l6-s3/solution/solve.sh b/tasks/construct-rlve-polynomial-interpolation-l6-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c67ab68b76fcd57bef9090a061b2f9d2497d29e9 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l6-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coeffs": [3, 0, 3, 0, -3, 3, 3, 2, 2, -1, -4, 4, 3, 3, 4, 0, -4, 2, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-interpolation-l6-s3/tests/check.py b/tasks/construct-rlve-polynomial-interpolation-l6-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f05264e3fd4584db7cb3768800e4a2497564b4f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l6-s3/tests/check.py @@ -0,0 +1,13 @@ +from run import Invalid, int_list + + +def check(inst, ans): + X, Y = inst["X"], inst["Y"] + c = int_list(ans.get("coeffs"), len(X), name="coeffs") + for x, y in zip(X, Y): + v = 0 + for a in reversed(c): + v = v * x + a + if v != y: + raise Invalid(f"f({x}) = {v}, need {y}") + return None, {} diff --git a/tasks/construct-rlve-polynomial-interpolation-l6-s3/tests/instance.json b/tasks/construct-rlve-polynomial-interpolation-l6-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3995b5ce49aaa49295d4665161b32cd3e3c391c8 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l6-s3/tests/instance.json @@ -0,0 +1 @@ +{"X": [-12, 17, 9, -15, -11, 12, 2, 3, 1, 4, 13, -10, 6, -14, -16, -5, -1, 15, -17], "Y": [74698078822391405235, 43649794214300099405319, 476326279877929167, 4210461041507507211303, 15486482568262947827, 83573171142477652659, 893439, 1274336985, 23, 224676198707, 352022120891395654235, 2760372561182670303, 327609121674783, 1210984275454873306943, 13503292151267620356867, 9329113941953, -3, 4604577289142538955053, 40340773465346910331085], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l6-s3/tests/run.py b/tasks/construct-rlve-polynomial-interpolation-l6-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l6-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-interpolation-l6-s3/tests/test.sh b/tasks/construct-rlve-polynomial-interpolation-l6-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l6-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-interpolation-l6-s4/environment/Dockerfile b/tasks/construct-rlve-polynomial-interpolation-l6-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l6-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-interpolation-l6-s4/environment/instance.json b/tasks/construct-rlve-polynomial-interpolation-l6-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5738fa590b52afebfca8282f131fa2bff61c8852 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l6-s4/environment/instance.json @@ -0,0 +1 @@ +{"X": [-6, -9, 0, -7, -8, 4, -3, -10, 18, -2, 3, 15, -14, -4, -16, -12, 10, -1, 5], "Y": [514888084817072, 761056249466439875, 2, 8261787103435007, 91385118295515402, 314707973502, 1880010887, 5067464597180780612, 194193518771557643040632, 1075932, 1693425707, 7271966341156601397587, 2157982153896815552280, 344200676870, 23848957278736585985042, 134743004719968279182, 4871545403221178592, -13, 17889606426647], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l6-s4/solution/solve.sh b/tasks/construct-rlve-polynomial-interpolation-l6-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..fff1bca8abd1751b7276c31056e7fadb5c436a98 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l6-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coeffs": [2, -1, -4, -1, -2, 2, 1, 2, 2, 3, 0, 4, 5, 4, -5, 2, -3, -1, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-interpolation-l6-s4/tests/check.py b/tasks/construct-rlve-polynomial-interpolation-l6-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f05264e3fd4584db7cb3768800e4a2497564b4f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l6-s4/tests/check.py @@ -0,0 +1,13 @@ +from run import Invalid, int_list + + +def check(inst, ans): + X, Y = inst["X"], inst["Y"] + c = int_list(ans.get("coeffs"), len(X), name="coeffs") + for x, y in zip(X, Y): + v = 0 + for a in reversed(c): + v = v * x + a + if v != y: + raise Invalid(f"f({x}) = {v}, need {y}") + return None, {} diff --git a/tasks/construct-rlve-polynomial-interpolation-l6-s4/tests/instance.json b/tasks/construct-rlve-polynomial-interpolation-l6-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5738fa590b52afebfca8282f131fa2bff61c8852 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l6-s4/tests/instance.json @@ -0,0 +1 @@ +{"X": [-6, -9, 0, -7, -8, 4, -3, -10, 18, -2, 3, 15, -14, -4, -16, -12, 10, -1, 5], "Y": [514888084817072, 761056249466439875, 2, 8261787103435007, 91385118295515402, 314707973502, 1880010887, 5067464597180780612, 194193518771557643040632, 1075932, 1693425707, 7271966341156601397587, 2157982153896815552280, 344200676870, 23848957278736585985042, 134743004719968279182, 4871545403221178592, -13, 17889606426647], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l6-s4/tests/run.py b/tasks/construct-rlve-polynomial-interpolation-l6-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l6-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-interpolation-l6-s4/tests/test.sh b/tasks/construct-rlve-polynomial-interpolation-l6-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l6-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prefix-product-permutation-l2-s9/environment/Dockerfile b/tasks/construct-rlve-prefix-product-permutation-l2-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l2-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prefix-product-permutation-l2-s9/environment/instance.json b/tasks/construct-rlve-prefix-product-permutation-l2-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bb065b11048419da75bd01796319b82aa7d39ebe --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l2-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 53, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l2-s9/solution/solve.sh b/tasks/construct-rlve-prefix-product-permutation-l2-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f05f78d7d5edc84d2f7911ee4c62238ffc1fa68b --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l2-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"perm": [1, 2, 28, 19, 41, 33, 10, 39, 21, 7, 17, 30, 32, 50, 20, 47, 11, 26, 4, 15, 9, 49, 42, 31, 43, 18, 52, 3, 37, 12, 24, 13, 6, 46, 40, 51, 29, 44, 8, 35, 5, 23, 25, 38, 48, 34, 16, 45, 22, 14, 36, 27, 53]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-product-permutation-l2-s9/tests/check.py b/tasks/construct-rlve-prefix-product-permutation-l2-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3d93850acd79cc0f8fff05cdbb0c63aabc484815 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l2-s9/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("perm"), n, 1, n, "perm") + if len(set(p)) != n: + raise Invalid("not a permutation") + seen, acc = set(), 1 + for v in p: + acc = acc * v % n + if acc in seen: + raise Invalid(f"prefix product residue {acc} repeats") + seen.add(acc) + return None, {} diff --git a/tasks/construct-rlve-prefix-product-permutation-l2-s9/tests/instance.json b/tasks/construct-rlve-prefix-product-permutation-l2-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bb065b11048419da75bd01796319b82aa7d39ebe --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l2-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 53, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l2-s9/tests/run.py b/tasks/construct-rlve-prefix-product-permutation-l2-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l2-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prefix-product-permutation-l2-s9/tests/test.sh b/tasks/construct-rlve-prefix-product-permutation-l2-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l2-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prefix-product-permutation-l6-s1/environment/Dockerfile b/tasks/construct-rlve-prefix-product-permutation-l6-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l6-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prefix-product-permutation-l6-s1/environment/instance.json b/tasks/construct-rlve-prefix-product-permutation-l6-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..69c121c6174fff7a31874c600882d260e3293587 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l6-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 18593, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l6-s1/solution/solve.sh b/tasks/construct-rlve-prefix-product-permutation-l6-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f724f50dea49f801cfdd83fcd04e87e11d6de822 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l6-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"perm": [1, 2, 9298, 6199, 13946, 11157, 3100, 15938, 16270, 2067, 5579, 11833, 10847, 5722, 17266, 16115, 17432, 7657, 1034, 11744, 2790, 11511, 5917, 4043, 5424, 13388, 12158, 13085, 17930, 4489, 8058, 5399, 18013, 3945, 3829, 6907, 9814, 17589, 15169, 1908, 10692, 908, 5756, 2163, 2959, 11570, 2022, 1979, 12009, 7590, 15991, 2553, 15376, 5614, 6543, 6086, 18262, 10113, 2245, 6934, 13326, 17070, 2700, 16233, 9007, 12301, 1973, 18039, 1915, 7546, 3454, 2096, 14204, 2548, 8795, 10661, 7585, 14972, 10251, 7297, 14643, 10560, 9751, 18370, 12175, 12688, 1082, 1497, 1480, 16296, 15082, 14099, 10308, 7998, 990, 17224, 6005, 13802, 13092, 13711, 7996, 10310, 1277, 12276, 16985, 2303, 12104, 5214, 3272, 10918, 12340, 18259, 18428, 8228, 5057, 4528, 1123, 13032, 12764, 6407, 15960, 9528, 17832, 6501, 10647, 6397, 8117, 17862, 4504, 13117, 6151, 14478, 987, 9647, 9020, 10055, 958, 17644, 13070, 7893, 11024, 6858, 10345, 12353, 16399, 15773, 10571, 14926, 4398, 1748, 5331, 10221, 3793, 13247, 16783, 15955, 5126, 9712, 3649, 1872, 7322, 11203, 14577, 8442, 4876, 8227, 18482, 18260, 6088, 6162, 15641, 15767, 9838, 16552, 749, 12538, 10037, 2312, 17445, 11323, 16838, 10787, 7050, 18086, 14451, 18393, 13296, 697, 9792, 17807, 17909, 13240, 3003, 9153, 16198, 4101, 15843, 1983, 6856, 11026, 13295, 18409, 14452, 16579, 639, 3901, 15435, 2516, 8493, 16281, 1152, 11897, 15349, 6897, 11904, 4152, 10933, 16709, 14756, 850, 15467, 13462, 9130, 12174, 18511, 9752, 13411, 14171, 2529, 2112, 11561, 11189, 562, 9497, 15813, 15271, 15679, 2433, 3204, 15560, 17277, 6713, 14061, 15916, 18213, 8956, 3251, 5195, 5324, 6124, 3199, 4890, 4059, 3749, 18228, 4230, 11549, 16713, 6559, 10482, 3076, 12895, 16536, 16968, 494, 15998, 4824, 17828, 13807, 2904, 5028, 17016, 9776, 10898, 18119, 1218, 15832, 3827, 3947, 15062, 14809, 18197, 12726, 658, 5173, 5742, 6177, 8099, 8200, 9201, 7887, 10799, 5286, 8187, 16760, 16262, 11496, 4571, 10171, 13184, 2666, 2966, 5111, 9635, 1897, 10852, 6624, 10963, 8392, 16488, 7978, 3887, 11860, 4575, 14153, 6966, 1825, 2875, 10233, 409, 12958, 14134, 5602, 7254, 7289, 2461, 13518, 3640, 11735, 8252, 4114, 10112, 18538, 6087, 18427, 18483, 12341, 6732, 12378, 8941, 7821, 2182, 7884, 17022, 14216, 1510, 17573, 15004, 375, 16463, 15566, 16740, 5019, 3688, 10453, 420, 8723, 8334, 5662, 15124, 17716, 12362, 5394, 15572, 12822, 4229, 18340, 3750, 7226, 14563, 9197, 3459, 15945, 3590, 349, 2133, 14193, 17509, 8904, 7605, 8955, 18350, 15917, 18060, 1502, 14151, 4577, 4373, 17396, 15535, 2051, 6801, 7922, 17222, 992, 12616, 12725, 18313, 14810, 9414, 6648, 1392, 9205, 17579, 16523, 9550, 8290, 8361, 320, 5638, 1951, 5882, 7718, 11616, 10555, 11112, 4247, 15027, 8141, 356, 9873, 2695, 5949, 14682, 7675, 6257, 3449, 13064, 15249, 10316, 11373, 3409, 5467, 2148, 8355, 11456, 16675, 15871, 9722, 17874, 7734, 4976, 16028, 17167, 13862, 3260, 15384, 6781, 9256, 2527, 14173, 3464, 6706, 15803, 7086, 17695, 1265, 2971, 10353, 10614, 5781, 9358, 5595, 9679, 9578, 5319, 4749, 4062, 7907, 5234, 7636, 3238, 7840, 15410, 1217, 18320, 10899, 13020, 17077, 1903, 8639, 14226, 3357, 3735, 7031, 13917, 17255, 17525, 9107, 15210, 13775, 2576, 1626, 265, 2598, 2743, 11959, 13581, 12359, 14160, 1600, 12285, 11742, 1036, 2030, 9500, 1875, 14450, 18411, 7051, 11412, 3021, 5775, 11454, 8357, 2456, 3280, 13703, 14538, 5518, 10835, 6389, 6448, 10524, 17565, 4180, 17781, 13443, 9544, 13111, 17296, 6969, 11709, 1501, 18211, 15918, 6904, 3775, 10749, 7452, 11811, 15604, 17805, 9794, 14185, 5903, 14746, 7445, 9060, 12227, 9906, 10023, 17213, 14324, 1914, 18527, 1974, 14121, 16828, 4458, 7405, 233, 9099, 6639, 15660, 5365, 9626, 12134, 2587, 12026, 12168, 12570, 3089, 4414, 4050, 4625, 13397, 7928, 4601, 15447, 3944, 18562, 5400, 17414, 11940, 13763, 4094, 14603, 17677, 5178, 17428, 13057, 15045, 1506, 2286, 12438, 5086, 3676, 15889, 17818, 10630, 5384, 10780, 6137, 2556, 5625, 4818, 16021, 949, 5527, 14723, 11595, 12609, 4672, 5482, 1301, 13493, 6721, 17541, 8892, 13286, 7037, 1944, 4985, 15227, 12436, 2288, 17823, 7077, 3223, 12780, 16001, 913, 10164, 1438, 14729, 5117, 2015, 205, 14695, 15776, 4642, 16364, 3789, 12098, 13780, 12924, 7329, 3645, 17534, 1231, 11768, 16056, 3190, 11117, 6615, 5868, 284, 13423, 12528, 11354, 16625, 14353, 4488, 18566, 13086, 3044, 12322, 9214, 16454, 9242, 3243, 6171, 6742, 12663, 9449, 15486, 8350, 4471, 9941, 3911, 10922, 10388, 9175, 13239, 18404, 17808, 13100, 16405, 1863, 10052, 1454, 8787, 9928, 16799, 5298, 188, 8804, 8232, 9364, 17080, 14085, 17667, 4841, 2510, 5091, 11141, 6786, 5227, 7134, 9507, 13207, 4362, 9128, 13464, 6190, 12128, 11385, 16859, 7733, 18155, 9723, 15478, 8436, 11994, 6874, 17083, 1024, 15708, 5306, 2115, 4503, 18467, 8118, 11172, 2986, 12910, 15163, 7282, 15600, 4599, 7930, 1730, 11362, 7973, 4069, 11092, 2042, 175, 6058, 1067, 8889, 7097, 14026, 8755, 2045, 13749, 17194, 3803, 7448, 4478, 6500, 18472, 9529, 7959, 13806, 18327, 4825, 10048, 4208, 7076, 17967, 2289, 15419, 2187, 10629, 17995, 15890, 7768, 15706, 1026, 3572, 3401, 4299, 13258, 13099, 17908, 18405, 9793, 18052, 15605, 14457, 6363, 1314, 9157, 11531, 16702, 10149, 14004, 8867, 12621, 12141, 9993, 15445, 4603, 5960, 8790, 13364, 8262, 6643, 14072, 8988, 13442, 18068, 4181, 12845, 9457, 8922, 12116, 9831, 976, 14042, 12238, 4926, 13156, 12802, 15105, 16031, 5278, 9376, 14853, 7474, 2124, 16853, 7514, 11090, 4071, 11219, 9475, 1929, 4937, 5926, 1348, 12264, 2975, 12389, 16638, 1362, 3838, 220, 3129, 9658, 1725, 10856, 15829, 14310, 7625, 4774, 14455, 15607, 5687, 8898, 1705, 7003, 2734, 14467, 10371, 15463, 4178, 17567, 15025, 4249, 8338, 9798, 7936, 6227, 14158, 12361, 18234, 15125, 13164, 6670, 11785, 17478, 17311, 11619, 8584, 6017, 16228, 10521, 10927, 7722, 16989, 4998, 3391, 5984, 13925, 10593, 1264, 18139, 7087, 4706, 11029, 7187, 12650, 13314, 7902, 42, 12840, 9410, 8848, 2593, 633, 8432, 1486, 3618, 5177, 18006, 14604, 10825, 2891, 3655, 13976, 11604, 2798, 7398, 4840, 17892, 14086, 15732, 2660, 1379, 2375, 7494, 11328, 11296, 3954, 1013, 11914, 13921, 13115, 4506, 10916, 3274, 13217, 14718, 17002, 2573, 609, 13069, 18457, 959, 5450, 6849, 15807, 10086, 8539, 137, 952, 13146, 4320, 3174, 16410, 4712, 1679, 5550, 1868, 3635, 3516, 14814, 6959, 4520, 8628, 11753, 8763, 821, 4554, 14255, 16902, 11624, 6888, 1214, 10585, 8191, 10110, 4116, 133, 8949, 10596, 95, 1372, 395, 5980, 9569, 6791, 2206, 6180, 16841, 16377, 14425, 10097, 9734, 6143, 14627, 15168, 18557, 9815, 1275, 10312, 13029, 14047, 14640, 938, 6682, 16522, 18191, 9206, 2981, 3526, 4964, 15003, 18248, 1511, 728, 2888, 781, 15024, 17725, 4179, 18070, 10525, 5844, 10937, 19, 6852, 504, 16566, 8661, 12056, 10577, 5418, 5002, 3195, 8219, 12521, 3257, 14559, 11686, 8783, 16857, 11387, 7095, 8891, 17976, 6722, 13536, 14069, 1461, 6556, 1230, 17945, 3646, 3485, 1960, 5855, 12536, 751, 9707, 9106, 18107, 17256, 15174, 12749, 7660, 1888, 11987, 5375, 5042, 13023, 1414, 5906, 87, 17099, 10319, 8903, 18217, 14194, 7014, 7093, 11389, 2952, 2830, 16670, 1549, 3723, 7608, 13827, 12950, 6114, 14669, 14250, 13646, 5012, 6238, 8607, 13849, 16459, 4855, 10254, 15090, 9264, 6009, 10284, 13549, 7061, 17310, 17711, 11786, 11526, 7395, 3703, 14066, 117, 5564, 4550, 13107, 3320, 14882, 17127, 13357, 2683, 5837, 14110, 7878, 15364, 2835, 1294, 14931, 15310, 8718, 15381, 3863, 15582, 12315, 1545, 11579, 11504, 4167, 11322, 18416, 2313, 211, 6699, 7951, 13261, 17113, 2301, 16987, 7724, 8728, 11269, 7656, 18578, 16116, 11997, 13056, 18004, 5179, 15267, 13234, 6882, 11703, 11344, 14663, 7302, 3055, 8839, 7236, 11886, 11939, 18011, 5401, 6529, 16818, 7523, 4206, 10050, 1865, 10440, 17343, 15516, 6105, 11840, 6687, 11135, 10550, 7945, 15534, 18206, 4374, 14612, 5373, 11989, 12860, 14687, 5062, 3069, 12155, 10575, 12058, 2813, 12990, 11706, 982, 8011, 3184, 475, 276, 2764, 4287, 7362, 15183, 5798, 13121, 6305, 1792, 11633, 1880, 12038, 1060, 651, 6828, 6747, 8159, 3361, 8477, 8771, 14190, 13743, 16268, 15940, 14369, 3519, 7510, 10269, 16100, 2493, 16104, 7614, 6417, 15515, 17405, 10441, 12243, 8912, 8416, 3539, 6317, 1612, 4904, 15687, 9644, 8001, 899, 457, 15625, 14379, 4198, 10016, 17290, 7365, 6028, 2559, 8779, 1008, 8284, 103, 6320, 7348, 2545, 17185, 10553, 11618, 17710, 17479, 7062, 1895, 9637, 15346, 7343, 16187, 15728, 15759, 1137, 3665, 13253, 1823, 6968, 18064, 13112, 616, 5103, 15181, 7364, 17325, 10017, 10892, 14056, 5559, 10725, 3308, 5291, 12231, 794, 9439, 7113, 6712, 18354, 15561, 10249, 14974, 12584, 8313, 7857, 7177, 6919, 11541, 16114, 18580, 5723, 15840, 12699, 10819, 12666, 15458, 7285, 13904, 15173, 17524, 18108, 13918, 2261, 1622, 4805, 3086, 15456, 12668, 843, 6332, 3047, 4725, 11933, 17040, 7353, 13472, 3404, 2236, 3536, 4971, 11466, 1956, 848, 14758, 8404, 14491, 5899, 4588, 8257, 6620, 6004, 18499, 991, 18201, 7923, 15847, 3963, 8203, 15934, 932, 16221, 14323, 18042, 10024, 3120, 4394, 11922, 14261, 11878, 8400, 3227, 11946, 402, 9391, 1576, 13699, 14169, 13413, 3315, 13979, 3802, 17837, 13750, 7043, 12869, 8834, 14796, 2421, 7943, 10552, 17314, 2546, 14206, 5571, 1080, 12690, 3851, 2614, 2271, 12864, 11335, 4754, 15650, 6604, 5737, 11478, 12305, 13861, 18151, 16029, 15107, 12392, 16736, 15361, 16012, 5693, 16495, 8430, 635, 3867, 9950, 9078, 13149, 4862, 17138, 17036, 1841, 13515, 5886, 15294, 13641, 12734, 9573, 8542, 692, 9809, 17035, 17151, 4863, 11950, 4525, 1058, 12040, 2252, 7639, 9234, 12794, 13356, 17466, 14883, 7785, 10790, 1720, 15752, 7057, 7582, 14409, 12938, 12325, 17097, 89, 2300, 17439, 13262, 8376, 10162, 915, 14978, 1689, 3987, 10490, 2035, 16923, 14843, 11371, 10318, 17512, 88, 17116, 12326, 6885, 534, 385, 4445, 16491, 3549, 594, 16310, 8366, 4378, 346, 1023, 17868, 6875, 14084, 17894, 9365, 1902, 18116, 13021, 5044, 11536, 11015, 12547, 2699, 18533, 13327, 4765, 2351, 3980, 4099, 16200, 5806, 9164, 13403, 2413, 5912, 14321, 16223, 11401, 16214, 12835, 6444, 8984, 6279, 1145, 7017, 7710, 1924, 1094, 14873, 5315, 10766, 8998, 7352, 17242, 11934, 13181, 1840, 17150, 17139, 9810, 1740, 11083, 8328, 1701, 8353, 2150, 12602, 15926, 15904, 6550, 14215, 18251, 7885, 9203, 1394, 4897, 9775, 18323, 5029, 7803, 16877, 7229, 6414, 3182, 8013, 9954, 4371, 4579, 15306, 5766, 2572, 17648, 14719, 5075, 14957, 16299, 2085, 4434, 501, 6311, 13728, 6071, 8271, 4997, 17702, 7723, 17437, 2302, 18490, 12277, 1259, 13692, 2779, 15979, 16326, 13428, 14880, 3322, 2918, 16333, 1343, 13791, 5202, 16018, 493, 18331, 16537, 2091, 9463, 6423, 9326, 4729, 8176, 13758, 8166, 15355, 10757, 4916, 13682, 9785, 8680, 16318, 10978, 15416, 12807, 11760, 10274, 15875, 15031, 15698, 14247, 7553, 15737, 8016, 13179, 11936, 2795, 13985, 10973, 7427, 12762, 13034, 7872, 10359, 12374, 8427, 3124, 13054, 11999, 14842, 17103, 2036, 7536, 5610, 7416, 4738, 13882, 965, 13046, 2469, 4558, 12260, 6276, 9971, 12503, 15429, 3616, 1488, 14609, 6195, 11623, 17616, 14256, 9978, 1789, 11216, 3770, 9407, 10266, 1565, 10243, 14126, 9696, 863, 11593, 14725, 10207, 7915, 2438, 16452, 9216, 3813, 16586, 11684, 14561, 7228, 17013, 7804, 1472, 2844, 5997, 13746, 8936, 853, 7740, 3502, 14406, 10664, 743, 7234, 8841, 5186, 9614, 7732, 17876, 11386, 17545, 8784, 1562, 7513, 17761, 2125, 6188, 13466, 7012, 14196, 150, 13265, 12003, 3114, 8379, 16376, 17597, 6181, 10786, 18414, 11324, 7563, 2485, 15879, 11066, 12632, 8670, 5893, 4457, 18036, 14122, 8656, 2513, 5810, 11161, 13589, 4353, 3009, 7522, 17411, 6530, 5261, 12898, 5464, 12800, 13158, 16279, 8495, 16542, 11796, 8616, 1696, 7380, 12289, 1226, 6963, 10910, 5297, 17900, 9929, 5940, 9070, 13013, 3544, 11801, 11650, 7993, 5515, 13629, 3594, 6329, 15622, 8244, 15954, 18440, 13248, 14779, 9318, 14271, 15717, 1935, 14002, 10151, 13721, 5341, 1297, 11628, 317, 15721, 13513, 1843, 10040, 15219, 11106, 12024, 2589, 16261, 18300, 8188, 16599, 8422, 5413, 1558, 1446, 5081, 1828, 8556, 16285, 6632, 15099, 9373, 10696, 7402, 12996, 2241, 11717, 5018, 18243, 15567, 16340, 15360, 17163, 12393, 10627, 2189, 690, 8544, 1188, 8156, 13044, 967, 14961, 7860, 14945, 160, 11274, 9094, 507, 4146, 15254, 4518, 6961, 1228, 6558, 18337, 11550, 5728, 14755, 18377, 10934, 1075, 6609, 8515, 16656, 10148, 17798, 11532, 1287, 8959, 305, 7744, 6535, 15784, 9229, 1517, 480, 9957, 12022, 11108, 3425, 40, 7904, 5650, 14340, 6870, 4270, 555, 69, 11050, 9773, 4899, 15870, 18158, 11457, 11422, 10884, 1548, 17502, 2831, 11653, 9119, 840, 13659, 12072, 2283, 10231, 2877, 1818, 4594, 11055, 10147, 16704, 8516, 3480, 14839, 11557, 623, 13611, 10545, 5877, 12043, 4382, 12956, 411, 12714, 11574, 10121, 7128, 1361, 17748, 12390, 15109, 1064, 12741, 11208, 9904, 12229, 5293, 14601, 4096, 13225, 14352, 17933, 11355, 6293, 67, 557, 4475, 2524, 14595, 16572, 48, 6587, 9983, 2751, 198, 11740, 12287, 7382, 4785, 7412, 3396, 13892, 10400, 16194, 12387, 2977, 8421, 16758, 8189, 10587, 7213, 14548, 5049, 4108, 14164, 6341, 3072, 11435, 7314, 11683, 16881, 3814, 9279, 13814, 4908, 13477, 638, 18391, 14453, 4776, 6515, 2248, 7024, 47, 16617, 14596, 9766, 9348, 12638, 8660, 17558, 505, 9096, 2784, 13900, 8104, 1491, 1673, 11060, 9512, 11779, 3612, 7502, 748, 18421, 9839, 756, 4847, 9661, 7985, 10741, 3059, 391, 11795, 16809, 8496, 8863, 12333, 2090, 16967, 18332, 12896, 5263, 10565, 12219, 2146, 5469, 2324, 10, 13017, 12723, 12618, 9549, 18190, 17580, 6683, 4331, 13379, 15325, 16177, 5289, 3310, 12006, 8614, 11798, 2295, 1598, 14162, 4110, 12429, 6261, 2057, 1629, 9133, 7280, 15165, 15140, 72, 4392, 3122, 8429, 17159, 5694, 16417, 3548, 17091, 4446, 7977, 18285, 8393, 12658, 7812, 16065, 230, 7035, 13288, 731, 14093, 12575, 14835, 9912, 4941, 8973, 14658, 11120, 833, 1743, 12408, 10277, 14774, 2928, 4682, 15565, 18245, 376, 4403, 4854, 17488, 13850, 11825, 9054, 9241, 17925, 9215, 16884, 2439, 6375, 2064, 13127, 434, 10241, 1567, 5994, 16191, 2688, 7756, 11818, 15557, 6512, 8776, 10004, 10895, 12250, 12838, 44, 15637, 8550, 4149, 5160, 5252, 4452, 15208, 9109, 4266, 16394, 15103, 12804, 2292, 3547, 16493, 5695, 13133, 10773, 342, 10712, 4711, 17632, 3175, 775, 7967, 1862, 17906, 13101, 11279, 6914, 13897, 15772, 18450, 12354, 13347, 7335, 15102, 16422, 4267, 16120, 11648, 11803, 996, 12416, 10498, 4304, 7955, 6925, 5055, 8230, 8806, 2428, 14590, 14424, 17596, 16842, 8380, 13929, 9151, 3005, 2644, 14439, 8090, 6775, 3040, 3531, 3788, 17952, 4643, 8856, 13340, 15190, 1357, 15060, 3949, 3698, 5598, 1852, 6879, 16330, 8481, 59, 11662, 12079, 2020, 11572, 12716, 6554, 1463, 10957, 15359, 16738, 15568, 8564, 6995, 6679, 4676, 1342, 16974, 2919, 8480, 16352, 6880, 13236, 13427, 16979, 15980, 1418, 5732, 9944, 10684, 7466, 10977, 16952, 8681, 13656, 12671, 7691, 6522, 1932, 8365, 17088, 595, 6158, 627, 773, 3177, 5790, 2176, 15049, 6796, 2084, 16998, 14958, 15081, 18505, 1481, 1157, 1609, 106, 6492, 3350, 5591, 3976, 7601, 6631, 16750, 8557, 178, 1151, 18385, 8494, 16811, 13159, 12070, 13661, 11338, 5635, 4463, 13125, 2066, 18586, 15939, 17355, 13744, 5999, 15257, 15825, 11495, 18299, 16761, 2590, 11969, 7634, 5236, 15914, 14063, 12738, 6061, 5852, 7389, 14969, 15922, 7332, 14530, 12948, 13829, 1528, 14616, 4420, 15133, 12915, 4367, 15240, 5586, 5970, 8931, 9006, 18531, 2701, 12496, 3265, 10520, 17706, 6018, 3762, 9427, 11400, 17057, 14322, 17215, 933, 11102, 14517, 5891, 8672, 12834, 17055, 11402, 3053, 7304, 15217, 10042, 3344, 8281, 5568, 6951, 14572, 15779, 3973, 5805, 17064, 4100, 18400, 9154, 11484, 12386, 16603, 10401, 2687, 16443, 5995, 2846, 15727, 17304, 7344, 5149, 11828, 5191, 1535, 12684, 6078, 8185, 5288, 16517, 15326, 3798, 1407, 10653, 15792, 4091, 15150, 13940, 9788, 2215, 4006, 15425, 10889, 2915, 238, 15392, 9435, 10943, 10679, 1710, 2144, 12221, 12978, 15989, 7592, 7665, 12196, 10480, 6561, 9742, 3153, 3835, 10193, 15370, 5817, 9559, 10237, 516, 15316, 15673, 9827, 11305, 326, 5078, 12711, 10879, 3374, 7491, 4080, 5548, 1681, 14038, 4239, 5840, 4386, 11647, 16392, 4268, 6872, 11996, 17431, 18579, 17267, 11542, 7185, 11031, 1760, 2717, 13052, 3126, 5135, 7613, 17347, 2494, 1247, 2492, 17349, 10270, 13104, 6360, 3209, 11816, 7758, 12208, 8703, 3730, 5221, 9895, 6122, 5326, 13753, 705, 13505, 9938, 1770, 12786, 3159, 208, 10103, 13039, 11749, 6954, 7844, 11145, 14119, 1976, 4001, 9338, 450, 4423, 229, 16484, 7813, 12460, 7190, 6666, 11396, 10328, 14305, 3189, 17942, 11769, 3683, 12850, 12311, 11246, 1280, 1411, 4390, 74, 9801, 11132, 13439, 2603, 52, 3220, 12457, 605, 12971, 12566, 1273, 9817, 8593, 15886, 5277, 17767, 15106, 17166, 18152, 4977, 8740, 8505, 12828, 1592, 948, 17987, 4819, 492, 16970, 5203, 3672, 10296, 8094, 5692, 17161, 15362, 7880, 6460, 569, 6570, 1833, 2335, 6627, 9746, 912, 17963, 12781, 4823, 18329, 495, 15853, 9251, 9605, 5155, 2552, 18544, 7591, 16153, 12979, 12054, 8663, 8396, 5009, 5826, 14743, 1417, 16325, 16980, 2780, 3326, 5363, 15662, 10951, 14437, 2646, 14667, 6116, 8274, 9694, 14128, 4720, 4796, 3557, 4121, 12653, 9527, 18474, 6408, 7781, 11240, 5125, 18439, 16784, 8245, 15589, 2224, 4157, 2623, 3929, 11331, 3589, 18222, 3460, 5682, 5771, 14368, 17354, 16269, 18587, 3101, 2862, 931, 17217, 8204, 6350, 9685, 5410, 301, 15630, 15903, 17026, 12603, 3643, 7331, 16249, 14970, 7587, 6903, 18059, 18212, 18351, 14062, 16256, 5237, 1131, 12759, 10108, 8193, 2403, 2153, 10840, 6549, 17025, 15927, 15631, 8721, 422, 12647, 12463, 6047, 1524, 63, 2363, 6100, 5967, 7767, 17817, 17996, 3677, 5276, 16033, 8594, 10999, 10508, 10415, 10699, 11065, 16834, 2486, 5544, 15030, 16946, 10275, 12410, 9721, 18157, 16676, 4900, 13499, 9335, 7246, 5506, 2950, 11391, 11591, 865, 4129, 8927, 12607, 11597, 12299, 9009, 9250, 15996, 496, 6637, 9101, 13602, 3962, 17220, 7924, 8611, 1982, 18398, 4102, 12698, 17264, 5724, 9763, 3609, 8111, 15521, 7162, 3826, 18318, 1219, 14309, 17740, 10857, 14401, 11494, 16264, 15258, 13622, 7131, 10434, 15236, 14862, 13497, 4902, 1614, 2617, 15270, 18360, 9498, 2032, 4696, 2825, 10085, 17640, 6850, 21, 7085, 18141, 6707, 6658, 1658, 4611, 6990, 925, 11198, 14894, 8919, 4090, 16172, 10654, 3522, 3766, 6435, 5512, 13714, 9228, 16695, 6536, 1211, 5606, 3972, 16203, 14573, 4641, 17954, 14696, 10570, 18449, 16400, 13898, 2786, 8511, 9837, 18423, 15642, 1092, 1926, 6943, 10604, 3230, 1136, 17302, 15729, 7682, 5668, 8731, 11674, 7056, 17122, 1721, 12599, 2406, 2869, 4357, 15036, 14476, 6153, 8466, 6931, 6518, 9076, 9952, 8015, 16941, 7554, 14679, 15493, 2659, 17665, 14087, 7681, 15758, 17303, 16188, 2847, 14239, 8248, 6244, 13512, 16769, 318, 8363, 1934, 16778, 14272, 12885, 13836, 8636, 6575, 13454, 11728, 5305, 17866, 1025, 17815, 7769, 921, 14941, 6758, 4924, 12240, 14246, 16944, 15032, 6821, 10949, 15664, 7410, 4787, 270, 13568, 14869, 9643, 17334, 4905, 3478, 8518, 3680, 8576, 7705, 2432, 18358, 15272, 1620, 2263, 10116, 9826, 16137, 15317, 11756, 10423, 6472, 3820, 2129, 13914, 7409, 15694, 10950, 15975, 5364, 18030, 6640, 7442, 10073, 3893, 14096, 14692, 3162, 10157, 6603, 17173, 4755, 3529, 3042, 13088, 2731, 7205, 1091, 15766, 18424, 6163, 13768, 8549, 16431, 45, 7026, 10447, 15379, 8720, 15902, 15928, 302, 13485, 6230, 14378, 17329, 458, 8243, 16786, 6330, 845, 6207, 1994, 10175, 14542, 9388, 1018, 15070, 8462, 5405, 7422, 736, 5686, 17735, 14456, 17804, 18053, 11812, 9341, 4598, 17855, 7283, 15460, 4809, 3443, 4657, 9564, 5354, 193, 9443, 2223, 15952, 8246, 14241, 1775, 11074, 9594, 12314, 17452, 3864, 13480, 12384, 11486, 3144, 9470, 7182, 512, 12821, 18231, 5395, 3438, 8563, 16339, 16739, 18244, 16464, 4683, 5620, 10248, 17276, 18355, 3205, 6511, 16439, 11819, 2228, 15065, 2948, 5508, 667, 6274, 12262, 1350, 13871, 9267, 13868, 6664, 7192, 2383, 11292, 1176, 9757, 11287, 7853, 2050, 18205, 17397, 7946, 12200, 12281, 13879, 12091, 6702, 13532, 1207, 6441, 12253, 2005, 7161, 15835, 8112, 261, 5701, 6104, 17404, 17344, 6418, 5909, 12519, 8221, 13789, 1345, 3140, 6024, 573, 14182, 3509, 6726, 13152, 14344, 10259, 12935, 9844, 3381, 7437, 7, 2658, 15734, 14680, 5951, 13796, 12564, 12973, 8349, 17918, 9450, 15264, 15283, 6591, 1751, 10217, 8435, 17872, 9724, 8570, 1384, 14202, 2098, 10167, 1668, 5542, 2488, 13461, 18374, 851, 8938, 4177, 17727, 10372, 4808, 15598, 7284, 17260, 12667, 17249, 3087, 12572, 3896, 7108, 3018, 9126, 4364, 3943, 18015, 4602, 17791, 9994, 8852, 2449, 14761, 4888, 3201, 9162, 5808, 2515, 18388, 3902, 2942, 8439, 10529, 3615, 16908, 12504, 15230, 10888, 16165, 4007, 12883, 14274, 962, 2186, 17821, 2290, 12806, 16950, 10979, 12180, 1585, 10583, 1216, 18121, 7841, 7360, 4289, 2538, 654, 7479, 11567, 8150, 13592, 1043, 10377, 11514, 12470, 251, 13706, 3156, 9434, 16161, 239, 3036, 12085, 4136, 12234, 2499, 6780, 18148, 3261, 3862, 17454, 8719, 15633, 10448, 5613, 18542, 2554, 6139, 11517, 630, 5816, 16143, 10194, 1390, 6650, 7990, 2834, 17460, 7879, 16011, 17162, 16737, 16341, 10958, 472, 10756, 16958, 8167, 9352, 672, 12425, 6896, 18382, 11898, 7342, 17306, 9638, 247, 13401, 9166, 7197, 8269, 6073, 1046, 4037, 4732, 446, 3212, 14734, 13960, 6098, 2365, 8076, 13385, 3797, 16176, 16518, 13380, 109, 7678, 944, 5379, 8761, 11755, 15672, 16138, 517, 4893, 9289, 13637, 8717, 17456, 14932, 14786, 5765, 17005, 4580, 6404, 10515, 15177, 3959, 14434, 6225, 7938, 11088, 7516, 13640, 17146, 5887, 7124, 10747, 3777, 10763, 7869, 1311, 13305, 2080, 6590, 15483, 15265, 5181, 1398, 4617, 6993, 8566, 5487, 1127, 3714, 1619, 15678, 18359, 15814, 2618, 13233, 17426, 5180, 15282, 15484, 9451, 4214, 14399, 10859, 13621, 15824, 16265, 6000, 4517, 16718, 4147, 8552, 2387, 10315, 18166, 13065, 7156, 12102, 2305, 13005, 10127, 11666, 5585, 16238, 4368, 483, 14861, 15820, 10435, 1235, 10119, 11576, 10887, 15427, 12505, 12435, 17970, 4986, 8053, 6252, 11865, 7715, 2465, 11105, 16765, 10041, 16210, 7305, 8750, 3098, 11159, 5812, 13774, 18105, 9108, 16425, 4453, 14286, 13596, 895, 12612, 14905, 8144, 11182, 1989, 4704, 7089, 14430, 15022, 783, 14297, 5122, 1356, 16360, 13341, 14145, 7221, 432, 13129, 5797, 17373, 7363, 17292, 5104, 9273, 3958, 15302, 10516, 12748, 17523, 17257, 13905, 7486, 1907, 18556, 17590, 14628, 15139, 16501, 7281, 17857, 12911, 12826, 8507, 10058, 13199, 3025, 10033, 4483, 10719, 13785, 2999, 13939, 16170, 4092, 13765, 12337, 427, 5532, 13167, 5351, 11048, 71, 16500, 15166, 14629, 9397, 372, 2651, 12914, 16241, 4421, 452, 11890, 5705, 14104, 10539, 13163, 17715, 18235, 5663, 14990, 14188, 8773, 4779, 13689, 2910, 10078, 1941, 3757, 3585, 8881, 14948, 1063, 16636, 12391, 17165, 16030, 17768, 12803, 16421, 16395, 7336, 9372, 16748, 6633, 4515, 6002, 6622, 10854, 1727, 4190, 9263, 17485, 10255, 8799, 4412, 3091, 11870, 14690, 14098, 18504, 16297, 14959, 969, 3782, 4225, 1243, 11086, 7940, 2805, 14830, 8461, 15613, 1019, 13632, 13839, 2947, 15554, 2229, 14808, 18315, 3948, 16358, 1358, 13625, 10178, 1257, 12279, 12202, 11831, 5581, 1801, 6795, 16302, 2177, 2103, 1505, 18002, 13058, 8410, 8706, 10802, 12562, 13798, 2631, 14475, 15746, 4358, 12029, 6820, 15697, 16945, 15876, 5545, 8140, 18177, 4248, 17724, 17568, 782, 15195, 14431, 13605, 8676, 10145, 11057, 12987, 14625, 6145, 10946, 9910, 14837, 3482, 9715, 14752, 7263, 2649, 374, 18247, 17574, 4965, 1807, 12267, 5266, 13832, 13854, 6507, 13526, 11069, 4586, 5901, 14187, 15122, 5664, 3997, 8831, 2758, 10485, 6815, 2040, 11094, 8065, 3165, 1688, 17108, 916, 13419, 12583, 17274, 10250, 18517, 7586, 15921, 16250, 7390, 4020, 13956, 9505, 7136, 7175, 7859, 16726, 968, 15080, 16298, 16999, 5076, 328, 6861, 5991, 2671, 11265, 649, 1062, 15111, 8882, 159, 16724, 7861, 12488, 6757, 15703, 922, 4620, 14317, 13825, 7610, 4930, 14850, 14785, 15309, 17457, 1295, 5343, 8131, 4397, 18447, 10572, 13391, 2579, 8300, 5954, 13508, 598, 2707, 13320, 10076, 2912, 10020, 6825, 2541, 5746, 10211, 6752, 13575, 354, 8143, 15202, 12613, 9028, 7550, 14672, 4687, 10558, 14645, 2239, 12998, 8918, 15795, 11199, 1121, 4530, 5859, 9024, 11806, 7374, 9122, 14333, 7784, 17126, 17467, 3321, 16977, 13429, 8582, 11621, 6197, 9300, 5314, 17045, 1095, 10988, 9642, 15689, 13569, 10183, 9891, 2504, 13375, 13496, 15819, 15237, 484, 11565, 7481, 14350, 13227, 6381, 7473, 17764, 9377, 14784, 14934, 4931, 13844, 14535, 254, 368, 11370, 17102, 16924, 12000, 11556, 16653, 3481, 15011, 9911, 16477, 12576, 2369, 9169, 8460, 15072, 2806, 12161, 14522, 7378, 1698, 9189, 8304, 14764, 11690, 538, 7847, 3305, 7833, 4258, 6958, 17625, 3517, 14371, 9413, 18196, 18314, 15063, 2230, 644, 6498, 4480, 8373, 153, 5349, 13169, 5209, 3268, 2420, 17189, 8835, 4615, 1400, 759, 11148, 9537, 8738, 4979, 5764, 15308, 14933, 14851, 9378, 1713, 2010, 9317, 16781, 13249, 8126, 12122, 2927, 16467, 10278, 12732, 13643, 11432, 2762, 278, 14649, 35, 11689, 14822, 8305, 4887, 15441, 2450, 8403, 17232, 849, 18376, 16710, 5729, 7262, 15008, 9716, 14739, 4561, 10071, 7444, 18048, 5904, 1416, 15982, 5827, 12258, 4560, 14750, 9717, 6745, 6830, 13959, 15333, 3213, 1142, 3014, 5116, 17959, 1439, 8646, 10206, 16888, 11594, 17984, 5528, 11441, 5074, 17001, 17649, 13218, 13555, 12775, 11037, 11427, 7420, 5407, 5779, 10616, 312, 6736, 6806, 8621, 5273, 8521, 2939, 4500, 6022, 3142, 11488, 10569, 15775, 17955, 206, 3161, 15654, 14097, 15084, 11871, 5061, 17390, 12861, 8653, 681, 7674, 18171, 5950, 15492, 15735, 7555, 11303, 9829, 12118, 6371, 4686, 14901, 7551, 14249, 17495, 6115, 15971, 2647, 7265, 7301, 17421, 11345, 7962, 6613, 11119, 16473, 8974, 8967, 6463, 5678, 14230, 3147, 581, 34, 14767, 279, 3534, 2238, 14898, 10559, 18514, 7298, 937, 17583, 14048, 9321, 3417, 3294, 4162, 4992, 2747, 1376, 10393, 9396, 15138, 15167, 17591, 6144, 15015, 12988, 2815, 2393, 12791, 13003, 2307, 10995, 4419, 16243, 1529, 14497, 5372, 17394, 4375, 6194, 16905, 1489, 8106, 4211, 10824, 17676, 18007, 4095, 16629, 5294, 12930, 3607, 9765, 16571, 16618, 2525, 9258, 11351, 14423, 16379, 2429, 3171, 5713, 10833, 5520, 5718, 11256, 12954, 4384, 5842, 10527, 8441, 18432, 11204, 3628, 4640, 15778, 16204, 6952, 11751, 8630, 6739, 7730, 9616, 7800, 9196, 18225, 7227, 16879, 11685, 17548, 3258, 13864, 10421, 11758, 12809, 12677, 24, 13172, 8309, 5048, 16595, 7214, 14180, 575, 13971, 9387, 15616, 10176, 13627, 5517, 18076, 13704, 253, 14847, 13845, 468, 10689, 12947, 16247, 7333, 13349, 10621, 746, 7504, 837, 7377, 14827, 12162, 14053, 10007, 5890, 16218, 11103, 2467, 13048, 10457, 9671, 6481, 9211, 12941, 4920, 9136, 9675, 2802, 2424, 3446, 4831, 587, 3993, 1967, 5371, 14614, 1530, 2396, 196, 2753, 5898, 17230, 8405, 13965, 13545, 2002, 4432, 2087, 6167, 12330, 10342, 331, 8484, 986, 18463, 6152, 15745, 15037, 2632, 5943, 5283, 8709, 6110, 13717, 10370, 17729, 2735, 9669, 10459, 5312, 9302, 13524, 6509, 3207, 6362, 17803, 15606, 17736, 4775, 16578, 18392, 18410, 18087, 1876, 3342, 10044, 2166, 13436, 6690, 216, 7663, 7594, 8089, 16370, 2645, 15973, 10952, 6224, 15300, 3960, 13604, 15021, 15196, 7090, 1148, 7274, 10096, 17595, 16378, 14591, 11352, 12530, 6215, 9656, 3131, 869, 1029, 526, 815, 5751, 4567, 9842, 12937, 17119, 7583, 10663, 16867, 3503, 9333, 13501, 11493, 15827, 10858, 15261, 4215, 1268, 8580, 13431, 12144, 7671, 8209, 4584, 11071, 1186, 8546, 770, 11520, 10488, 3989, 7772, 9143, 3333, 4197, 17328, 15626, 6231, 13203, 6325, 8033, 8846, 9412, 14812, 3518, 17353, 15941, 5772, 366, 256, 7047, 7788, 6288, 4736, 7418, 11429, 14253, 4556, 2471, 12756, 4487, 17932, 16626, 13226, 14857, 7482, 417, 3569, 872, 10258, 15501, 13153, 5139, 6869, 16684, 5651, 10761, 3779, 11638, 11238, 7783, 14885, 9123, 11415, 9485, 2172, 2202, 2476, 11724, 1913, 18041, 17214, 16222, 17058, 5913, 10300, 13824, 14938, 4621, 6484, 8963, 6051, 4608, 7624, 17739, 15830, 1220, 11234, 3188, 16058, 10329, 13949, 6564, 11777, 9514, 14278, 5121, 15193, 784, 5338, 12294, 5690, 8096, 2209, 10641, 5499, 13175, 13595, 15206, 4454, 7779, 6410, 12553, 9554, 13685, 5120, 14299, 9515, 5448, 961, 15422, 12884, 15716, 16779, 9319, 14050, 7819, 8943, 13572, 11911, 2075, 5217, 11877, 17208, 11923, 6812, 11523, 9977, 16901, 17617, 4555, 14358, 11430, 13645, 17494, 14670, 7552, 16943, 15699, 12241, 10443, 5005, 1774, 15587, 8247, 15725, 2848, 3560, 6567, 6429, 5387, 713, 9468, 3146, 14653, 5679, 2356, 3356, 18113, 8640, 1588, 14017, 388, 1200, 3984, 12402, 10228, 1509, 18250, 17023, 6551, 1949, 5640, 4014, 12754, 2473, 6949, 5570, 17183, 2547, 18522, 2097, 15474, 1385, 6674, 10463, 3668, 149, 16848, 7013, 17508, 18218, 2134, 13742, 17357, 8772, 15121, 14991, 5902, 18050, 9795, 3508, 15505, 574, 14546, 7215, 11449, 7599, 3978, 2353, 3463, 18144, 2528, 18367, 13412, 17199, 13700, 9308, 10511, 6340, 16592, 4109, 16509, 1599, 18095, 12360, 17718, 6228, 13487, 10908, 6965, 18280, 4576, 18209, 1503, 2105, 10619, 13351, 7220, 15188, 13342, 2169, 3388, 4310, 10817, 12701, 1766, 560, 11191, 5601, 18273, 12959, 2322, 5471, 13725, 4719, 15967, 9695, 16892, 10244, 679, 8655, 16827, 18037, 1975, 16072, 11146, 761, 12096, 3791, 10223, 8561, 3440, 7877, 17462, 5838, 4241, 664, 30, 10538, 15128, 5706, 6040, 9043, 10307, 18503, 15083, 14691, 15655, 3894, 12574, 16479, 732, 129, 5479, 942, 7680, 15731, 17666, 17893, 17081, 6876, 13579, 11961, 3498, 12594, 3340, 1878, 11635, 972, 9968, 8987, 17784, 6644, 1460, 17538, 13537, 116, 17473, 3704, 12737, 16255, 15915, 18352, 6714, 11165, 8490, 5558, 17287, 10893, 10006, 14520, 12163, 7818, 14269, 9320, 14639, 17584, 13030, 1125, 5489, 12237, 17773, 977, 4341, 4238, 16125, 1682, 6336, 3855, 3846, 8525, 12558, 9870, 10263, 12843, 4183, 8754, 17841, 7098, 298, 8425, 12376, 6734, 314, 4443, 387, 14223, 1589, 3290, 12192, 6982, 10385, 4204, 7525, 3602, 12695, 1367, 10339, 8866, 17796, 10150, 16776, 1936, 7541, 9603, 9253, 2994, 741, 10666, 579, 3149, 805, 12636, 9350, 8169, 12543, 4283, 10972, 16936, 2796, 11606, 11285, 9759, 3801, 17196, 3316, 11603, 17672, 3656, 4279, 12112, 9386, 14544, 576, 5199, 9193, 5032, 13544, 14489, 8406, 7007, 6580, 6097, 15332, 14735, 6831, 9504, 14966, 4021, 2818, 642, 2232, 9740, 6563, 14303, 10330, 11156, 18590, 6200, 7970, 10143, 8678, 9787, 16169, 15151, 3000, 9032, 7629, 8649, 7913, 10209, 5748, 9140, 9150, 16374, 8381, 5455, 10592, 17698, 5985, 614, 13114, 17655, 11915, 2260, 17254, 18109, 7032, 7408, 15666, 2130, 3031, 12976, 12223, 3922, 3695, 8038, 7485, 15172, 17258, 7286, 12963, 8103, 16562, 2785, 15771, 16401, 6915, 10534, 10061, 10399, 16605, 3397, 11507, 902, 7567, 5302, 6458, 7882, 2184, 964, 16917, 4739, 12090, 15530, 12282, 4869, 4466, 2629, 13800, 6007, 9266, 15547, 1351, 6663, 15545, 9268, 1633, 10420, 14557, 3259, 18150, 17168, 12306, 4234, 11178, 1677, 4714, 6506, 14997, 13833, 8529, 11824, 16458, 17489, 8608, 13275, 467, 14534, 14848, 4932, 7259, 1421, 2946, 15067, 13633, 8635, 15714, 12886, 8528, 13853, 14998, 5267, 1527, 16245, 12949, 17498, 7609, 14937, 14318, 10301, 10969, 858, 4141, 2018, 12081, 9821, 3476, 4907, 16583, 9280, 7890, 11212, 1987, 11184, 2903, 18326, 17829, 7960, 11347, 13091, 18497, 6006, 13874, 2630, 15039, 12563, 15490, 5952, 8302, 9191, 5201, 16972, 1344, 15510, 8222, 3134, 2998, 15153, 10720, 9883, 7864, 12923, 17949, 12099, 12969, 607, 2575, 18104, 15211, 5813, 2596, 267, 768, 8548, 15639, 6164, 12336, 15148, 4093, 18009, 11941, 6618, 8259, 8165, 16960, 8177, 11196, 927, 704, 16086, 5327, 7042, 17193, 17838, 2046, 8935, 16872, 5998, 16267, 17356, 14191, 2135, 1108, 8342, 11300, 7171, 7713, 11867, 5445, 1443, 1458, 6646, 9416, 6070, 16993, 6312, 4718, 14130, 5472, 12292, 5340, 16774, 10152, 165, 10369, 14469, 6111, 9227, 15786, 5513, 7995, 18495, 13093, 10289, 3833, 3155, 15395, 252, 14537, 18077, 3281, 9307, 14168, 17200, 1577, 8821, 1918, 2726, 5097, 2778, 16982, 1260, 2909, 15118, 4780, 2013, 5119, 14280, 9555, 9784, 16955, 4917, 7837, 1639, 4914, 10759, 5653, 4087, 9460, 11317, 11836, 2894, 6356, 824, 5440, 13458, 10984, 3660, 3746, 4752, 11337, 16276, 12071, 16665, 841, 12670, 16316, 8682, 2120, 9623, 12217, 10567, 11490, 7457, 5824, 5011, 17493, 14251, 11431, 14771, 12733, 17145, 15295, 7517, 8716, 15312, 9290, 11444, 8634, 13838, 15068, 1020, 3593, 16789, 5516, 14540, 10177, 15058, 1359, 7130, 15823, 15259, 10860, 442, 2568, 9856, 3807, 12832, 8674, 13607, 10544, 16650, 624, 3369, 10543, 13613, 8675, 15020, 14432, 3961, 15849, 9102, 12477, 10323, 1605, 894, 15205, 14287, 13176, 1042, 15401, 8151, 4352, 16822, 11162, 10198, 2611, 12770, 4948, 1103, 12358, 18097, 11960, 14082, 6877, 1854, 353, 14908, 6753, 11910, 14266, 8944, 10182, 14868, 15690, 271, 1580, 10793, 9401, 4628, 5052, 9074, 6520, 7693, 5875, 10547, 12774, 14716, 13219, 1078, 5573, 1520, 7060, 17481, 10285, 4046, 2001, 14488, 13966, 5033, 9522, 11669, 2212, 10366, 115, 14068, 17539, 6723, 3907, 1206, 15527, 6703, 12892, 12493, 12630, 11068, 14995, 6508, 14461, 9303, 7153, 3875, 1595, 3639, 18268, 2462, 5885, 17148, 1842, 16768, 15722, 6245, 6156, 597, 14920, 5955, 9937, 16084, 706, 7455, 11492, 14403, 9334, 15868, 4901, 15818, 14863, 13376, 6720, 17978, 1302, 3415, 9323, 7369, 10907, 14156, 6229, 15628, 303, 8961, 6486, 12383, 15580, 3865, 637, 16581, 4909, 4316, 4297, 3403, 17240, 7354, 2639, 157, 8884, 7011, 16850, 6189, 17880, 9129, 18373, 15468, 2489, 10983, 13667, 5441, 4253, 11727, 15711, 6576, 10093, 7752, 9771, 11052, 8994, 11250, 2410, 6768, 9543, 18067, 17782, 8989, 2602, 16044, 11133, 6689, 14445, 2167, 13344, 9991, 12143, 14395, 8581, 14879, 16978, 16327, 13237, 9177, 12527, 17936, 285, 12854, 12582, 14976, 917, 590, 1168, 3329, 3314, 17198, 14170, 18368, 9753, 1733, 8982, 6446, 6391, 6766, 2412, 17061, 9165, 15343, 248, 13272, 7927, 18018, 4626, 9403, 4803, 1624, 2578, 14924, 10573, 12157, 18569, 5425, 3796, 15328, 8077, 5849, 6490, 108, 15324, 16519, 4332, 6719, 13495, 14864, 2505, 8701, 12210, 5921, 7372, 11808, 709, 11462, 8163, 8261, 17787, 8791, 10687, 470, 10960, 2338, 2682, 17465, 17128, 12795, 5476, 12446, 7219, 14147, 10620, 14528, 7334, 16397, 12355, 9990, 13434, 2168, 14144, 15189, 16361, 8857, 11657, 6583, 11695, 12064, 1779, 5698, 2061, 8031, 6327, 3596, 4764, 17069, 18534, 6935, 12501, 9973, 3891, 10075, 14917, 2708, 2563, 829, 9220, 7901, 17689, 12651, 4123, 9887, 7795, 293, 10409, 2417, 2079, 15286, 1312, 6365, 1965, 3995, 5666, 7684, 1795, 696, 18408, 18394, 11027, 4708, 12138, 6866, 2886, 730, 16481, 7036, 17974, 8893, 8135, 4132, 9294, 3721, 1551, 7830, 10728, 9016, 466, 13847, 8609, 7926, 13399, 249, 12472, 2508, 4843, 11554, 12002, 16846, 151, 8375, 17112, 17440, 7952, 13098, 17810, 4300, 6302, 4873, 1822, 17299, 3666, 10465, 8125, 14778, 16782, 18441, 3794, 5427, 3452, 7548, 9030, 3002, 18403, 17910, 9176, 13426, 16328, 6881, 17425, 15268, 2619, 2934, 566, 8970, 6380, 14856, 14351, 16627, 4097, 3982, 1202, 6607, 1077, 13554, 14717, 17650, 3275, 9835, 8513, 6611, 7964, 602, 7816, 12165, 4361, 17883, 9508, 7826, 6324, 14376, 6232, 363, 3024, 15158, 10059, 10536, 32, 583, 1182, 12067, 12347, 10132, 2984, 11174, 3884, 12817, 8909, 2665, 18295, 10172, 1839, 17038, 11935, 16939, 8017, 1041, 13594, 14288, 5500, 8308, 14551, 25, 5208, 14800, 5350, 15144, 5533, 6669, 17714, 15126, 10540, 12345, 12069, 16278, 16812, 12801, 17770, 4927, 5138, 14343, 15502, 6727, 4861, 17153, 9079, 4319, 17635, 953, 11747, 13041, 6750, 10213, 4668, 8004, 12920, 9582, 12050, 12511, 10772, 16415, 5696, 1781, 5796, 15185, 433, 16448, 2065, 16272, 4464, 4871, 6304, 17371, 5799, 5241, 6150, 18465, 4505, 17654, 13922, 615, 17295, 18065, 9545, 10028, 3319, 17469, 4551, 6359, 16098, 10271, 11278, 16404, 17907, 17809, 13259, 7953, 4306, 5421, 10288, 13710, 18496, 13803, 11348, 2730, 15646, 3043, 17929, 18567, 12159, 2808, 4882, 10601, 1805, 4967, 4056, 520, 7761, 4010, 12878, 9902, 11210, 7892, 18456, 17645, 610, 3873, 7155, 15248, 18167, 3450, 5429, 11927, 7201, 8409, 15044, 18003, 17429, 11998, 16926, 3125, 16108, 2718, 3566, 10456, 14514, 2468, 16915, 966, 16728, 8157, 6749, 13143, 11748, 16077, 10104, 4538, 1309, 7871, 16932, 12763, 18477, 1124, 14046, 17585, 10313, 2389, 11645, 4388, 1413, 17516, 5043, 17076, 18117, 10900, 12722, 16527, 11, 6763, 3543, 16795, 9071, 6928, 3354, 2358, 12626, 10830, 10126, 15244, 2306, 14620, 12792, 9236, 463, 8917, 14896, 2240, 16744, 7403, 4460, 323, 11342, 11705, 17383, 2814, 14624, 15016, 11058, 1675, 11180, 8146, 3218, 54, 12053, 15988, 16154, 12222, 13911, 3032, 8348, 15488, 12565, 16038, 606, 13778, 12100, 7158, 11283, 11608, 8102, 13902, 7287, 7256, 2321, 14133, 18274, 410, 16645, 4383, 14582, 11257, 9225, 6113, 17497, 13828, 16246, 14531, 10690, 1910, 4256, 7835, 4919, 14509, 9212, 12324, 17118, 14410, 9843, 15499, 10260, 359, 3472, 3606, 14599, 5295, 10912, 2839, 9865, 7328, 17948, 13781, 7865, 9581, 13138, 8005, 12131, 3941, 4366, 16240, 15134, 2652, 12825, 15162, 17858, 2987, 861, 9698, 6300, 4302, 10500, 2582, 1435, 2101, 2179, 5463, 16815, 5262, 16535, 18333, 3077, 12492, 13530, 6704, 3466, 4492, 12556, 8527, 13835, 15715, 14273, 15423, 4008, 7763, 8471, 9901, 13074, 4011, 7340, 11900, 7747, 14, 1330, 2756, 8833, 17191, 7044, 1884, 3841, 11334, 17176, 2272, 8652, 14686, 17391, 11990, 1424, 7118, 7120, 12581, 13421, 286, 12419, 12310, 16053, 3684, 8385, 4663, 9456, 17779, 4182, 14029, 10264, 9409, 17686, 43, 16433, 12251, 6443, 17054, 16215, 8673, 13615, 3808, 3288, 1591, 16024, 8506, 15161, 12912, 2653, 4228, 18230, 15573, 513, 7142, 8908, 13187, 3885, 7980, 461, 9238, 7471, 6383, 12676, 14554, 11759, 16949, 15417, 2291, 16420, 15104, 17769, 13157, 16813, 5465, 3411, 1223, 5475, 13355, 17129, 9235, 13002, 14621, 2394, 1532, 9432, 3158, 16081, 1771, 7435, 3383, 4822, 16000, 17964, 3224, 2453, 9037, 11036, 14715, 13556, 10548, 11137, 4947, 13585, 2612, 3853, 6338, 10513, 6406, 18476, 13033, 16933, 7428, 10107, 15911, 1132, 4486, 14355, 2472, 14210, 4015, 8069, 1032, 7659, 17522, 15175, 10517, 5212, 12106, 12533, 2343, 11207, 16634, 1065, 6060, 16254, 14064, 3705, 9572, 17144, 13642, 14772, 10279, 7988, 6652, 11979, 657, 18312, 18198, 12617, 16526, 13018, 10901, 5037, 8049, 1947, 6553, 16345, 11573, 16643, 412, 10878, 16132, 5079, 1448, 3302, 11472, 8587, 4077, 2378, 9924, 1765, 14139, 10818, 17263, 15841, 4103, 1366, 14008, 3603, 4409, 546, 3850, 17180, 1081, 18509, 12176, 3082, 6077, 16181, 1536, 4275, 8296, 8216, 7083, 23, 14553, 12810, 6384, 5224, 11224, 7690, 16315, 13657, 842, 17248, 15457, 17261, 10820, 9448, 17920, 6743, 9719, 12412, 7811, 16486, 8394, 8665, 1798, 9526, 15962, 4122, 13313, 17690, 7188, 12462, 15899, 423, 3914, 3104, 4800, 10294, 3674, 5088, 8659, 16568, 9349, 13991, 806, 9806, 8669, 16832, 11067, 13528, 12494, 2703, 10829, 13008, 2359, 9665, 6864, 12140, 17794, 8868, 9548, 16525, 12724, 18199, 993, 9027, 14904, 15203, 896, 4671, 17982, 11596, 15858, 8928, 11733, 3642, 15925, 17027, 2151, 2405, 15750, 1722, 4850, 2329, 3339, 14079, 3499, 11974, 1370, 97, 4794, 4722, 9330, 1112, 8312, 17273, 14975, 13420, 12855, 7121, 10010, 888, 2368, 14834, 16478, 14094, 3895, 15454, 3088, 18023, 12169, 11229, 1272, 16037, 12972, 15489, 13797, 15040, 10803, 10869, 9869, 14032, 8526, 12888, 4493, 9553, 14282, 6411, 8456, 9116, 6131, 2698, 17072, 11016, 9631, 4282, 13988, 8170, 12125, 8370, 10036, 18419, 750, 17529, 5856, 2342, 12744, 12107, 6214, 14421, 11353, 17935, 13424, 9178, 4866, 1603, 10325, 3256, 17550, 8220, 15512, 5910, 2415, 10411, 11021, 7533, 9085, 10771, 13135, 12051, 56, 334, 169, 12434, 15229, 15428, 16909, 9972, 13324, 6936, 12014, 4634, 3264, 16231, 2702, 12629, 13529, 12893, 3078, 1192, 6756, 14943, 7862, 9885, 4125, 4879, 9369, 5644, 1099, 3927, 2625, 10322, 13600, 9103, 8746, 8699, 2507, 13270, 250, 15397, 11515, 6141, 9736, 6940, 9478, 6046, 15898, 12648, 7189, 16063, 7814, 604, 16040, 3221, 7079, 6127, 8860, 1003, 3969, 3581, 7650, 7918, 7218, 13353, 5477, 131, 4118, 2851, 10130, 12349, 5085, 17999, 2287, 17969, 15228, 12506, 170, 2955, 4828, 6260, 16507, 4111, 6266, 6895, 15351, 673, 11854, 10867, 10805, 12309, 12852, 287, 10497, 16388, 997, 1755, 7810, 12660, 9720, 15873, 10276, 16469, 1744, 5130, 716, 6468, 10227, 14219, 3985, 1691, 6973, 3719, 9296, 4, 4650, 10626, 16735, 17164, 15108, 16637, 17749, 2976, 16602, 16195, 11485, 15579, 13481, 6487, 6064, 4175, 8940, 18256, 6733, 14022, 8426, 16929, 10360, 7642, 4160, 3296, 10658, 876, 4438, 5109, 2968, 4218, 5393, 18233, 17717, 14159, 18096, 13582, 1104, 9989, 13346, 16398, 18451, 10346, 2872, 5084, 12440, 10131, 13192, 12068, 13161, 10541, 3371, 6731, 18258, 18484, 10919, 426, 15147, 13766, 6165, 2089, 16539, 8864, 10341, 14483, 6168, 11701, 6884, 17096, 17117, 12939, 9213, 17927, 3045, 6334, 1684, 8625, 9610, 1544, 17451, 15583, 9595, 11245, 16052, 12851, 12420, 10806, 4233, 13860, 17169, 11479, 7239, 1972, 18529, 9008, 15856, 11598, 11918, 8896, 5689, 14294, 5339, 13723, 5473, 1225, 16804, 7381, 16610, 11741, 18093, 1601, 4868, 13878, 15531, 12201, 15055, 1258, 16984, 18491, 1278, 11248, 8996, 10768, 5391, 4220, 10563, 5265, 15000, 1808, 2974, 17751, 1349, 15549, 6275, 16912, 4559, 14741, 5828, 8083, 4430, 2004, 15524, 6442, 12837, 16434, 10896, 9778, 9173, 10390, 2663, 8911, 17341, 10442, 14245, 15700, 4925, 17772, 14043, 5490, 2498, 15387, 4137, 793, 17282, 5292, 16631, 9905, 18045, 9061, 6476, 3921, 13910, 12977, 16155, 2145, 16532, 10566, 13652, 9624, 5367, 3740, 11123, 5784, 5920, 13372, 8702, 16093, 7759, 522, 12148, 5189, 11830, 15054, 12280, 15532, 7947, 126, 10479, 16150, 7666, 10875, 6981, 14014, 3291, 8081, 5830, 120, 2636, 10815, 4312, 6043, 10140, 11365, 1584, 15414, 10980, 1250, 3081, 12687, 18510, 18371, 9131, 1631, 9270, 11228, 12569, 18024, 12027, 4360, 13209, 7817, 14052, 14521, 14828, 2807, 13084, 18568, 13389, 10574, 17387, 3070, 6343, 5759, 1542, 9612, 5188, 12205, 523, 8072, 7670, 14394, 13432, 9992, 17793, 12622, 6865, 13292, 4709, 10714, 2586, 18027, 9627, 3940, 12918, 8006, 11384, 17878, 6191, 8369, 12541, 8171, 2926, 14776, 8127, 9533, 6370, 14675, 9830, 17776, 8923, 4084, 9385, 13973, 4280, 9633, 5113, 6213, 12532, 12745, 5213, 18488, 2304, 15246, 7157, 12968, 13779, 17950, 3790, 14116, 762, 124, 7949, 6701, 15529, 13880, 4740, 3599, 5070, 4135, 15389, 3037, 2157, 9820, 13818, 2019, 16348, 11663, 2854, 9520, 5035, 10903, 2282, 16664, 13660, 16277, 13160, 12346, 13193, 1183, 1778, 13335, 11696, 6693, 10850, 1899, 2812, 17385, 10576, 17556, 8662, 15987, 12980, 55, 12510, 13136, 9583, 9769, 7754, 2690, 1571, 4381, 16647, 5878, 2251, 17133, 1059, 17366, 1881, 259, 8114, 2447, 8854, 4645, 4293, 6819, 15034, 4359, 12167, 18025, 2588, 16763, 11107, 16690, 9958, 2883, 5142, 8503, 8742, 11587, 4633, 12499, 6937, 5258, 6901, 7589, 18546, 1980, 8613, 16514, 3311, 3113, 16845, 13266, 11555, 14841, 16925, 13055, 17430, 16117, 6873, 17870, 8437, 2944, 1423, 12859, 17392, 5374, 17519, 1889, 10081, 5382, 10632, 3935, 7477, 656, 12728, 6653, 4834, 10337, 1369, 12592, 3500, 7742, 307, 7633, 16259, 2591, 8850, 9996, 10993, 2309, 1846, 3497, 14081, 13580, 18098, 2744, 9495, 564, 2936, 11154, 10332, 810, 4524, 17136, 4864, 9180, 401, 17204, 3228, 10606, 5866, 6617, 13762, 18010, 17415, 11887, 2794, 16938, 13180, 17039, 17243, 4726, 3051, 11404, 2534, 7200, 13061, 5430, 882, 6811, 14260, 17209, 4395, 8133, 8895, 12297, 11599, 2259, 13920, 17656, 1014, 2074, 14265, 13573, 6754, 1194, 7461, 5158, 4151, 18380, 6898, 6533, 7746, 12875, 7341, 15348, 18383, 1153, 10645, 6503, 3067, 5064, 5704, 15130, 453, 2793, 11938, 17416, 7237, 11481, 1317, 242, 4535, 7431, 8399, 17207, 14262, 5218, 5101, 618, 1055, 5060, 14689, 15085, 3092, 5444, 13735, 7714, 15223, 6253, 338, 6218, 4574, 18282, 3888, 11790, 9964, 4027, 10866, 12423, 674, 5933, 8877, 3858, 11766, 1233, 10437, 5553, 5453, 8383, 3686, 5021, 6686, 17402, 6106, 3653, 2893, 13672, 11318, 10846, 18583, 5580, 15053, 12203, 5190, 16184, 5150, 9053, 16457, 13851, 8530, 8213, 10504, 2227, 15556, 16440, 7757, 16095, 3210, 448, 9340, 15603, 18054, 7453, 708, 13369, 7373, 14888, 9025, 995, 16390, 11649, 16793, 3545, 2294, 16512, 8615, 16808, 16543, 392, 10674, 7149, 9963, 11858, 3889, 9975, 11525, 17477, 17712, 6671, 4336, 7073, 8109, 3611, 16556, 9513, 14301, 6565, 3562, 2899, 7647, 8687, 8574, 3682, 16055, 17943, 1232, 11849, 3859, 4637, 9092, 11276, 10273, 16948, 12808, 14555, 10422, 15671, 15318, 8762, 17621, 8629, 14570, 6953, 16076, 13040, 13144, 954, 2789, 18575, 1035, 18092, 12286, 16611, 199, 7570, 142, 8251, 18266, 3641, 12605, 8929, 5972, 6456, 5304, 15710, 13455, 4254, 1912, 14326, 2477, 6600, 726, 1513, 4512, 5017, 16742, 2242, 2266, 5360, 1171, 6893, 6268, 1500, 18062, 6970, 981, 17382, 12991, 11343, 17423, 6883, 12328, 6169, 3245, 214, 6692, 12063, 13336, 6584, 11007, 2676, 537, 14821, 14765, 36, 8782, 17547, 14560, 16880, 16587, 7315, 2193, 4699, 8062, 9483, 11417, 1326, 7055, 15754, 8732, 8121, 10639, 2211, 13541, 9523, 5584, 15242, 10128, 2853, 12078, 16349, 60, 5270, 6095, 6582, 13338, 8858, 6129, 9118, 16668, 2832, 7992, 16792, 11802, 16391, 16121, 4387, 13026, 2390, 4024, 6845, 2520, 10752, 11237, 14336, 3780, 971, 14076, 1879, 17368, 1793, 7686, 4441, 316, 16771, 1298, 532, 6887, 17615, 16903, 6196, 14877, 8583, 17709, 17312, 10554, 18181, 7719, 6402, 4582, 8211, 8532, 8198, 8101, 12965, 11284, 13983, 2797, 17671, 13977, 3317, 10030, 2258, 11917, 12298, 15857, 12608, 17983, 14724, 16889, 864, 15862, 11392, 10188, 4632, 12016, 8743, 9710, 5128, 1746, 4400, 1088, 11503, 17449, 1546, 10886, 15232, 10120, 16642, 12715, 16346, 2021, 18549, 2960, 8149, 15403, 7480, 14859, 485, 4679, 11188, 18364, 2113, 5308, 622, 16652, 14840, 12001, 13267, 4844, 1403, 5727, 16712, 18338, 4231, 10808, 7807, 183, 510, 7184, 16113, 17268, 6920, 2842, 1474, 11014, 17074, 5045, 1115, 1286, 16701, 17799, 9158, 7654, 11271, 7394, 17476, 11787, 9976, 14258, 6813, 10487, 14386, 771, 629, 15373, 6140, 12469, 15398, 10378, 5916, 18573, 2791, 455, 901, 13890, 3398, 4166, 17448, 11580, 1089, 7207, 1052, 9705, 753, 4570, 18298, 16263, 15826, 14402, 13502, 7456, 13650, 10568, 14698, 3143, 15578, 12385, 16196, 9155, 1316, 11884, 7238, 12304, 17170, 5738, 11476, 5739, 6015, 8586, 12707, 3303, 7849, 9899, 8473, 1955, 17235, 4972, 2773, 8162, 13367, 710, 9089, 3631, 11421, 16674, 18159, 8356, 18081, 5776, 9688, 9999, 7598, 14178, 7216, 7920, 6803, 8633, 13635, 9291, 5073, 14721, 5529, 3348, 6494, 5628, 7313, 16589, 3073, 2761, 14770, 13644, 14252, 14359, 7419, 14713, 11038, 7294, 4858, 10883, 16673, 11458, 3632, 10737, 1325, 11677, 9484, 14331, 9124, 3020, 18084, 7052, 2483, 7565, 904, 5946, 6134, 2533, 11930, 3052, 16213, 17056, 16224, 9428, 3254, 10327, 16060, 6667, 5535, 10187, 11590, 15863, 2951, 17505, 7094, 17544, 16858, 17877, 12129, 8007, 1999, 4048, 4416, 7147, 10676, 6148, 5243, 4449, 3408, 18164, 10317, 17101, 14844, 369, 4033, 1717, 1583, 12182, 10141, 7972, 17851, 1731, 9755, 1178, 6710, 7115, 6292, 16624, 17934, 12529, 14422, 14592, 9259, 2729, 13090, 13804, 7961, 14662, 17422, 11704, 12992, 324, 11307, 5634, 16275, 13662, 4753, 17175, 12865, 3842, 3588, 15947, 3930, 11295, 17660, 7495, 9781, 7562, 16837, 18415, 17446, 4168, 8500, 10845, 11835, 13673, 9461, 2093, 3431, 739, 2996, 3136, 1336, 4692, 5633, 11340, 325, 16135, 9828, 14677, 7556, 7170, 13738, 8343, 80, 3953, 17659, 11329, 3931, 1175, 15541, 2384, 3379, 9846, 7852, 15538, 9758, 13982, 11607, 12966, 7159, 2007, 6913, 16403, 13102, 10272, 11762, 9093, 16722, 161, 7393, 11528, 7655, 17434, 8729, 5670, 648, 14951, 2672, 2347, 4066, 5247, 2199, 3494, 9224, 12953, 14583, 5719, 6696, 3248, 1290, 2409, 13447, 8995, 12274, 1279, 16051, 12312, 9596, 1554, 1354, 5124, 15957, 7782, 14335, 11639, 10753, 3187, 14307, 1221, 3413, 1304, 1271, 12568, 12170, 9271, 5106, 7689, 12673, 5225, 6788, 3708, 9474, 17757, 4072, 3769, 16898, 1790, 6307, 1986, 13811, 7891, 13072, 9903, 16633, 12742, 2344, 3627, 14576, 18433, 7323, 7068, 1120, 14893, 15796, 926, 13756, 8178, 7898, 1850, 5600, 14136, 561, 18363, 11562, 4680, 2930, 2902, 13809, 1988, 15200, 8145, 12984, 1676, 13858, 4235, 7167, 3883, 13189, 2985, 17860, 8119, 8734, 7621, 1661, 5834, 8489, 14059, 6715, 10197, 13588, 16823, 5811, 15213, 3099, 18589, 13947, 10331, 11954, 2937, 8523, 3848, 548, 9536, 14791, 760, 14118, 16073, 7845, 540, 6785, 17888, 5092, 7104, 4946, 12772, 10549, 17400, 6688, 13438, 16045, 9802, 7910, 2275, 7619, 8736, 9539, 9356, 5783, 12213, 3741, 832, 16472, 14659, 6614, 17940, 3191, 7029, 3737, 4246, 18179, 10556, 4689, 3424, 16689, 12023, 16764, 15220, 2466, 14516, 16219, 934, 7268, 8815, 9424, 10137, 9481, 8064, 14982, 2041, 17848, 4070, 17759, 7515, 15297, 7939, 15075, 1244, 8327, 17032, 1741, 835, 7506, 3299, 4956, 9880, 8239, 9593, 15585, 1776, 1185, 14390, 4585, 14994, 13527, 12631, 16833, 15880, 10700, 7573, 6081, 9511, 16558, 1674, 12986, 15017, 10146, 16658, 4595, 8993, 13449, 9772, 16679, 70, 15142, 5352, 9566, 3693, 3924, 4347, 1653, 2859, 3917, 7293, 11426, 14714, 12776, 9038, 8813, 7270, 1759, 16111, 7186, 17692, 4707, 13294, 18395, 6857, 18454, 7894, 7532, 12515, 10412, 9311, 9619, 9630, 12546, 17073, 11537, 1475, 4187, 7933, 77, 3624, 2675, 11693, 6585, 50, 2605, 2443, 10931, 4154, 10507, 15884, 8595, 7145, 4418, 14618, 2308, 11965, 9997, 9690, 380, 9641, 14871, 1096, 4769, 3659, 13666, 13459, 2490, 1249, 12179, 15415, 16951, 16319, 7467, 9860, 7426, 16935, 13986, 4284, 857, 13822, 10302, 9562, 4659, 9947, 8391, 18287, 6625, 2337, 13360, 471, 15358, 16342, 1464, 9362, 8234, 6223, 14436, 15974, 15663, 15695, 6822, 9909, 15013, 6146, 10678, 16159, 9436, 7066, 7325, 1162, 18, 17562, 5845, 1074, 16708, 18378, 4153, 11002, 2444, 6400, 7721, 17704, 10522, 6450, 4202, 10387, 17913, 3912, 425, 12339, 18485, 3273, 17652, 4507, 2865, 2838, 12928, 5296, 16801, 6964, 14155, 13488, 7370, 5923, 2281, 12074, 5036, 12721, 13019, 18118, 18321, 9777, 12249, 16435, 10005, 14055, 17288, 10018, 2914, 16164, 15426, 15231, 11577, 1547, 16672, 11423, 4859, 6729, 3373, 16131, 12712, 413, 6980, 12194, 7667, 892, 1607, 1159, 9868, 12560, 10804, 12422, 11855, 4028, 8980, 1735, 720, 441, 13620, 15260, 14400, 15828, 17741, 1726, 15094, 6623, 18289, 1898, 12061, 6694, 5721, 18582, 11834, 11319, 8501, 5144, 8825, 6548, 15906, 2154, 6778, 2501, 6388, 18074, 5519, 14586, 5714, 10125, 13007, 12627, 2704, 779, 2890, 17675, 14605, 4212, 9453, 9447, 12665, 17262, 12700, 14140, 4311, 12186, 2637, 7356, 4261, 3711, 1470, 7806, 11547, 4232, 12308, 12421, 10868, 12561, 15041, 8707, 5285, 18303, 7888, 9282, 8978, 4030, 9400, 13565, 1581, 1719, 17124, 7786, 7049, 18413, 16839, 6182, 5936, 2110, 2531, 6136, 17992, 5385, 6431, 4544, 4327, 9653, 341, 16414, 13134, 12512, 9086, 5390, 12272, 8997, 17043, 5316, 7868, 15289, 3778, 14338, 5652, 13677, 4915, 16957, 15356, 473, 3186, 11236, 11640, 2521, 7451, 18056, 3776, 15291, 7125, 8697, 8748, 7307, 3058, 16546, 7986, 10281, 1324, 11419, 3633, 1870, 3651, 6108, 8711, 4813, 5673, 9015, 13278, 7831, 3307, 17285, 5560, 1664, 8237, 9882, 13784, 15154, 4484, 1134, 3232, 2585, 12136, 4710, 16412, 343, 1574, 9393, 291, 7797, 9314, 4783, 7384, 5524, 140, 7572, 11064, 15881, 10416, 7401, 16746, 9374, 5280, 907, 18554, 1909, 12946, 14532, 469, 13362, 8792, 7465, 16321, 9945, 4661, 8387, 1709, 16158, 10944, 6147, 11378, 7148, 11793, 393, 1374, 2749, 9985, 5322, 5197, 578, 13995, 742, 16866, 14407, 7584, 18519, 8796, 875, 12369, 3297, 7508, 3521, 15791, 16173, 1408, 8044, 1197, 3062, 6396, 18470, 6502, 11895, 1154, 5335, 5498, 14290, 2210, 11671, 8122, 9065, 765, 4790, 7249, 3934, 11983, 5383, 17994, 17819, 2188, 16734, 12394, 4651, 8453, 7232, 745, 14527, 13350, 14148, 2106, 311, 14709, 5780, 18135, 10354, 9004, 8933, 2048, 7855, 8315, 5865, 11944, 3229, 15762, 6944, 1804, 13081, 4883, 101, 8286, 94, 17606, 8950, 1263, 17697, 13926, 5456, 5676, 6465, 7212, 16597, 8190, 17612, 1215, 15412, 1586, 8642, 2857, 1655, 5417, 17555, 12057, 17386, 12156, 13390, 14925, 18448, 15774, 14697, 11489, 13651, 12218, 16533, 5264, 12269, 4221, 9750, 18513, 14644, 14899, 4688, 11111, 18180, 11617, 17313, 17186, 7944, 17399, 11136, 12773, 13557, 5876, 16649, 13612, 13608, 3370, 12344, 13162, 15127, 14105, 31, 13197, 10060, 13895, 6916, 9113, 7500, 3614, 15431, 8440, 14579, 5843, 17564, 18071, 6449, 10926, 17705, 16229, 3266, 5211, 12747, 15176, 15303, 6405, 12766, 6339, 14166, 9309, 10414, 15883, 11000, 4155, 2226, 11821, 8214, 8298, 2581, 12904, 4303, 16387, 12417, 288, 10396, 6986, 5631, 4694, 2034, 17105, 3988, 14385, 11521, 6814, 14985, 2759, 3075, 18335, 6560, 16149, 12197, 127, 734, 7424, 9862, 6923, 7957, 9531, 8129, 5345, 3818, 6474, 9063, 8124, 13251, 3667, 14199, 6675, 9701, 5311, 14464, 9670, 14513, 13049, 3567, 419, 18240, 3689, 3394, 7414, 5612, 15378, 15634, 7027, 3193, 5004, 14244, 12242, 17342, 17406, 1866, 5552, 11847, 1234, 15235, 15821, 7132, 5229, 10335, 4836, 1636, 3241, 9244, 4606, 6053, 6471, 15670, 11757, 14556, 13865, 1634, 4838, 7400, 10698, 15882, 10509, 9310, 11020, 12516, 2416, 13308, 294, 1836, 1997, 8009, 984, 8486, 2686, 16193, 16604, 13893, 10062, 6985, 10495, 289, 9395, 14631, 1377, 2662, 12246, 9174, 17912, 10923, 4203, 14012, 6983, 10064, 6773, 8092, 10298, 5915, 11513, 15399, 1044, 6075, 3084, 4807, 15462, 17728, 14468, 13718, 166, 114, 13539, 2213, 9790, 699, 9232, 7641, 12373, 16930, 7873, 8714, 7519, 9003, 10613, 18136, 2972, 1810, 2642, 3007, 4355, 2871, 12352, 18452, 6859, 330, 14482, 12331, 8865, 14006, 1368, 11976, 4835, 10431, 5230, 809, 11953, 11155, 13948, 14304, 16059, 11397, 3255, 12523, 1604, 13599, 12478, 2626, 8902, 17511, 17100, 11372, 18165, 15250, 2388, 13028, 17586, 1276, 18493, 7997, 18502, 14100, 9044, 407, 10235, 9561, 10968, 13823, 14319, 5914, 10380, 8093, 16015, 3673, 12642, 4801, 9405, 3772, 3832, 13709, 13094, 5422, 4045, 13548, 17482, 6010, 1323, 10739, 7987, 12731, 14773, 16468, 12409, 15874, 16947, 11761, 11277, 13103, 16099, 17350, 7511, 1564, 16895, 9408, 12842, 14030, 9871, 358, 12934, 15500, 14345, 873, 8798, 15089, 17486, 4856, 7296, 18516, 14973, 17275, 15562, 5621, 3108, 678, 14125, 16893, 1566, 16446, 435, 7140, 515, 16140, 9560, 10304, 408, 18276, 2876, 16662, 2284, 1508, 14218, 12403, 6469, 6055, 8560, 14114, 3792, 18443, 5332, 1484, 8434, 15480, 1752, 2220, 4667, 13141, 6751, 14910, 5747, 13933, 7914, 16887, 14726, 8647, 7631, 309, 2108, 5938, 9931, 2610, 13587, 11163, 6716, 1389, 15369, 16144, 3836, 1364, 4105, 4631, 11589, 11393, 5536, 3552, 9890, 14867, 13570, 8945, 9682, 1256, 15057, 13626, 14541, 15617, 1995, 1838, 13183, 18296, 4572, 6220, 1667, 15472, 2099, 1437, 17961, 914, 17110, 8377, 3116, 724, 6602, 15652, 3163, 8067, 4017, 164, 13720, 16775, 14003, 17797, 16703, 16657, 11056, 15018, 8677, 13943, 7971, 11364, 12183, 6044, 9480, 11097, 9425, 3764, 3524, 2983, 13191, 12348, 12441, 2852, 11665, 15243, 13006, 10831, 5715, 8695, 7127, 16641, 11575, 15233, 1236, 9825, 15675, 2264, 2244, 18537, 18263, 4115, 17610, 8192, 15910, 12760, 7429, 4537, 13038, 16078, 209, 2315, 1785, 2054, 9733, 17594, 14426, 7275, 7751, 13452, 6577, 9854, 2570, 5768, 3435, 8538, 17639, 15808, 2826, 8759, 5381, 11985, 1890, 1940, 15116, 2911, 14916, 13321, 3892, 15657, 7443, 14748, 4562, 6038, 5708, 4761, 4743, 6772, 10383, 6984, 10398, 13894, 10535, 13198, 15159, 8508, 957, 18459, 9021, 1453, 17904, 1864, 17408, 4207, 17826, 4826, 2957, 2165, 14447, 3343, 16209, 15218, 16766, 1844, 2311, 18418, 12539, 8371, 4482, 15156, 3026, 2257, 11601, 3318, 13109, 9546, 8870, 3119, 17212, 18043, 9907, 6824, 14914, 2913, 10891, 17289, 17326, 4199, 5165, 3717, 6975, 887, 12579, 7122, 5889, 14519, 14054, 10894, 16436, 8777, 2561, 2710, 7597, 11451, 9689, 10992, 11966, 8851, 15444, 17792, 12142, 13433, 13345, 12356, 1105, 4747, 5321, 10670, 2750, 16614, 6588, 2082, 6798, 1788, 16900, 14257, 11524, 11788, 3890, 13323, 12502, 16910, 6277, 8986, 14074, 973, 6843, 4026, 11857, 11791, 7150, 4961, 4758, 2882, 12021, 16691, 481, 4370, 17008, 8014, 15739, 9077, 17155, 3868, 8390, 10965, 4660, 10683, 16322, 5733, 3910, 17915, 4472, 1769, 16083, 13506, 5956, 2028, 1038, 6540, 2609, 10200, 5939, 16798, 17901, 8788, 5962, 1764, 12703, 2379, 5762, 4981, 4989, 3576, 8451, 4653, 8809, 1642, 2278, 4940, 16476, 14836, 15012, 10947, 6823, 10022, 18044, 12228, 16632, 11209, 13073, 12879, 8472, 11469, 7850, 9848, 6121, 16089, 5222, 6386, 2503, 14866, 10184, 3553, 7794, 13311, 4124, 12486, 7863, 13783, 10721, 8238, 11077, 4957, 3284, 1140, 3215, 2963, 2694, 18174, 357, 10262, 14031, 12559, 10870, 1160, 7327, 12926, 2840, 6922, 10475, 7425, 10975, 7468, 9057, 3806, 13617, 2569, 10091, 6578, 7009, 8886, 9491, 6120, 9897, 7851, 11289, 3380, 15498, 12936, 14411, 4568, 755, 16551, 18422, 15768, 8512, 13215, 3276, 6841, 975, 17775, 12117, 14676, 11304, 16136, 15674, 10117, 1237, 4406, 3475, 13817, 12082, 2158, 8592, 16035, 1274, 17588, 18558, 6908, 1049, 1739, 17034, 17140, 693, 8668, 12634, 807, 5232, 7909, 11131, 16046, 75, 7935, 17721, 8339, 3507, 14184, 18051, 17806, 18406, 698, 10364, 2214, 16168, 13941, 8679, 16954, 13683, 9556, 7561, 11326, 7496, 9172, 12248, 10897, 18322, 17017, 4898, 16678, 11051, 13450, 7753, 12048, 9584, 9347, 16570, 14597, 3608, 15838, 5725, 1405, 3800, 13981, 11286, 15539, 1177, 11360, 1732, 13410, 18369, 18512, 10561, 4222, 9184, 911, 16003, 6628, 8600, 3152, 16147, 6562, 13951, 2233, 5256, 6939, 12467, 6142, 17593, 10098, 2055, 6263, 8255, 4590, 800, 5975, 9048, 8569, 15477, 17873, 18156, 15872, 12411, 12661, 6744, 14738, 14751, 15009, 3483, 3648, 18437, 5127, 11585, 8744, 9105, 17527, 752, 11499, 1053, 620, 5310, 10461, 6676, 6299, 12907, 862, 16891, 14127, 15968, 8275, 1085, 379, 10991, 9998, 11452, 5777, 5409, 15931, 6351, 1255, 10180, 8946, 9577, 18131, 5596, 3700, 2801, 14506, 9137, 818, 6480, 14512, 10458, 14465, 2736, 5989, 6863, 12624, 2360, 9590, 7984, 16548, 4848, 1724, 17743, 3130, 14419, 6216, 340, 10775, 4328, 5024, 8414, 8914, 9019, 18461, 988, 8000, 17333, 15688, 14870, 10989, 381, 246, 15345, 17307, 1896, 18291, 5112, 12110, 4281, 12545, 11017, 9620, 3939, 12133, 18028, 5366, 12216, 13653, 2121, 3938, 9629, 11018, 9312, 7799, 14566, 7731, 16861, 5187, 12150, 1543, 12317, 8626, 4522, 812, 5154, 15994, 9252, 13999, 7542, 5147, 7346, 6322, 7828, 1553, 11244, 12313, 15584, 11075, 8240, 7983, 9663, 2361, 65, 6295, 2740, 9346, 9768, 12049, 13137, 12921, 7866, 5318, 18130, 9680, 8947, 135, 8541, 17143, 12735, 3706, 6790, 17601, 5981, 3692, 11046, 5353, 15594, 4658, 10967, 10303, 10236, 16141, 5818, 7560, 9783, 13684, 14281, 12554, 4494, 8289, 18189, 16524, 12619, 8869, 10027, 13110, 18066, 13444, 6769, 2139, 9355, 11126, 8737, 14790, 11149, 549, 6369, 12120, 8128, 10472, 7958, 17831, 18473, 15961, 12654, 1799, 5583, 11668, 13542, 5034, 12076, 2855, 8644, 1441, 5447, 14277, 14300, 11778, 16557, 11061, 6082, 7825, 13206, 17884, 7135, 14965, 13957, 6832, 7320, 1874, 18089, 2031, 15812, 18361, 563, 11957, 2745, 4994, 6119, 9850, 8887, 1069, 489, 3386, 2171, 14330, 11416, 11678, 8063, 11096, 10138, 6045, 12465, 6941, 1928, 17756, 11220, 3709, 4263, 7181, 15576, 3145, 14232, 714, 5132, 223, 6422, 16965, 2092, 11316, 13674, 4088, 8921, 17778, 12846, 4664, 9446, 10822, 4213, 15263, 15485, 17919, 12664, 10821, 9454, 4665, 2222, 15591, 194, 2398, 7112, 17280, 795, 7065, 10942, 16160, 15393, 3157, 12788, 1533, 5193, 3253, 11399, 16225, 3763, 10136, 11098, 8816, 6348, 8206, 684, 5357, 5170, 6069, 13730, 6647, 18195, 14811, 14372, 8847, 17685, 12841, 10265, 16896, 3771, 10292, 4802, 13395, 4627, 13564, 10794, 4031, 371, 15137, 14630, 10394, 290, 10709, 1575, 17202, 403, 1017, 15615, 14543, 13972, 12113, 4085, 5655, 6272, 669, 2142, 1712, 14783, 14852, 17765, 5279, 10695, 16747, 15100, 7337, 5643, 12483, 4880, 2810, 1901, 17079, 17895, 8233, 10955, 1465, 5802, 5594, 18133, 5782, 11125, 9540, 2140, 671, 15353, 8168, 13990, 12637, 16569, 9767, 9585, 2741, 2600, 8991, 4597, 15602, 11813, 449, 16069, 4002, 7245, 15867, 13500, 14404, 3504, 1111, 12587, 4723, 3049, 4728, 16963, 6424, 7368, 13490, 3416, 14638, 14049, 14270, 16780, 14780, 2011, 4782, 10706, 7798, 9618, 11019, 10413, 10510, 14167, 13701, 3282, 4959, 7152, 13523, 14462, 5313, 14875, 6198, 18592, 3, 12397, 3720, 13282, 4133, 5072, 11443, 13636, 15313, 4894, 4428, 8085, 8182, 7576, 8977, 10797, 7889, 13813, 16584, 3815, 1815, 4325, 4546, 3957, 15179, 5105, 11227, 12171, 1632, 13867, 15546, 13872, 6008, 17484, 15091, 4191, 5095, 2728, 11350, 14593, 2526, 18146, 6782, 2993, 13998, 9604, 15995, 15854, 9010, 8828, 2026, 5958, 4605, 10427, 3242, 17924, 16455, 9055, 7470, 12813, 462, 13001, 12793, 17130, 7640, 10362, 700, 1516, 16694, 15785, 13715, 6112, 12952, 11258, 3495, 1848, 7900, 13316, 830, 3743, 3812, 16883, 16453, 17926, 12323, 12940, 14510, 6482, 4623, 4052, 2980, 17578, 18192, 1393, 17020, 7886, 18305, 8201, 3965, 3458, 18224, 14564, 7801, 5031, 13968, 5200, 13793, 8303, 14824, 1699, 8330, 5754, 910, 9748, 4223, 3784, 400, 11948, 4865, 12526, 13425, 13238, 17911, 10389, 12247, 9779, 7497, 8459, 14832, 2370, 7196, 15342, 13402, 17062, 5807, 15438, 3202, 2435, 7653, 11530, 17800, 1315, 11483, 16197, 18401, 3004, 16373, 13930, 9141, 7774, 5931, 676, 3110, 3332, 14382, 7773, 9149, 13931, 5749, 817, 9674, 14507, 4921, 7279, 16503, 1630, 12173, 18372, 13463, 17881, 4363, 15450, 3019, 11414, 14332, 14886, 7375, 839, 16667, 11654, 6130, 12550, 8457, 7499, 10532, 6917, 7179, 4265, 16424, 15209, 18106, 17526, 9708, 8745, 12476, 13601, 15850, 6638, 18032, 234, 2783, 16564, 506, 16721, 11275, 11763, 4638, 3630, 11460, 711, 5389, 10770, 12513, 7534, 2038, 6817, 4295, 4318, 13148, 17154, 9951, 15740, 6519, 13561, 5053, 6927, 13012, 16796, 5941, 2634, 122, 764, 10637, 8123, 10467, 6475, 12226, 18046, 7446, 3805, 9858, 7469, 9240, 16456, 11826, 5151, 529, 5485, 8568, 9726, 5976, 2071, 406, 10306, 14101, 6041, 4314, 4911, 8812, 11035, 12777, 2454, 8359, 8292, 7628, 13937, 3001, 13242, 7549, 14903, 12614, 994, 11805, 14889, 5860, 1452, 10054, 18460, 9648, 8915, 465, 13277, 10729, 5674, 5458, 6546, 8827, 9249, 15855, 12300, 18530, 16234, 8932, 10612, 10355, 7520, 3011, 6282, 7351, 17042, 10767, 12273, 11249, 13448, 11053, 4596, 9343, 2601, 13441, 17783, 14073, 9969, 6278, 17052, 6445, 13408, 1734, 10864, 4029, 10796, 9283, 7577, 8966, 14657, 16474, 4942, 6379, 13229, 567, 6462, 14656, 8975, 7578, 6050, 14314, 6485, 13483, 304, 16699, 1288, 3250, 18349, 18214, 7606, 3725, 2907, 1262, 10595, 17607, 134, 9576, 9681, 10181, 13571, 14267, 7820, 18255, 12379, 4176, 15465, 852, 16871, 13747, 2047, 10611, 9005, 16235, 5971, 11732, 12606, 15859, 4130, 8137, 4083, 12115, 17777, 9458, 4089, 15794, 14895, 12999, 464, 9018, 9649, 8415, 17340, 12244, 2664, 13186, 12818, 7143, 8597, 7604, 18216, 17510, 10320, 2627, 4468, 1704, 17733, 5688, 12296, 11919, 8134, 13285, 17975, 17542, 7096, 17843, 1068, 9490, 9851, 7010, 13468, 158, 14947, 15112, 3586, 3844, 3857, 11851, 5934, 6184, 2723, 439, 722, 3118, 10026, 9547, 12620, 17795, 14005, 10340, 12332, 16540, 8497, 1002, 12453, 6128, 11656, 13339, 16362, 4644, 12033, 2448, 15443, 9995, 11967, 2592, 17684, 9411, 14373, 8034, 83, 226, 5185, 16863, 7235, 17418, 3056, 7309, 4614, 14795, 17190, 12870, 2757, 14987, 3998, 2025, 9248, 9011, 6547, 10842, 5145, 7544, 1917, 13697, 1578, 273, 7698, 6347, 9423, 11099, 7269, 11034, 9039, 4912, 1641, 9916, 4654, 2427, 16381, 8231, 17897, 189, 789, 544, 4411, 15088, 10256, 874, 10660, 18520, 2549, 7464, 10686, 13363, 17788, 5961, 9927, 17902, 1455, 1561, 16856, 17546, 11687, 37, 1007, 17321, 2560, 10003, 16437, 6513, 4778, 15120, 14189, 17358, 8478, 2921, 2459, 7291, 3919, 6478, 820, 17620, 11754, 15319, 5380, 10083, 2827, 173, 2044, 17840, 14027, 4184, 5659, 3097, 15215, 7306, 10744, 8698, 12475, 9104, 9709, 11586, 12017, 8504, 16026, 4978, 14789, 9538, 11127, 7620, 11170, 8120, 11673, 15755, 5669, 11268, 17435, 7725, 6036, 4564, 8333, 18238, 421, 15901, 15632, 15380, 17455, 15311, 13638, 7518, 10357, 7874, 4812, 10732, 6109, 14471, 5284, 10801, 15042, 8411, 3729, 16092, 12209, 13373, 2506, 12474, 8747, 10745, 7126, 10123, 5716, 5522, 7386, 1963, 6367, 551, 8573, 11772, 7648, 3583, 3759, 2119, 13655, 16317, 16953, 9786, 13942, 10144, 15019, 13606, 13614, 12833, 16216, 5892, 16831, 12633, 9807, 694, 1797, 12656, 8395, 15986, 12055, 17557, 16567, 12639, 5089, 2512, 16826, 14123, 680, 14685, 12862, 2273, 7912, 13935, 7630, 10205, 14727, 1440, 9518, 2856, 10581, 1587, 14225, 18114, 1904, 6574, 15713, 13837, 13634, 11445, 6804, 6738, 14569, 11752, 17622, 4521, 9609, 12318, 1685, 6093, 5272, 14705, 6807, 7071, 4338, 1695, 16807, 11797, 16513, 12007, 1981, 15845, 7925, 13274, 13848, 17490, 6239, 5250, 5162, 6453, 803, 3151, 9744, 6629, 7603, 8906, 7144, 10998, 15885, 16034, 9818, 2159, 7701, 4541, 4076, 12706, 11473, 6016, 17708, 11620, 14878, 13430, 14396, 1269, 1306, 7704, 15682, 3681, 11771, 8688, 552, 1383, 15476, 9725, 9049, 5486, 15277, 6994, 16338, 15569, 3439, 14113, 10224, 6056, 177, 16284, 16751, 1829, 3377, 2386, 15252, 4148, 16430, 15638, 13769, 769, 14388, 1187, 16731, 691, 17142, 9574, 136, 17638, 10087, 3436, 5397, 8060, 4701, 8197, 11611, 8212, 11823, 13852, 13834, 12887, 12557, 14033, 3847, 11152, 2938, 14703, 5274, 3679, 15684, 3479, 16655, 16705, 6610, 13214, 9836, 15769, 2787, 956, 10057, 15160, 12827, 16025, 8741, 12018, 5143, 10844, 11320, 4169, 1001, 8862, 16541, 16810, 16280, 18386, 2517, 5557, 14058, 11166, 5835, 2685, 10403, 985, 14480, 332, 58, 16351, 16331, 2920, 8770, 17359, 3362, 7020, 1954, 11468, 9900, 12880, 7764, 5589, 3352, 6930, 15743, 6154, 6247, 5404, 15612, 15071, 14831, 9170, 7498, 9115, 12551, 6412, 7231, 10624, 4652, 9918, 3577, 7539, 1938, 1892, 798, 4592, 1820, 4875, 18431, 14578, 10528, 15432, 2943, 11993, 17871, 15479, 10218, 1485, 17681, 634, 17158, 16496, 3123, 16928, 12375, 14023, 299, 5412, 16757, 16600, 2978, 4054, 4969, 3538, 17339, 8913, 9650, 5025, 3728, 8705, 15043, 13059, 7202, 7006, 13964, 14490, 17231, 14759, 2451, 3226, 17206, 11879, 7432, 5008, 15985, 8664, 12657, 16487, 18286, 10964, 9948, 3869, 1708, 10681, 4662, 12848, 3685, 11844, 5454, 13928, 16375, 16843, 3115, 10161, 17111, 13263, 152, 14803, 4481, 10035, 12540, 12126, 6192, 4377, 17087, 16311, 1933, 15719, 319, 18187, 8291, 9035, 2455, 18080, 11455, 18160, 2149, 17029, 1702, 4470, 17917, 15487, 12974, 3033, 1320, 3622, 79, 11299, 13739, 1109, 3506, 9797, 17722, 4250, 3095, 5661, 18237, 8724, 4565, 5753, 9187, 1700, 17031, 11084, 1245, 2496, 5492, 7318, 6834, 1648, 2721, 6186, 2127, 3822, 5864, 10608, 7856, 17272, 12585, 1113, 5047, 14550, 13173, 5501, 4886, 14763, 14823, 9190, 13794, 5953, 14922, 2580, 10502, 8215, 12681, 4276, 4772, 7627, 9034, 8360, 18188, 9551, 4495, 93, 10598, 102, 17319, 1009, 5567, 16207, 3345, 430, 7223, 1495, 1084, 9693, 15969, 6117, 4996, 16991, 6072, 15340, 7198, 2536, 4291, 4647, 7440, 6642, 17786, 13365, 8164, 13760, 6619, 17227, 4589, 9730, 6264, 4113, 18265, 11736, 143, 6243, 15724, 14240, 15588, 15953, 16785, 15623, 459, 7982, 9592, 11076, 9881, 10722, 1665, 6222, 10954, 9363, 17896, 8805, 16382, 5056, 18481, 18429, 4877, 4127, 867, 3133, 13788, 15511, 12520, 17551, 3196, 7082, 12680, 8297, 10503, 11822, 8531, 11612, 4583, 14392, 7672, 683, 9421, 6349, 15933, 17218, 3964, 9200, 18306, 8100, 11610, 8533, 4702, 1991, 2402, 15909, 10109, 17611, 10586, 16598, 16759, 18301, 5287, 16179, 6079, 7575, 9285, 8086, 2713, 7897, 11195, 13757, 16961, 4730, 4039, 6838, 2925, 12124, 12542, 13989, 9351, 15354, 16959, 13759, 8260, 13366, 11463, 2774, 3360, 17361, 6748, 13043, 16729, 1189, 1253, 6353, 4351, 13591, 15402, 11568, 2961, 3217, 12983, 11181, 15201, 14906, 355, 18176, 15028, 5546, 4082, 8925, 4131, 13284, 8894, 11920, 4396, 14928, 5344, 10471, 9532, 12121, 14777, 13250, 10466, 9064, 10638, 11672, 8733, 11171, 17861, 18468, 6398, 2446, 12035, 260, 15520, 15836, 3610, 11781, 7074, 4210, 14607, 1490, 16561, 13901, 12964, 11609, 8199, 18307, 6178, 2208, 14292, 5691, 16014, 10297, 10381, 6774, 16369, 14440, 7595, 2712, 8181, 9286, 4429, 12256, 5829, 12190, 3292, 3419, 5848, 13384, 15329, 2366, 890, 7669, 12146, 524, 1031, 12752, 4016, 10155, 3164, 14981, 11095, 9482, 11679, 4700, 8535, 5398, 18564, 4490, 3468, 5433, 6251, 15225, 4987, 4983, 1946, 12719, 5038, 5822, 7459, 1196, 10651, 1409, 1282, 6978, 415, 7484, 13907, 3696, 3951, 82, 8845, 14374, 6326, 13331, 2062, 6377, 4944, 7106, 3898, 2821, 147, 3670, 5205, 6439, 1209, 6538, 1040, 13178, 16940, 15738, 9953, 17009, 3183, 17380, 983, 10405, 1998, 11383, 12130, 12919, 13139, 4669, 898, 17332, 9645, 989, 18501, 10309, 18494, 13712, 5514, 16791, 11651, 2833, 15366, 6651, 12730, 10280, 10740, 16547, 9662, 9591, 8241, 460, 12815, 3886, 18284, 16489, 4447, 5245, 4068, 17850, 11363, 10142, 13944, 6201, 1861, 16407, 776, 601, 13212, 6612, 14661, 11346, 13805, 17830, 9530, 10473, 6924, 16385, 4305, 13097, 13260, 17441, 6700, 12093, 125, 12199, 15533, 17398, 10551, 17187, 2422, 2804, 15074, 11087, 15298, 6226, 17720, 9799, 76, 11011, 4188, 1729, 17853, 4600, 18017, 13398, 13273, 8610, 15846, 17221, 18202, 6802, 11447, 7217, 12448, 7651, 2437, 16886, 10208, 13934, 8650, 2274, 11130, 9803, 5233, 18126, 4063, 5649, 16686, 41, 17688, 13315, 9221, 1849, 11194, 8179, 2714, 7531, 11023, 18455, 13071, 11211, 13812, 9281, 10798, 18304, 9202, 17021, 18252, 2183, 13885, 6459, 16010, 15363, 17461, 14111, 3441, 4811, 8713, 10358, 16931, 13035, 1310, 15288, 10764, 5317, 9580, 12922, 13782, 9884, 12487, 14944, 16725, 14962, 7176, 17271, 8314, 10609, 2049, 15537, 11288, 9847, 9898, 11470, 3304, 14819, 539, 11144, 16074, 6955, 7359, 15409, 18122, 3239, 1638, 13680, 4918, 12943, 4257, 14817, 3306, 10727, 13279, 1552, 9598, 6323, 13205, 9509, 6083, 5461, 2181, 18254, 8942, 14268, 14051, 12164, 13210, 603, 12459, 16064, 16485, 12659, 12413, 1756, 182, 11546, 10809, 1471, 16876, 17014, 5030, 9195, 14565, 9617, 9313, 10707, 292, 13310, 9888, 3554, 6034, 7727, 6174, 6287, 14363, 7048, 10789, 17125, 14884, 14334, 11239, 15958, 6409, 14284, 4455, 5895, 1333, 5930, 9148, 9142, 14383, 3990, 920, 15705, 17816, 15891, 5968, 5588, 8470, 12881, 4009, 13076, 521, 12207, 16094, 11817, 16441, 2689, 12047, 9770, 13451, 10094, 7276, 6761, 13, 12874, 11901, 6534, 16697, 306, 11972, 3501, 16869, 854, 2767, 4195, 3335, 4975, 18154, 17875, 16860, 9615, 14567, 6740, 6173, 7791, 6035, 8727, 17436, 16988, 17703, 10928, 6401, 11615, 18182, 5883, 2464, 15222, 11866, 13736, 7172, 1923, 17048, 7018, 3364, 3169, 2431, 15681, 8577, 1307, 4540, 8590, 2160, 6346, 8818, 274, 477, 5576, 5874, 13559, 6521, 16314, 12672, 11225, 5107, 4440, 11631, 1794, 13299, 5667, 15757, 15730, 14088, 943, 15322, 110, 6256, 18170, 14683, 682, 8208, 14393, 12145, 8073, 891, 10874, 12195, 16151, 7593, 14442, 217, 1887, 17521, 12750, 1033, 18577, 17433, 11270, 11529, 9159, 2436, 7917, 12449, 3582, 8686, 11773, 2900, 2932, 2621, 4159, 12372, 10361, 9233, 17131, 2253, 3237, 18124, 5235, 16258, 11970, 308, 10204, 8648, 13936, 9033, 8293, 4773, 17738, 14311, 4609, 1660, 11169, 8735, 11128, 2276, 1644, 3180, 6416, 17346, 16105, 5136, 4929, 14936, 13826, 17499, 3724, 8954, 18215, 8905, 8598, 6630, 16287, 3977, 14177, 11450, 10000, 2711, 8088, 14441, 7664, 16152, 15990, 18545, 12010, 6902, 15920, 14971, 18518, 10662, 14408, 17120, 7058, 1522, 6049, 8965, 8976, 9284, 8183, 6080, 11063, 10701, 141, 11738, 200, 5301, 13888, 903, 11409, 2484, 16836, 11325, 9782, 9557, 5819, 3881, 7169, 11302, 14678, 15736, 16942, 14248, 14671, 14902, 9029, 13243, 3453, 18525, 1916, 8823, 5146, 9602, 14000, 1937, 8449, 3578, 5609, 16921, 2037, 9084, 12514, 11022, 7895, 2715, 1762, 5964, 5068, 3601, 14010, 4205, 17410, 16819, 3010, 9002, 10356, 8715, 13639, 15296, 11089, 17760, 16854, 1563, 10268, 17351, 3520, 10656, 3298, 11080, 836, 14525, 747, 16554, 3613, 10531, 9114, 8458, 9171, 9780, 11327, 17661, 2376, 4079, 16129, 3375, 1831, 6572, 1906, 15171, 13906, 8039, 416, 14349, 14858, 11566, 15404, 655, 11981, 3936, 2123, 17763, 14854, 6382, 12812, 9239, 9056, 9859, 10976, 16320, 10685, 8793, 2550, 5157, 11907, 1195, 8046, 5823, 13649, 11491, 13503, 707, 11810, 18055, 10750, 2522, 4477, 17835, 3804, 9059, 18047, 14747, 10072, 15658, 6641, 8264, 4648, 6, 15496, 3382, 12784, 1772, 5007, 8398, 11880, 4536, 10106, 12761, 16934, 10974, 9861, 10476, 735, 15610, 5406, 14712, 11428, 14360, 4737, 16919, 5611, 10450, 3395, 16607, 4786, 15693, 15665, 13915, 7033, 232, 18034, 4459, 12995, 16745, 10697, 10417, 4839, 17669, 2799, 3702, 17475, 11527, 11272, 162, 4019, 14968, 16251, 5853, 1962, 8692, 5523, 10704, 4784, 16609, 12288, 16805, 1697, 14826, 14523, 838, 9121, 14887, 11807, 13370, 5922, 10906, 13489, 9324, 6425, 6027, 17324, 17291, 15182, 17374, 4288, 15408, 7842, 6956, 4260, 10813, 2638, 13471, 17241, 17041, 8999, 6283, 2544, 17316, 6321, 9600, 5148, 16186, 17305, 15347, 11899, 12876, 4012, 5642, 9371, 15101, 16396, 13348, 14529, 16248, 15923, 3644, 17947, 12925, 9866, 1161, 10940, 7067, 11202, 18434, 1873, 9502, 6833, 8323, 5493, 2192, 11682, 16588, 11436, 5629, 6988, 4613, 8837, 3057, 10743, 8749, 15216, 16211, 3054, 17420, 14664, 7266, 936, 14642, 18515, 10252, 4857, 11425, 11039, 3918, 8767, 2460, 18270, 7255, 12962, 13903, 17259, 15459, 15599, 17856, 15164, 16502, 9134, 4922, 6760, 7750, 10095, 14427, 1149, 180, 1758, 11033, 8814, 11100, 935, 7300, 14665, 2648, 15007, 14753, 5730, 1420, 13842, 4933, 2320, 12961, 7288, 18271, 5603, 6891, 1173, 3933, 10634, 4791, 5505, 15866, 9336, 4003, 4173, 6066, 661, 1971, 12303, 11480, 11885, 17417, 8840, 16864, 744, 10623, 8454, 6413, 17012, 16878, 14562, 18226, 3751, 1494, 8278, 431, 15187, 14146, 13352, 12447, 7919, 11448, 14179, 14547, 16596, 10588, 6466, 718, 1737, 1051, 11501, 1090, 15644, 2732, 7005, 8408, 13060, 11928, 2535, 8268, 15341, 9167, 2371, 1539, 2382, 15543, 6665, 16062, 12461, 12649, 17691, 11030, 16112, 11543, 511, 15575, 9471, 4264, 9111, 6918, 17270, 7858, 14963, 7137, 1922, 7712, 13737, 11301, 7557, 3882, 11176, 4236, 4343, 4951, 3825, 15834, 15522, 2006, 11282, 12967, 12101, 15247, 13066, 3874, 13522, 9304, 4960, 9962, 11792, 10675, 11379, 4417, 10997, 8596, 8907, 12819, 514, 10239, 436, 1921, 7174, 14964, 9506, 17885, 5228, 10433, 15822, 13623, 1360, 16640, 10122, 8696, 10746, 15292, 5888, 10009, 12580, 12856, 7119, 12857, 1425, 6291, 11357, 6711, 17279, 9440, 2399, 6210, 3017, 15452, 3897, 8027, 4945, 11139, 5093, 4193, 2769, 2332, 297, 14025, 17842, 8890, 17543, 11388, 17506, 7015, 1147, 14429, 15197, 4705, 17694, 18140, 15804, 22, 12679, 8217, 3197, 6126, 12455, 3222, 17966, 17824, 4209, 8108, 11782, 4337, 8619, 6808, 1119, 11201, 7324, 10941, 9437, 796, 1894, 17309, 17480, 13550, 1521, 7581, 17121, 15753, 11675, 1327, 2482, 11411, 18085, 18412, 10788, 7787, 14364, 257, 1883, 12868, 17192, 13751, 5328, 6594, 3755, 1943, 17973, 13287, 16482, 231, 7407, 13916, 18110, 3736, 11115, 3192, 10446, 15635, 46, 16574, 2249, 5880, 1953, 8475, 3363, 7709, 17049, 1146, 7092, 17507, 14195, 16849, 13467, 8885, 9852, 6579, 13963, 8407, 7203, 2733, 17731, 1706, 3871, 612, 5987, 2738, 6297, 6678, 16337, 8565, 15278, 4618, 924, 15798, 4612, 7311, 5630, 10494, 10397, 10063, 10384, 14013, 12193, 10876, 414, 8041, 1283, 886, 10012, 3718, 12399, 1692, 980, 11708, 18063, 17297, 1824, 18279, 14154, 10909, 16802, 1227, 16716, 4519, 17624, 14815, 4259, 7358, 7843, 16075, 11750, 14571, 16205, 5569, 14208, 2474, 2204, 6793, 1803, 10603, 15763, 1927, 9477, 12466, 9737, 5257, 12013, 12500, 13325, 18535, 2246, 6517, 15742, 8467, 3353, 13011, 9072, 5054, 16384, 7956, 10474, 9863, 2841, 11540, 17269, 7178, 9112, 10533, 13896, 16402, 11280, 2008, 1715, 4035, 1048, 9813, 18559, 3830, 3774, 18058, 15919, 7588, 12011, 5259, 6532, 11903, 18381, 15350, 12426, 6267, 11712, 1172, 7252, 5604, 1213, 17614, 11625, 533, 17095, 12327, 11702, 17424, 13235, 16329, 16353, 1853, 13578, 14083, 17082, 17869, 11995, 16118, 4269, 16683, 14341, 5140, 2885, 13291, 12139, 12623, 9666, 5990, 14954, 329, 10344, 18453, 11025, 18396, 1984, 6309, 503, 17560, 20, 15806, 17641, 5451, 5555, 2519, 11642, 4025, 9966, 974, 9833, 3277, 2924, 8173, 4040, 5787, 1647, 8322, 7319, 9503, 13958, 14736, 6746, 17363, 652, 2540, 14913, 10021, 9908, 10948, 15696, 15033, 12030, 4294, 9082, 2039, 14984, 10486, 11522, 14259, 11924, 883, 1118, 7070, 8620, 14706, 6737, 8632, 11446, 7921, 18203, 2052, 1787, 9980, 2083, 16301, 15050, 1802, 6946, 2205, 17600, 9570, 3707, 11222, 5226, 17887, 11142, 541, 2992, 9255, 18147, 15385, 2500, 10838, 2155, 3039, 16368, 8091, 10382, 10065, 4744, 2138, 9542, 13445, 2411, 13405, 6392, 3542, 13015, 12, 7749, 7277, 4923, 15702, 14942, 12489, 1193, 11909, 13574, 14909, 10212, 13142, 13042, 8158, 17362, 6829, 14737, 9718, 12662, 17921, 6172, 7729, 14568, 8631, 6805, 14707, 313, 14021, 12377, 18257, 12342, 3372, 10881, 4860, 13151, 15503, 3510, 3906, 13535, 17540, 17977, 13494, 13377, 4333, 1388, 10196, 11164, 14060, 18353, 17278, 7114, 11358, 1179, 6657, 15802, 18142, 3465, 12891, 13531, 15528, 12092, 7950, 17442, 212, 3247, 11254, 5720, 10849, 12062, 11697, 215, 14444, 13437, 11134, 17401, 11841, 5022, 4330, 16521, 17581, 939, 4675, 16336, 6996, 6298, 9700, 10462, 14200, 1386, 4335, 11784, 17713, 13165, 5534, 11395, 16061, 7191, 15544, 13869, 1352, 1556, 5415, 1657, 15801, 6708, 1180, 585, 4833, 11978, 12729, 7989, 15367, 1391, 18194, 9415, 13731, 1459, 14071, 17785, 8263, 7441, 15659, 18031, 9100, 15851, 497, 5015, 4514, 15098, 16749, 16286, 7602, 8599, 9745, 16004, 2336, 10962, 18288, 10853, 15095, 6003, 17226, 8258, 13761, 11942, 5867, 17939, 11118, 14660, 7963, 13213, 8514, 16706, 1076, 13221, 1203, 5736, 17172, 15651, 10158, 725, 11722, 2478, 1165, 5540, 1670, 3754, 7040, 5329, 1750, 15482, 15284, 2081, 9982, 16615, 49, 11006, 11694, 13337, 11658, 6096, 13962, 7008, 9853, 10092, 13453, 15712, 8637, 1905, 7488, 1832, 16007, 570, 6428, 14236, 3561, 11776, 14302, 13950, 9741, 16148, 10481, 18336, 16714, 1229, 17536, 1462, 16344, 12717, 1948, 14214, 17024, 15905, 10841, 8826, 9012, 5459, 6085, 18540, 5615, 2608, 9933, 1039, 8019, 1210, 15783, 16696, 7745, 11902, 6899, 5260, 16817, 17412, 5402, 6249, 5435, 2318, 4935, 1931, 16313, 7692, 13560, 9075, 15741, 6932, 2247, 16576, 4777, 8775, 16438, 15558, 3206, 14460, 13525, 14996, 13855, 4715, 3066, 11894, 10646, 18471, 17833, 4479, 14805, 645, 4816, 5627, 11438, 3349, 16291, 107, 13382, 5850, 6063, 12382, 13482, 8962, 14315, 4622, 9210, 14511, 9672, 819, 8765, 3920, 12225, 9062, 10468, 3819, 15669, 10424, 6054, 10226, 12404, 717, 7211, 10589, 5677, 14655, 8968, 568, 16009, 7881, 13886, 5303, 11730, 5973, 802, 8603, 5163, 4201, 10925, 10523, 18072, 6390, 13407, 8983, 17053, 12836, 12252, 15525, 1208, 8021, 5206, 27, 5511, 15788, 3767, 4074, 4543, 10778, 5386, 14235, 6568, 571, 6026, 7367, 9325, 16964, 9464, 224, 85, 5908, 15514, 17345, 7615, 3181, 17011, 7230, 8455, 12552, 14283, 7780, 15959, 18475, 12765, 10514, 15304, 4581, 11614, 7720, 10929, 2445, 8116, 18469, 10648, 3063, 6315, 3541, 6765, 13406, 6447, 18073, 10836, 2502, 9893, 5223, 12675, 12811, 7472, 14855, 13228, 8971, 4943, 8029, 2063, 16450, 2440, 5618, 4685, 14674, 12119, 9534, 550, 8690, 1964, 13303, 1313, 17802, 14458, 3208, 16097, 13105, 4552, 823, 13670, 2895, 4350, 8153, 1254, 9684, 15932, 8205, 9422, 8817, 7699, 2161, 5758, 12153, 3071, 16591, 14165, 10512, 12767, 3854, 14036, 1683, 12320, 3046, 17246, 844, 15621, 16787, 3595, 13330, 8032, 14375, 13204, 7827, 9599, 7347, 17317, 104, 1611, 17337, 3540, 6394, 3064, 4717, 13727, 16994, 502, 6854, 1985, 11214, 1791, 17370, 13122, 4872, 13256, 4301, 12906, 9699, 6677, 6997, 2739, 9587, 66, 16623, 11356, 7116, 1426, 4735, 14362, 7789, 6175, 5744, 2543, 7350, 9000, 3012, 1144, 17051, 8985, 9970, 16911, 12261, 15550, 668, 9382, 5656, 1478, 1499, 11711, 6894, 12427, 4112, 8254, 9731, 2056, 16506, 12430, 4829, 3448, 18169, 7676, 111, 337, 11864, 15224, 8054, 5434, 6527, 5403, 8464, 6155, 13511, 15723, 8249, 144, 2197, 5249, 8606, 17491, 5013, 499, 4436, 878, 362, 13202, 14377, 15627, 13486, 14157, 17719, 7937, 15299, 14435, 10953, 8235, 1666, 10169, 4573, 11862, 339, 9655, 14420, 12531, 12108, 5114, 3016, 7110, 2400, 1993, 15619, 846, 1958, 3487, 1431, 1860, 7969, 13945, 18591, 9299, 14876, 11622, 16904, 14610, 4376, 8368, 12127, 17879, 13465, 16851, 2126, 8319, 2722, 8875, 5935, 10785, 16840, 17598, 2207, 8098, 18308, 5743, 6286, 7790, 7728, 6741, 17922, 3244, 11700, 12329, 14484, 2088, 12335, 13767, 15640, 18425, 6089, 3367, 626, 16308, 596, 13510, 6246, 8465, 15744, 14477, 18464, 13118, 5242, 11377, 10677, 10945, 15014, 14626, 17592, 9735, 12468, 11516, 15374, 2555, 17991, 10781, 2532, 11406, 5947, 2697, 12549, 9117, 11655, 8859, 12454, 7080, 3198, 18345, 5325, 16088, 9896, 9849, 9492, 4995, 8273, 15970, 14668, 17496, 12951, 9226, 13716, 14470, 8710, 10733, 3652, 11839, 17403, 15517, 5702, 5066, 5966, 15893, 2364, 15331, 13961, 6581, 11659, 5271, 8623, 1686, 3167, 3366, 6161, 18426, 18261, 18539, 6544, 5460, 7824, 9510, 11062, 7574, 8184, 16180, 12685, 3083, 10375, 1045, 15339, 8270, 16992, 13729, 9417, 5171, 660, 7242, 4174, 12381, 6488, 5851, 16253, 12739, 1066, 17845, 176, 8559, 10225, 6470, 10425, 4607, 14313, 8964, 7579, 1523, 15897, 12464, 9479, 10139, 12184, 4313, 9042, 14102, 5707, 10069, 4563, 8726, 7726, 7792, 3555, 4798, 3106, 5623, 2558, 17323, 7366, 6426, 572, 15507, 3141, 14700, 4501, 2117, 3761, 16227, 17707, 8585, 11474, 5740, 5175, 3620, 1322, 10283, 17483, 9265, 13873, 13801, 18498, 17225, 6621, 15096, 4516, 15256, 16266, 13745, 16873, 2845, 16190, 16444, 1568, 2670, 14953, 6862, 9667, 2737, 6999, 613, 13924, 17699, 3392, 3691, 9568, 17602, 396, 5871, 2070, 9047, 9727, 801, 6455, 11731, 8930, 16236, 5587, 7766, 15892, 6101, 5067, 7528, 1763, 9926, 8789, 17789, 4604, 9246, 2027, 9936, 13507, 14921, 8301, 13795, 15491, 14681, 18172, 2696, 6133, 11407, 905, 5282, 14473, 2633, 9069, 16797, 9930, 10201, 2109, 10784, 6183, 8876, 11852, 675, 9147, 7775, 1334, 3138, 1347, 17753, 4938, 2280, 10905, 7371, 13371, 12211, 5785, 4042, 18572, 11512, 10379, 10299, 14320, 17059, 2414, 12518, 15513, 6419, 86, 17514, 1415, 14745, 18049, 14186, 14992, 4587, 17229, 14492, 2754, 1332, 7777, 4456, 16830, 8671, 16217, 14518, 10008, 7123, 15293, 17147, 13516, 2463, 7717, 18183, 1952, 7022, 2250, 12042, 16648, 10546, 13558, 7694, 5577, 2069, 5978, 397, 283, 17938, 6616, 11943, 10607, 8316, 3823, 4953, 1451, 9023, 14890, 4531, 2341, 12535, 17530, 1961, 7388, 16252, 6062, 6489, 13383, 8078, 3420, 1073, 10936, 17563, 10526, 14580, 4385, 16123, 4240, 14109, 17463, 2684, 8488, 11167, 1662, 5562, 119, 12189, 8082, 12257, 14742, 15983, 5010, 13648, 7458, 8047, 5039, 3880, 7559, 9558, 16142, 15371, 631, 2595, 13773, 15212, 11160, 16824, 2514, 15437, 9163, 17063, 16201, 3974, 5593, 9360, 1466, 5240, 13120, 17372, 15184, 13130, 1782, 5438, 826, 3491, 2175, 16304, 3178, 1646, 6836, 4041, 5919, 12212, 11124, 9357, 18134, 10615, 14710, 5408, 9687, 11453, 18082, 3022, 365, 14367, 15942, 5683, 3434, 10089, 2571, 17004, 15307, 14787, 4980, 9922, 2380, 1541, 12152, 6344, 2162, 18552, 909, 9186, 8331, 4566, 14413, 816, 9139, 13932, 10210, 14911, 2542, 6285, 6176, 18309, 5174, 6014, 11475, 11477, 17171, 6605, 1204, 3909, 9943, 16323, 1419, 7261, 14754, 16711, 11551, 1404, 9762, 15839, 17265, 18581, 10848, 6695, 11255, 14584, 5521, 8694, 10124, 10832, 14587, 3172, 4322, 2880, 4760, 10068, 6039, 14103, 15129, 11891, 5065, 6103, 15518, 262, 2060, 13333, 1780, 13132, 16416, 16494, 17160, 16013, 8095, 14293, 12295, 8897, 17734, 15608, 737, 3433, 5770, 15943, 3461, 2355, 14229, 14654, 6464, 10590, 5457, 9014, 10730, 4814, 647, 11267, 8730, 15756, 7683, 13300, 3996, 14989, 15123, 18236, 8335, 3096, 8752, 4185, 1477, 6271, 9383, 4086, 13676, 10760, 14339, 16685, 7905, 4064, 2349, 4767, 1098, 12482, 9370, 7338, 4013, 14212, 1950, 18185, 321, 4462, 16274, 11339, 11308, 4693, 10493, 6987, 7312, 11437, 6495, 4817, 17989, 2557, 6030, 3107, 10247, 15563, 4684, 6373, 2441, 2607, 6542, 18541, 15377, 10449, 7415, 16920, 7537, 3579, 3971, 15781, 1212, 6890, 7253, 18272, 14135, 11192, 1851, 16355, 3699, 9678, 18132, 9359, 5803, 3975, 16289, 3351, 8469, 7765, 5969, 16237, 15241, 11667, 9524, 1800, 15052, 11832, 18584, 2068, 5873, 7695, 478, 1519, 13552, 1079, 17182, 14207, 6950, 16206, 8282, 1010, 4549, 17471, 118, 5832, 1663, 10724, 17286, 14057, 8491, 2518, 6847, 5452, 11846, 10438, 1867, 17629, 1680, 16127, 4081, 8139, 15029, 15877, 2487, 15470, 1669, 6597, 1166, 592, 3551, 10186, 11394, 6668, 13166, 15145, 428, 3347, 11440, 14722, 17985, 950, 139, 10703, 7385, 8693, 5717, 14585, 10834, 18075, 14539, 13628, 16790, 7994, 13713, 15787, 6436, 28, 666, 15552, 2949, 15865, 7247, 4792, 99, 4885, 8307, 13174, 14289, 10642, 5336, 786, 688, 2191, 7317, 8324, 2497, 12236, 14044, 1126, 15276, 8567, 9050, 530, 1300, 17980, 4673, 941, 14090, 130, 12445, 13354, 12796, 1224, 12291, 13724, 14131, 2323, 16530, 2147, 18162, 3410, 12799, 16814, 12899, 2180, 7823, 6084, 6545, 9013, 5675, 10591, 13927, 8382, 11845, 5554, 6848, 17642, 960, 14276, 9516, 1442, 13734, 11868, 3093, 4252, 13457, 13668, 825, 5794, 1783, 2317, 6526, 6250, 8055, 3469, 881, 11926, 13062, 3451, 13245, 3795, 13387, 18570, 4044, 10287, 13095, 4307, 5001, 17554, 10578, 1656, 6660, 1557, 16756, 8423, 300, 15930, 9686, 5778, 14711, 7421, 15611, 8463, 6248, 6528, 17413, 18012, 18563, 8059, 8536, 3437, 15571, 18232, 12363, 4219, 12271, 10769, 9087, 712, 14234, 6430, 10779, 17993, 10631, 11984, 10082, 8760, 15320, 945, 3878, 5041, 17518, 11988, 17393, 14613, 14498, 1968, 4244, 3739, 12215, 9625, 18029, 15661, 15976, 3327, 1170, 11714, 2267, 5169, 9419, 685, 192, 15593, 9565, 11047, 15143, 13168, 14801, 154, 1813, 3817, 10470, 8130, 14929, 1296, 16773, 13722, 12293, 14295, 785, 5497, 10643, 1155, 1483, 10220, 18444, 1749, 6593, 7041, 13752, 16087, 6123, 18346, 5196, 10669, 9986, 4748, 18129, 9579, 7867, 10765, 17044, 14874, 9301, 14463, 10460, 9702, 621, 11559, 2114, 17865, 15709, 11729, 6457, 13887, 7568, 201, 187, 17899, 16800, 10911, 12929, 14600, 16630, 12230, 17283, 3309, 16516, 16178, 8186, 18302, 10800, 8708, 14472, 5944, 906, 10694, 9375, 17766, 16032, 15887, 3678, 8520, 14704, 8622, 6094, 11660, 61, 1526, 13831, 14999, 12268, 10564, 16534, 12897, 16816, 6531, 6900, 12012, 6938, 9738, 2234, 3406, 4451, 16427, 5161, 8605, 6240, 2198, 11261, 4067, 7975, 4448, 11376, 6149, 13119, 5800, 1467, 1130, 15913, 16257, 7635, 18125, 7908, 9804, 808, 10334, 10432, 7133, 17886, 6787, 11223, 12674, 6385, 9894, 16090, 3731, 5100, 11876, 14263, 2076, 3271, 18487, 12105, 12746, 10518, 3267, 14799, 13170, 26, 6438, 8022, 3671, 16017, 16971, 13792, 9192, 13969, 577, 10668, 5323, 18347, 3252, 9430, 1534, 16183, 11829, 12204, 12149, 9613, 16862, 8842, 227, 4425, 1397, 15281, 15266, 17427, 18005, 17678, 3619, 6013, 5741, 18310, 659, 6068, 9418, 5358, 2268, 1617, 3716, 10014, 4200, 6452, 8604, 5251, 16428, 4150, 11906, 7462, 2551, 15993, 9606, 813, 528, 9052, 11827, 16185, 7345, 9601, 7543, 8824, 10843, 8502, 12019, 2884, 6868, 14342, 13154, 4928, 7612, 16106, 3127, 222, 9466, 715, 12406, 1745, 11584, 9711, 18438, 15956, 11241, 1355, 15192, 14298, 14279, 13686, 2014, 17958, 14730, 3015, 6212, 12109, 9634, 18292, 2967, 12366, 4439, 7688, 11226, 9272, 15180, 17293, 617, 11875, 5219, 3732, 2777, 13694, 2727, 9261, 4192, 7103, 11140, 17889, 2511, 8658, 12640, 3675, 17998, 12439, 12350, 2873, 1827, 16753, 1447, 12710, 16133, 327, 14956, 17000, 14720, 11442, 9292, 4134, 12087, 3600, 7527, 5965, 6102, 5703, 11892, 3068, 17389, 14688, 11872, 1056, 4527, 18480, 8229, 16383, 6926, 9073, 13562, 4629, 4107, 16594, 14549, 8310, 1114, 11535, 17075, 13022, 17517, 5376, 3879, 5821, 8048, 12720, 10902, 12075, 9521, 13543, 13967, 9194, 7802, 17015, 18324, 2905, 3727, 8413, 9651, 4329, 6685, 11842, 3687, 18242, 16741, 11718, 4513, 6635, 498, 6237, 17492, 13647, 5825, 15984, 8397, 7433, 1773, 14243, 10444, 3194, 17553, 5419, 4308, 3390, 17701, 16990, 8272, 6118, 9493, 2746, 14634, 4163, 3575, 9920, 4982, 8052, 15226, 17971, 1945, 8051, 4988, 9921, 5763, 14788, 8739, 16027, 18153, 7735, 3336, 2772, 11465, 17236, 3537, 8418, 4055, 13079, 1806, 15002, 17575, 3527, 4757, 9961, 7151, 9305, 3283, 9879, 11078, 3300, 1450, 5862, 3824, 7164, 4344, 1102, 13584, 12771, 11138, 7105, 8028, 6378, 8972, 16475, 9913, 2279, 5925, 17754, 1930, 6524, 2319, 7258, 13843, 14849, 14935, 7611, 5137, 13155, 17771, 12239, 15701, 6759, 7278, 9135, 14508, 12942, 7836, 13681, 16956, 10758, 13678, 1640, 8811, 9040, 4315, 13476, 16582, 13815, 3477, 15686, 17335, 1613, 15817, 13498, 15869, 16677, 9774, 17018, 1395, 4427, 9288, 15314, 518, 4058, 18343, 3200, 15440, 14762, 8306, 5502, 100, 10600, 13082, 2809, 9368, 12484, 4126, 8226, 18430, 8443, 1821, 13255, 6303, 13123, 4465, 13877, 12283, 1602, 12525, 9179, 11949, 17137, 17152, 13150, 6728, 10882, 11424, 7295, 10253, 17487, 16460, 4404, 1239, 2328, 12597, 1723, 9660, 16549, 757, 1402, 11553, 13268, 2509, 17891, 17668, 7399, 10418, 1635, 10430, 10336, 11977, 6654, 586, 14502, 3447, 6259, 12431, 2956, 10047, 17827, 18328, 15999, 12782, 3384, 491, 16020, 17988, 5626, 6496, 646, 5672, 10731, 8712, 7875, 3442, 15597, 15461, 10373, 3085, 17251, 1623, 13394, 9404, 10293, 12643, 3105, 6032, 3556, 15965, 4721, 12589, 98, 5504, 7248, 10635, 766, 269, 15692, 7411, 16608, 7383, 10705, 9315, 2012, 13688, 15119, 8774, 6514, 16577, 14454, 17737, 7626, 8294, 4277, 3658, 10986, 1097, 5646, 2350, 17068, 13328, 3597, 4742, 10067, 5709, 2881, 9960, 4962, 3528, 15649, 17174, 11336, 13663, 3747, 4061, 18128, 5320, 9987, 1106, 2137, 6771, 10066, 4762, 3598, 12089, 13881, 16918, 7417, 14361, 6289, 1427, 445, 15336, 4038, 8175, 16962, 9327, 3050, 11932, 17244, 3048, 9329, 12588, 4795, 15966, 14129, 13726, 6313, 3065, 6505, 13856, 1678, 17631, 16411, 10713, 12137, 13293, 11028, 17693, 7088, 15198, 1990, 8196, 8534, 8061, 11680, 2194, 2824, 15810, 2033, 10492, 5632, 11309, 1337, 3423, 11110, 10557, 14900, 14673, 6372, 5619, 15564, 16465, 2929, 11187, 11563, 486, 1341, 16335, 6680, 940, 5481, 17981, 12610, 897, 8003, 13140, 10214, 2221, 9445, 9455, 12847, 8386, 10682, 9946, 10966, 9563, 15595, 3444, 2426, 8808, 9917, 8452, 10625, 12395, 5, 7439, 8265, 4292, 12032, 8855, 16363, 17953, 15777, 14574, 3629, 9091, 11764, 3860, 3263, 12498, 12015, 11588, 10189, 4106, 5051, 13563, 9402, 13396, 18019, 4051, 9209, 6483, 14316, 14939, 923, 6992, 15279, 1399, 14794, 8836, 7310, 6989, 15799, 1659, 7623, 14312, 6052, 10426, 9245, 5959, 17790, 15446, 18016, 7929, 17854, 15601, 9342, 8992, 11054, 16659, 1819, 8445, 799, 9729, 8256, 17228, 5900, 14993, 11070, 14391, 8210, 11613, 6403, 15305, 17006, 4372, 18208, 14152, 18281, 11861, 6219, 10170, 18297, 11497, 754, 9841, 14412, 5752, 8332, 8725, 6037, 10070, 14749, 14740, 12259, 16913, 2470, 14357, 14254, 17618, 822, 6358, 13106, 17470, 5565, 1011, 3956, 9275, 4326, 10777, 6432, 4075, 8589, 7702, 1308, 13037, 10105, 7430, 11881, 243, 2680, 2340, 5858, 14891, 1122, 18479, 5058, 1057, 17135, 11951, 811, 9608, 8627, 17623, 6960, 16717, 15255, 6001, 15097, 6634, 5016, 11719, 1514, 702, 929, 2864, 10915, 17653, 13116, 18466, 17863, 2116, 6021, 14701, 2940, 3904, 3512, 92, 8288, 9552, 12555, 12889, 3467, 8057, 18565, 17931, 14354, 12757, 1133, 10718, 15155, 10034, 8372, 14804, 6499, 17834, 7449, 2523, 16620, 558, 1768, 9940, 17916, 8351, 1703, 8900, 2628, 13876, 4870, 13124, 16273, 5636, 322, 12994, 7404, 18035, 16829, 5894, 7778, 14285, 15207, 16426, 5253, 3407, 11375, 5244, 7976, 16490, 17092, 386, 14019, 315, 11630, 7687, 5108, 12367, 877, 6235, 500, 16996, 2086, 14486, 2003, 12255, 8084, 9287, 4895, 1396, 5183, 228, 16067, 451, 15132, 16242, 14617, 10996, 7146, 11380, 4049, 18021, 3090, 15087, 8800, 545, 12693, 3604, 3474, 9823, 1238, 4853, 16461, 377, 1087, 11582, 1747, 18446, 14927, 8132, 11921, 17210, 3121, 16498, 73, 16048, 1412, 13025, 11646, 16122, 5841, 14581, 12955, 16646, 12044, 1572, 345, 17086, 8367, 6193, 14611, 17395, 18207, 4578, 17007, 9955, 482, 15239, 16239, 12916, 3942, 15449, 9127, 17882, 13208, 12166, 12028, 15035, 15747, 2870, 10348, 3008, 16821, 13590, 8152, 6354, 2896, 1652, 11043, 3925, 1101, 4950, 7165, 4237, 14040, 978, 1694, 8618, 7072, 11783, 6672, 1387, 6718, 13378, 16520, 6684, 5023, 9652, 10776, 4545, 9276, 1816, 2879, 5711, 3173, 17634, 13147, 9080, 4296, 13475, 4910, 9041, 6042, 12185, 10816, 14141, 3389, 5000, 5420, 13096, 7954, 16386, 10499, 12905, 6301, 13257, 17811, 3402, 13474, 4317, 9081, 6818, 12031, 4646, 8266, 2537, 15407, 7361, 17375, 2765, 856, 10971, 13987, 12544, 9632, 12111, 13974, 3657, 4771, 8295, 12682, 1537, 2373, 1381, 554, 16682, 6871, 16119, 16393, 16423, 9110, 7180, 9472, 3710, 10812, 7357, 6957, 14816, 7834, 12944, 1911, 11726, 13456, 5442, 3094, 8337, 17723, 15026, 18178, 11113, 3738, 5369, 1969, 663, 14108, 5839, 16124, 14039, 4342, 7166, 11177, 13859, 12307, 10807, 11548, 18339, 18229, 12823, 2654, 1242, 15077, 3783, 9183, 9749, 10562, 12270, 5392, 12364, 2969, 1267, 14398, 15262, 9452, 10823, 14606, 8107, 7075, 17825, 10049, 17409, 7524, 14011, 10386, 10924, 6451, 5164, 10015, 17327, 14380, 3334, 7737, 2768, 7102, 5094, 9262, 15092, 1728, 7932, 11012, 1476, 5658, 8753, 14028, 12844, 17780, 18069, 17566, 17726, 15464, 8939, 12380, 6065, 7243, 4004, 2217, 1000, 8499, 11321, 17447, 11505, 3399, 3574, 4991, 14635, 3295, 12371, 7643, 2622, 15950, 2225, 10506, 11001, 10932, 18379, 11905, 5159, 16429, 8551, 15253, 16719, 508, 185, 203, 2017, 13820, 859, 2989, 792, 12233, 15388, 12086, 5071, 9293, 13283, 8136, 8926, 15860, 866, 8225, 4878, 12485, 9886, 13312, 12652, 15963, 3558, 2850, 12443, 132, 17609, 10111, 18264, 8253, 6265, 12428, 16508, 14163, 16593, 5050, 4630, 10190, 1365, 12697, 15842, 18399, 16199, 17065, 3981, 13224, 16628, 14602, 18008, 13764, 15149, 16171, 15793, 8920, 9459, 13675, 5654, 9384, 12114, 8924, 8138, 5547, 16128, 7492, 2377, 12705, 8588, 4542, 6433, 3768, 11218, 17758, 11091, 17849, 7974, 5246, 11262, 2348, 5648, 7906, 18127, 4750, 3748, 18342, 4891, 519, 13078, 4968, 8419, 2979, 9208, 4624, 18020, 4415, 11381, 2000, 13547, 10286, 5423, 18571, 5918, 5786, 6837, 8174, 4731, 15337, 1047, 6910, 1716, 11368, 370, 9399, 10795, 8979, 10865, 11856, 9965, 6844, 11643, 2391, 2817, 13955, 14967, 7391, 163, 10154, 8068, 12753, 14211, 5641, 7339, 12877, 13075, 7762, 12882, 15424, 16166, 2216, 4172, 7244, 9337, 16070, 1977, 2024, 8830, 14988, 5665, 13301, 1966, 14500, 588, 919, 7771, 14384, 10489, 17106, 1690, 12401, 14220, 1201, 13223, 4098, 17066, 2352, 14176, 7600, 16288, 5592, 5804, 16202, 15780, 5607, 3580, 12451, 1004, 3428, 3457, 9199, 8202, 17219, 15848, 13603, 14433, 15301, 15178, 9274, 4547, 1012, 17658, 11297, 81, 8036, 3697, 16357, 15061, 18316, 3828, 18561, 18014, 15448, 4365, 12917, 12132, 9628, 9621, 2122, 7476, 11982, 10633, 7250, 1174, 11294, 11330, 15948, 2624, 12480, 1100, 4346, 11044, 3694, 13909, 12224, 6477, 8766, 7292, 11040, 2860, 3103, 12645, 424, 10921, 17914, 9942, 5734, 1205, 13534, 6724, 3511, 4498, 2941, 15434, 18389, 640, 2820, 8026, 7107, 15453, 12573, 14095, 15656, 10074, 13322, 9974, 11789, 11859, 18283, 7979, 12816, 13188, 11175, 7168, 7558, 5820, 5040, 5377, 946, 1594, 13521, 7154, 13067, 611, 7001, 1707, 8389, 9949, 17156, 636, 13479, 15581, 17453, 15382, 3262, 4636, 11765, 11850, 8878, 3845, 14035, 6337, 12768, 2613, 17179, 12691, 547, 11151, 8524, 14034, 3856, 8879, 3587, 11333, 12866, 1885, 219, 17746, 1363, 10192, 16145, 3154, 13708, 10290, 3773, 6906, 18560, 3946, 18317, 15833, 7163, 4952, 5863, 8317, 2128, 15668, 6473, 10469, 5346, 1814, 9278, 16585, 16882, 9217, 3744, 3662, 3287, 12831, 13616, 9857, 9058, 7447, 17836, 17195, 13980, 9760, 1406, 16175, 15327, 13386, 5426, 13246, 18442, 10222, 14115, 12097, 17951, 16365, 3532, 281, 399, 9182, 4224, 15078, 970, 11637, 14337, 10762, 15290, 10748, 18057, 6905, 3831, 10291, 9406, 16897, 11217, 4073, 6434, 15789, 3523, 10135, 9426, 16226, 6019, 2118, 8684, 3584, 15114, 1942, 7039, 6595, 1671, 1493, 7225, 18227, 18341, 4060, 4751, 13664, 3661, 3811, 9218, 831, 11122, 12214, 5368, 4245, 11114, 7030, 18111, 3358, 2776, 5099, 5220, 16091, 8704, 8412, 5026, 2906, 8953, 7607, 17500, 1550, 13281, 9295, 12398, 6974, 10013, 5166, 1618, 15274, 1128, 1469, 10811, 4262, 9473, 11221, 6789, 9571, 12736, 14065, 17474, 7396, 2800, 9677, 5597, 16356, 3950, 8037, 13908, 3923, 11045, 9567, 5982, 3393, 10452, 18241, 5020, 11843, 8384, 12849, 16054, 11770, 8575, 15683, 8519, 5275, 15888, 17997, 5087, 12641, 10295, 16016, 5204, 8023, 148, 14198, 10464, 13252, 17300, 1138, 3286, 3810, 3745, 13665, 10985, 4770, 4278, 13975, 17673, 2892, 11838, 6107, 10734, 1871, 18436, 9713, 3484, 17533, 17946, 7330, 15924, 12604, 11734, 18267, 13519, 1596, 2297, 3515, 17627, 1869, 10736, 11420, 11459, 9090, 4639, 14575, 11205, 2345, 2674, 11009, 78, 8345, 1321, 6012, 5176, 17679, 1487, 16907, 15430, 10530, 7501, 16555, 11780, 8110, 15837, 9764, 14598, 12931, 3473, 4408, 12694, 14009, 7526, 5069, 12088, 4741, 4763, 13329, 6328, 16788, 13630, 1021, 348, 18221, 15946, 11332, 3843, 8880, 15113, 3758, 8685, 7649, 12450, 3970, 5608, 7538, 8450, 9919, 4990, 4164, 3400, 17813, 1027, 871, 14347, 418, 10455, 13050, 2719, 1650, 2898, 11775, 6566, 14237, 2849, 4120, 15964, 4797, 6033, 7793, 9889, 10185, 5537, 593, 17090, 16492, 16418, 2293, 11800, 16794, 13014, 6764, 6393, 6316, 17338, 8417, 4970, 17237, 2237, 14647, 280, 3787, 16366, 3041, 15648, 4756, 4963, 17576, 2982, 10134, 3765, 15790, 10655, 7509, 17352, 14370, 14813, 17626, 3636, 2298, 91, 4497, 3905, 6725, 15504, 14183, 9796, 8340, 1110, 9332, 14405, 16868, 7741, 11973, 12593, 14080, 11962, 1847, 9223, 11259, 2200, 2174, 5792, 827, 2565, 1430, 6204, 1959, 17532, 3647, 9714, 15010, 14838, 16654, 8517, 15685, 4906, 13816, 9822, 4407, 3605, 12932, 360, 880, 5432, 8056, 4491, 12890, 6705, 18143, 14174, 2354, 5681, 15944, 18223, 9198, 3966, 3429, 2095, 18524, 7547, 13244, 5428, 13063, 18168, 6258, 4830, 14503, 2425, 4656, 15596, 4810, 7876, 14112, 8562, 15570, 5396, 8537, 10088, 5769, 5684, 738, 11314, 2094, 3456, 3967, 1005, 39, 16688, 11109, 4690, 1338, 1072, 5847, 8079, 3293, 14637, 9322, 13491, 1303, 11232, 1222, 12798, 5466, 18163, 11374, 4450, 5254, 2235, 17239, 13473, 4298, 17812, 3573, 4165, 11506, 13891, 16606, 7413, 10451, 3690, 5983, 17700, 4999, 4309, 14142, 2170, 9487, 490, 4821, 12783, 7436, 15497, 9845, 11290, 2385, 8554, 1830, 7490, 16130, 10880, 6730, 12343, 10542, 13609, 625, 6160, 6090, 3168, 7708, 7019, 8476, 17360, 8160, 2775, 3734, 18112, 14227, 2357, 13010, 6929, 8468, 5590, 16290, 6493, 11439, 5530, 429, 8280, 16208, 10043, 14448, 1877, 14078, 12595, 2330, 2771, 4974, 7736, 4196, 14381, 9144, 3111, 3313, 13415, 1169, 5362, 15977, 2781, 236, 2917, 16976, 14881, 17468, 13108, 10029, 11602, 13978, 17197, 13414, 3330, 3112, 12005, 16515, 5290, 17284, 10726, 7832, 14818, 7848, 11471, 12708, 1449, 4955, 11079, 7507, 10657, 12370, 4161, 14636, 3418, 8080, 12191, 14015, 1590, 12830, 3809, 3663, 1139, 9878, 4958, 9306, 13702, 18078, 2457, 2923, 6840, 9834, 13216, 17651, 10917, 18486, 5215, 2077, 2419, 14798, 5210, 10519, 16230, 12497, 4635, 3861, 15383, 18149, 13863, 14558, 17549, 12522, 10326, 11398, 9429, 5194, 18348, 8957, 1289, 11253, 6697, 213, 11699, 6170, 17923, 9243, 10428, 1637, 7839, 18123, 7637, 2254, 1858, 1433, 2584, 10716, 1135, 15761, 10605, 11945, 17205, 8401, 2452, 12779, 17965, 7078, 12456, 16041, 53, 12982, 8147, 2962, 9876, 1141, 14733, 15334, 447, 11815, 16096, 6361, 14459, 6510, 15559, 18356, 2434, 9161, 15439, 4889, 18344, 6125, 7081, 8218, 17552, 5003, 10445, 7028, 11116, 17941, 16057, 14306, 11235, 10754, 474, 17379, 8012, 17010, 6415, 7616, 1645, 5789, 16305, 774, 16409, 17633, 4321, 5712, 14588, 2430, 7707, 3365, 6091, 1687, 14980, 8066, 10156, 15653, 14693, 207, 16080, 12787, 9433, 15394, 13707, 3834, 16146, 9743, 8601, 804, 13993, 580, 14652, 14231, 9469, 15577, 11487, 14699, 6023, 15508, 1346, 5928, 1335, 11311, 2997, 13787, 8223, 868, 14418, 9657, 17744, 221, 5134, 16107, 13053, 16927, 8428, 16497, 4393, 17211, 10025, 8871, 723, 10160, 8378, 16844, 12004, 3312, 3331, 9145, 677, 10246, 5622, 6031, 4799, 12644, 3915, 2861, 15937, 18588, 11158, 15214, 8751, 5660, 8336, 4251, 5443, 11869, 15086, 4413, 18022, 12571, 15455, 17250, 4806, 10374, 6076, 12686, 12177, 1251, 1191, 12491, 12894, 18334, 10483, 2760, 11434, 16590, 6342, 12154, 17388, 5063, 11893, 6504, 4716, 6314, 6395, 10649, 1198, 390, 16545, 10742, 7308, 8838, 17419, 7303, 16212, 11403, 11931, 4727, 9328, 4724, 17245, 6333, 12321, 17928, 13087, 15647, 3530, 16367, 6776, 2156, 12084, 15390, 240, 1319, 8347, 12975, 13912, 2131, 351, 1856, 2256, 10032, 15157, 13200, 364, 5774, 18083, 11413, 9125, 15451, 7109, 6211, 5115, 14731, 1143, 6281, 9001, 7521, 16820, 4354, 10349, 2643, 16372, 9152, 18402, 13241, 9031, 13938, 15152, 13786, 3135, 11312, 740, 13997, 9254, 6783, 542, 791, 4139, 860, 12909, 17859, 11173, 13190, 10133, 3525, 17577, 9207, 4053, 8420, 16601, 12388, 17750, 12265, 1809, 10352, 18137, 1266, 4217, 12365, 5110, 18293, 2667, 2693, 9875, 3216, 8148, 11569, 18550, 2164, 10046, 4827, 12432, 171, 2829, 17504, 11390, 15864, 5507, 15553, 15066, 13840, 1422, 11992, 8438, 15433, 3903, 4499, 14702, 8522, 11153, 11955, 565, 13231, 2620, 7645, 2901, 11186, 4681, 16466, 14775, 12123, 8172, 6839, 3278, 2458, 8769, 8479, 16332, 16975, 3323, 237, 16163, 10890, 10019, 14915, 10077, 15117, 13690, 1261, 8952, 3726, 5027, 18325, 13808, 11185, 2931, 7646, 11774, 3563, 1651, 4349, 6355, 13671, 11837, 3654, 17674, 10826, 780, 17570, 729, 13290, 6867, 5141, 12020, 9959, 4759, 5710, 4323, 1817, 16661, 10232, 18277, 1826, 5083, 12351, 10347, 4356, 15748, 2407, 1292, 2837, 10914, 4508, 930, 15936, 3102, 3916, 11041, 1654, 10580, 8643, 9519, 12077, 11664, 10129, 12442, 4119, 3559, 14238, 15726, 16189, 5996, 16874, 1473, 11539, 6921, 9864, 12927, 10913, 2866, 1293, 17459, 15365, 7991, 11652, 16669, 17503, 2953, 172, 8758, 10084, 15809, 4697, 2195, 146, 8025, 3899, 641, 13954, 4022, 2392, 14623, 12989, 17384, 12059, 1900, 9367, 4881, 13083, 12160, 14829, 15073, 7941, 2423, 14505, 9676, 3701, 7397, 17670, 11605, 13984, 16937, 11937, 11888, 454, 11510, 18574, 11745, 955, 8510, 15770, 13899, 16563, 9097, 235, 3325, 15978, 16981, 13693, 5098, 3733, 3359, 8161, 11464, 4973, 3337, 2331, 7101, 4194, 7738, 855, 4286, 17376, 277, 14769, 11433, 3074, 10484, 14986, 8832, 12871, 1331, 5897, 14493, 197, 16613, 9984, 10671, 1375, 14633, 4993, 9494, 11958, 18099, 2599, 9345, 9586, 6296, 6998, 5988, 9668, 14466, 17730, 7004, 7204, 15645, 13089, 11349, 9260, 5096, 13695, 1919, 438, 8874, 6185, 8320, 1649, 3565, 13051, 16109, 1761, 7530, 7896, 8180, 8087, 7596, 10001, 2562, 13319, 14918, 599, 778, 10828, 12628, 12495, 16232, 18532, 17071, 12548, 6132, 5948, 18173, 9874, 2964, 2668, 1570, 12046, 7755, 16442, 16192, 10402, 8487, 5836, 17464, 13358, 2339, 4533, 244, 383, 536, 11692, 11008, 3625, 2346, 11264, 14952, 5992, 1569, 2692, 2965, 18294, 13185, 8910, 12245, 10391, 1378, 17664, 15733, 15494, 8, 2326, 1241, 4227, 12824, 12913, 15135, 373, 15006, 7264, 14666, 15972, 14438, 16371, 3006, 10350, 1811, 156, 13470, 7355, 10814, 12187, 121, 9068, 5942, 14474, 15038, 13799, 13875, 4467, 8901, 10321, 12479, 3928, 15949, 4158, 7644, 2933, 13232, 15269, 15815, 1615, 2270, 17178, 3852, 12769, 13586, 10199, 9932, 6541, 5616, 2442, 11004, 51, 16043, 13440, 8990, 9344, 2742, 18100, 266, 13772, 5814, 632, 17683, 8849, 11968, 16260, 16762, 12025, 18026, 12135, 10715, 3233, 1434, 12903, 10501, 8299, 14923, 13392, 1625, 18103, 13776, 608, 17647, 17003, 5767, 10090, 9855, 13618, 443, 1429, 3489, 828, 13318, 2709, 10002, 8778, 17322, 6029, 5624, 17990, 6138, 15375, 18543, 15992, 5156, 7463, 8794, 18521, 14205, 17184, 17315, 7349, 6284, 5745, 14912, 6826, 653, 15406, 4290, 8267, 7199, 11929, 11405, 6135, 10782, 2111, 18366, 14172, 18145, 9257, 14594, 16619, 4476, 7450, 10751, 11641, 6846, 5556, 8492, 18387, 15436, 5809, 16825, 8657, 5090, 17890, 4842, 13269, 12473, 8700, 13374, 14865, 9892, 6387, 10837, 6779, 15386, 12235, 5491, 8325, 1246, 16103, 17348, 16101, 1248, 10982, 13460, 15469, 5543, 15878, 16835, 7564, 11410, 7053, 1328, 16, 1164, 6599, 11723, 14327, 2203, 6948, 14209, 12755, 14356, 4557, 16914, 13047, 14515, 11104, 15221, 7716, 5884, 13517, 18269, 7290, 8768, 2922, 3279, 18079, 8358, 9036, 12778, 3225, 8402, 14760, 15442, 8853, 12034, 8115, 6399, 10930, 11003, 2606, 5617, 6374, 16451, 16885, 7916, 7652, 9160, 3203, 18357, 15680, 7706, 3170, 14589, 16380, 8807, 4655, 3445, 14504, 2803, 7942, 17188, 14797, 3269, 2078, 13307, 10410, 12517, 5911, 17060, 13404, 6767, 13446, 11251, 1291, 2868, 15749, 12600, 2152, 15908, 8194, 1992, 6209, 7111, 9441, 195, 14495, 1531, 12790, 14622, 2816, 4023, 11644, 13027, 10314, 15251, 8553, 3378, 11291, 15542, 7193, 1540, 5761, 9923, 12704, 4078, 7493, 17662, 1380, 4273, 1538, 7195, 9168, 14833, 12577, 889, 8075, 15330, 6099, 15894, 64, 9589, 9664, 12625, 13009, 3355, 14228, 5680, 3462, 14175, 3979, 17067, 4766, 5647, 4065, 11263, 2673, 3626, 11206, 12743, 12534, 5857, 4532, 2681, 13359, 10961, 6626, 16005, 1834, 296, 7100, 2770, 3338, 12596, 4851, 1240, 2656, 9, 16529, 5470, 14132, 12960, 7257, 4934, 6525, 5436, 1784, 10101, 210, 17444, 18417, 10038, 1845, 11964, 10994, 14619, 13004, 15245, 12103, 18489, 16986, 17438, 17114, 90, 3514, 3637, 1597, 16511, 11799, 3546, 16419, 12805, 15418, 17822, 17968, 12437, 18000, 1507, 10230, 16663, 12073, 10904, 5924, 4939, 9914, 1643, 7618, 11129, 7911, 8651, 12863, 17177, 2615, 1616, 5168, 5359, 11715, 2243, 10115, 15676, 1621, 17253, 13919, 11916, 11600, 10031, 3027, 1857, 3236, 7638, 17132, 12041, 5879, 7023, 16575, 6516, 6933, 18536, 10114, 2265, 11716, 16743, 12997, 14897, 14646, 3535, 17238, 3405, 5255, 9739, 13952, 643, 14807, 15064, 15555, 11820, 10505, 4156, 15951, 15590, 9444, 4666, 10215, 1753, 999, 4171, 4005, 16167, 9789, 10365, 13540, 11670, 10640, 14291, 8097, 6179, 17599, 6792, 6947, 2475, 14328, 2173, 3493, 11260, 5248, 6241, 145, 2823, 4698, 11681, 7316, 5494, 689, 16733, 10628, 17820, 15420, 963, 13884, 7883, 18253, 7822, 5462, 12900, 2102, 15048, 16303, 5791, 3492, 2201, 14329, 9486, 3387, 14143, 13343, 13435, 14446, 10045, 2958, 18551, 5757, 6345, 7700, 8591, 9819, 12083, 3038, 6777, 10839, 15907, 2404, 12601, 17028, 8354, 18161, 5468, 16531, 12220, 16156, 1711, 9380, 670, 9354, 9541, 6770, 4745, 1107, 13741, 14192, 18219, 350, 3030, 13913, 15667, 3821, 8318, 6187, 16852, 17762, 7475, 3937, 9622, 13654, 8683, 3760, 6020, 4502, 17864, 5307, 11560, 18365, 2530, 10783, 5937, 10202, 310, 10618, 14149, 1504, 15047, 2178, 12901, 1436, 10166, 15473, 14203, 18523, 3455, 3430, 11315, 9462, 16966, 16538, 12334, 6166, 14485, 4433, 16997, 16300, 6797, 9981, 6589, 15285, 13306, 2418, 3270, 5216, 14264, 11912, 1015, 405, 9046, 5977, 5872, 5578, 18585, 16271, 13126, 16449, 6376, 8030, 13332, 5699, 263, 1628, 16505, 6262, 9732, 10099, 1786, 6800, 18204, 15536, 7854, 10610, 8934, 13748, 17839, 8756, 174, 17847, 11093, 14983, 6816, 9083, 7535, 16922, 17104, 10491, 4695, 15811, 9499, 18090, 1037, 9935, 5957, 9247, 8829, 3999, 1978, 18548, 11571, 16347, 12080, 13819, 4142, 204, 17957, 5118, 13687, 4781, 9316, 14781, 1714, 6912, 11281, 7160, 15523, 12254, 4431, 14487, 13546, 4047, 11382, 8008, 10406, 1837, 10174, 15618, 6208, 2401, 8195, 4703, 15199, 11183, 13810, 11213, 6308, 6855, 18397, 15844, 8612, 12008, 18547, 2023, 4000, 16071, 14120, 18038, 18528, 12302, 7240, 662, 4243, 5370, 14499, 3994, 13302, 6366, 8691, 7387, 5854, 17531, 3486, 6205, 847, 17234, 11467, 8474, 7021, 5881, 18184, 5639, 14213, 6552, 12718, 8050, 4984, 17972, 7038, 3756, 15115, 10079, 1891, 8448, 7540, 14001, 16777, 15718, 8364, 16312, 6523, 4936, 17755, 9476, 6942, 15764, 1093, 17047, 7711, 7173, 7138, 437, 2725, 13696, 8822, 7545, 18526, 18040, 14325, 11725, 4255, 12945, 10691, 18555, 15170, 7487, 6573, 8638, 18115, 17078, 9366, 2811, 12060, 10851, 18290, 9636, 17308, 7063, 797, 8447, 1939, 10080, 11986, 17520, 7661, 218, 3840, 12867, 7045, 258, 12037, 17367, 11634, 14077, 3341, 14449, 18088, 9501, 7321, 18435, 3650, 10735, 3634, 17628, 5551, 10439, 17407, 10051, 17905, 16406, 7968, 6202, 1432, 3235, 2255, 3028, 352, 13577, 6878, 16354, 5599, 11193, 7899, 9222, 3496, 11963, 2310, 10039, 16767, 13514, 17149, 17037, 13182, 10173, 1996, 10407, 295, 2334, 16006, 6571, 7489, 3376, 8555, 16752, 5082, 2874, 18278, 6967, 17298, 13254, 4874, 8444, 4593, 16660, 2878, 4324, 9277, 3816, 5347, 155, 2641, 10351, 2973, 12266, 15001, 4966, 13080, 10602, 6945, 6794, 15051, 5582, 9525, 12655, 8666, 695, 13298, 7685, 11632, 17369, 6306, 11215, 16899, 9979, 6799, 2053, 10100, 2316, 5437, 5795, 13131, 5697, 13334, 12065, 1184, 11073, 15586, 14242, 5006, 7434, 12785, 16082, 9939, 4473, 559, 14138, 12702, 9925, 5963, 7529, 2716, 16110, 11032, 7271, 181, 7809, 12414, 998, 2219, 10216, 15481, 6592, 5330, 18445, 4399, 11583, 5129, 12407, 16470, 834, 11082, 17033, 9811, 1050, 7209, 719, 10863, 8981, 13409, 9754, 11361, 17852, 7931, 4189, 15093, 10855, 17742, 9659, 4849, 12598, 15751, 17123, 10791, 1582, 11367, 4034, 6911, 2009, 14782, 9379, 2143, 16157, 10680, 8388, 3870, 7002, 17732, 8899, 4469, 8352, 17030, 8329, 9188, 14825, 7379, 16806, 8617, 4339, 979, 6972, 12400, 3986, 17107, 14979, 3166, 6092, 8624, 12319, 6335, 14037, 16126, 5549, 17630, 4713, 13857, 11179, 12985, 11059, 16559, 1492, 3753, 6596, 5541, 15471, 10168, 6221, 8236, 10723, 5561, 5833, 11168, 7622, 4610, 15800, 6659, 5416, 10579, 2858, 11042, 4348, 2897, 3564, 2720, 8321, 6835, 5788, 3179, 7617, 2277, 9915, 8810, 4913, 13679, 7838, 3240, 10429, 4837, 10419, 13866, 9269, 12172, 9132, 16504, 2058, 264, 18102, 2577, 13393, 4804, 17252, 2262, 15677, 15273, 3715, 5167, 2269, 2616, 15816, 4903, 17336, 6318, 105, 16293, 1158, 10872, 893, 13598, 10324, 12524, 4867, 12284, 18094, 14161, 16510, 2296, 3638, 13520, 3876, 947, 16023, 12829, 3289, 14016, 14224, 8641, 10582, 15413, 12181, 11366, 1718, 10792, 13566, 272, 8820, 13698, 17201, 9392, 10710, 344, 4380, 12045, 2691, 2669, 5993, 16445, 10242, 16894, 10267, 7512, 16855, 8785, 1456, 1445, 16755, 5414, 6661, 1353, 11243, 9597, 7829, 13280, 3722, 17501, 16671, 10885, 11578, 17450, 12316, 9611, 12151, 5760, 2381, 7194, 2372, 4274, 12683, 16182, 5192, 9431, 12789, 2395, 14496, 14615, 16244, 13830, 5268, 62, 15896, 6048, 7580, 7059, 13551, 5574, 479, 16693, 9230, 701, 4511, 11720, 727, 17572, 18249, 14217, 10229, 2285, 18001, 15046, 2104, 14150, 18210, 18061, 11710, 6269, 1479, 18507, 1083, 8277, 7224, 3752, 1672, 16560, 8105, 14608, 16906, 3617, 17680, 8433, 10219, 5333, 1156, 16295, 18506, 1498, 6270, 5657, 4186, 11013, 11538, 2843, 16875, 7805, 10810, 3712, 1129, 5239, 5801, 9361, 10956, 16343, 6555, 17537, 14070, 6645, 13732, 1444, 1560, 8786, 17903, 10053, 9022, 5861, 4954, 3301, 12709, 5080, 16754, 1559, 1457, 13733, 5446, 9517, 8645, 14728, 17960, 10165, 2100, 12902, 2583, 3234, 1859, 6203, 3488, 2566, 444, 4734, 6290, 7117, 12858, 11991, 2945, 13841, 7260, 5731, 16324, 15981, 14744, 5905, 17515, 13024, 4389, 16049, 1281, 8043, 10652, 16174, 3799, 9761, 5726, 11552, 4845, 758, 14793, 4616, 15280, 5182, 4426, 4896, 17019, 9204, 18193, 6649, 15368, 10195, 6717, 4334, 6673, 14201, 15475, 8571, 553, 4272, 2374, 17663, 2661, 10392, 14632, 2748, 10672, 394, 17604, 96, 12591, 11975, 10338, 14007, 12696, 4104, 10191, 3837, 17747, 16639, 7129, 13624, 15059, 16359, 15191, 5123, 11242, 1555, 6662, 13870, 15548, 12263, 17752, 5927, 3139, 15509, 13790, 16973, 16334, 4677, 487, 1071, 3422, 4691, 11310, 3137, 5929, 7776, 5896, 2755, 12872, 15, 2481, 7054, 11676, 11418, 10738, 10282, 6011, 3621, 8346, 3034, 241, 11883, 11482, 9156, 17801, 6364, 13304, 15287, 7870, 13036, 4539, 7703, 8578, 1270, 11231, 3414, 13492, 17979, 5483, 531, 11627, 16772, 5342, 14930, 17458, 2836, 2867, 2408, 11252, 3249, 8958, 16700, 11533, 1116, 885, 6977, 8042, 1410, 16050, 11247, 12275, 18492, 10311, 17587, 9816, 16036, 12567, 11230, 1305, 8579, 14397, 4216, 2970, 18138, 17696, 10594, 8951, 2908, 13691, 16983, 12278, 15056, 10179, 9683, 6352, 8154, 1190, 3080, 12178, 10981, 2491, 16102, 2495, 8326, 11085, 15076, 4226, 2655, 2327, 4852, 4405, 9824, 10118, 15234, 10436, 11848, 11767, 17944, 17535, 6557, 16715, 6962, 16803, 12290, 5474, 12797, 3412, 11233, 14308, 15831, 18319, 18120, 15411, 10584, 17613, 6889, 5605, 15782, 6537, 8020, 6440, 15526, 13533, 3908, 5735, 6606, 13222, 3983, 14221, 389, 3061, 10650, 8045, 7460, 11908, 6755, 12490, 3079, 1252, 8155, 16730, 8545, 14389, 11072, 1777, 12066, 13194, 584, 6656, 6709, 11359, 9756, 15540, 11293, 3932, 7251, 6892, 11713, 5361, 3328, 13416, 591, 5539, 6598, 2479, 17, 10939, 7326, 9867, 10871, 1608, 16294, 1482, 5334, 10644, 11896, 18384, 16282, 179, 7273, 14428, 7091, 7016, 17050, 6280, 3013, 14732, 3214, 9877, 3285, 3664, 17301, 15760, 3231, 10717, 4485, 12758, 15912, 5238, 1468, 3713, 15275, 5488, 14045, 13031, 18478, 4529, 14892, 11200, 7069, 6809, 884, 1285, 11534, 5046, 8311, 12586, 9331, 3505, 8341, 13740, 2136, 4746, 9988, 12357, 13583, 4949, 4345, 3926, 12481, 5645, 4768, 10987, 14872, 17046, 1925, 15765, 15643, 7206, 11502, 11581, 4401, 378, 9692, 8276, 1496, 18508, 12689, 17181, 5572, 13553, 13220, 6608, 16707, 10935, 5846, 3421, 1339, 488, 9489, 8888, 17844, 6059, 12740, 16635, 15110, 14949, 650, 17365, 12039, 17134, 4526, 5059, 11873, 619, 9704, 11500, 7208, 1738, 9812, 6909, 4036, 15338, 6074, 10376, 15400, 13593, 13177, 8018, 6539, 9934, 2029, 18091, 11743, 18576, 7658, 12751, 8070, 525, 14416, 870, 3571, 17814, 15707, 17867, 17084, 347, 3592, 13631, 15069, 15614, 9389, 404, 2073, 11913, 17657, 3955, 4548, 5566, 8283, 17320, 8780, 38, 3427, 3968, 12452, 8861, 8498, 4170, 2218, 1754, 12415, 16389, 11804, 9026, 12615, 18200, 17223, 18500, 7999, 9646, 18462, 14479, 8485, 10404, 8010, 17381, 11707, 6971, 1693, 4340, 14041, 17774, 9832, 6842, 9967, 14075, 11636, 3781, 15079, 14960, 16727, 13045, 16916, 13883, 2185, 15421, 14275, 5449, 17643, 18458, 10056, 8509, 2788, 11746, 13145, 17636, 138, 5526, 17986, 16022, 1593, 3877, 5378, 15321, 7679, 14089, 5480, 4674, 6681, 17582, 14641, 7299, 7267, 11101, 16220, 17216, 15935, 2863, 4509, 703, 13755, 11197, 15797, 6991, 4619, 14940, 15704, 7770, 3991, 589, 13418, 14977, 17109, 10163, 17962, 16002, 9747, 9185, 5755, 18553, 10693, 5281, 5945, 11408, 7566, 13889, 11508, 456, 17331, 8002, 4670, 12611, 15204, 13597, 1606, 10873, 7668, 8074, 2367, 12578, 10011, 6976, 1284, 1117, 6810, 11925, 5431, 3470, 361, 6234, 4437, 12368, 10659, 8797, 10257, 14346, 3570, 1028, 14417, 3132, 8224, 4128, 15861, 11592, 16890, 9697, 12908, 2988, 4140, 13821, 10970, 4285, 2766, 7739, 16870, 8937, 15466, 18375, 14757, 17233, 1957, 6206, 15620, 6331, 17247, 12669, 13658, 16666, 9120, 7376, 14524, 7505, 11081, 1742, 16471, 11121, 3742, 9219, 13317, 2564, 3490, 5793, 5439, 13669, 6357, 4553, 17619, 8764, 6479, 9673, 9138, 5750, 14414, 527, 5153, 9607, 4523, 11952, 10333, 5231, 9805, 12635, 13992, 3150, 8602, 6454, 5974, 9728, 4591, 8446, 1893, 7064, 9438, 17281, 12232, 4138, 2990, 543, 8802, 190, 687, 5496, 5337, 14296, 15194, 15023, 17569, 2889, 10827, 2705, 600, 7966, 16408, 3176, 16306, 628, 11519, 14387, 8547, 13770, 268, 4789, 10636, 9066, 123, 12095, 14117, 11147, 14792, 1401, 4846, 16550, 9840, 4569, 11498, 9706, 17528, 12537, 18420, 16553, 7503, 14526, 10622, 7233, 16865, 10665, 13996, 2995, 11313, 3432, 5685, 15609, 7423, 10477, 128, 14092, 16480, 13289, 2887, 17571, 1512, 11721, 6601, 10159, 3117, 8872, 440, 10862, 1736, 7210, 6467, 12405, 5131, 9467, 14233, 5388, 9088, 11461, 13368, 11809, 7454, 13504, 16085, 13754, 928, 4510, 1515, 9231, 10363, 9791, 18407, 13297, 1796, 8667, 9808, 17141, 8543, 16732, 2190, 5495, 787, 191, 5356, 9420, 8207, 7673, 14684, 8654, 14124, 10245, 3109, 9146, 5932, 11853, 12424, 15352, 9353, 2141, 9381, 6273, 15551, 5509, 29, 14107, 4242, 1970, 7241, 6067, 5172, 18311, 12727, 11980, 7478, 15405, 2539, 6827, 17364, 1061, 14950, 11266, 5671, 4815, 6497, 14806, 2231, 13953, 2819, 3900, 18390, 16580, 13478, 3866, 17157, 8431, 17682, 2594, 5815, 15372, 11518, 772, 16307, 6159, 3368, 13610, 16651, 11558, 5309, 9703, 1054, 11874, 5102, 17294, 13113, 13923, 5986, 7000, 3872, 13068, 17646, 2574, 13777, 12970, 16039, 12458, 7815, 13211, 7965, 777, 2706, 14919, 13509, 6157, 16309, 17089, 3550, 5538, 1167, 13417, 918, 3992, 14501, 4832, 6655, 1181, 13195, 33, 14651, 3148, 13994, 10667, 5198, 13970, 14545, 14181, 15506, 6025, 6427, 6569, 16008, 6461, 8969, 13230, 2935, 11956, 9496, 18362, 11190, 14137, 1767, 4474, 16621, 68, 16681, 4271, 1382, 8572, 8689, 6368, 9535, 11150, 3849, 12692, 4410, 8801, 790, 2991, 6784, 11143, 7846, 14820, 11691, 2677, 384, 17094, 6886, 11626, 1299, 5484, 9051, 5152, 814, 14415, 1030, 8071, 12147, 12206, 7760, 13077, 4057, 4892, 15315, 16139, 10238, 7141, 12820, 15574, 7183, 11544, 184, 4145, 16720, 9095, 16565, 17559, 6853, 6310, 16995, 4435, 6236, 5014, 6636, 15852, 15997, 18330, 16969, 16019, 4820, 3385, 9488, 1070, 1340, 4678, 11564, 14860, 15238, 4369, 9956, 16692, 1518, 5575, 7696, 275, 17378, 3185, 10755, 15357, 10959, 13361, 10688, 14533, 13846, 13276, 9017, 8916, 13000, 9237, 12814, 7981, 8242, 15624, 17330, 900, 11509, 2792, 11889, 15131, 4422, 16068, 9339, 11814, 3211, 15335, 4733, 1428, 2567, 13619, 10861, 721, 8873, 2724, 1920, 7139, 10240, 16447, 13128, 15186, 7222, 8279, 3346, 5531, 15146, 12338, 10920, 3913, 12646, 15900, 8722, 18239, 10454, 3568, 14348, 7483, 8040, 6979, 10877, 12713, 16644, 12957, 18275, 10234, 10305, 9045, 2072, 1016, 9390, 17203, 11947, 9181, 3785, 282, 5870, 5979, 17603, 1373, 10673, 11794, 16544, 3060, 1199, 14222, 14018, 4444, 17093, 535, 2678, 245, 9640, 10990, 9691, 1086, 4402, 16462, 18246, 15005, 2650, 15136, 9398, 4032, 11369, 14845, 255, 14366, 5773, 3023, 13201, 6233, 879, 3471, 12933, 10261, 9872, 18175, 8142, 14907, 13576, 1855, 3029, 2132, 18220, 3591, 1022, 17085, 4379, 1573, 10711, 16413, 10774, 9654, 6217, 11863, 6254, 112, 168, 12508, 57, 8483, 14481, 10343, 6860, 14955, 5077, 16134, 11306, 11341, 12993, 4461, 5637, 18186, 8362, 15720, 16770, 11629, 4442, 14020, 6735, 14708, 10617, 2107, 10203, 7632, 11971, 7743, 16698, 8960, 13484, 15629, 15929, 5411, 8424, 14024, 7099, 2333, 1835, 10408, 13309, 7796, 10708, 9394, 10395, 10496, 12418, 12853, 13422, 17937, 5869, 398, 3786, 3533, 14648, 14768, 2763, 17377, 476, 7697, 8819, 1579, 13567, 15691, 4788, 767, 13771, 2597, 18101, 1627, 2059, 5700, 15519, 8113, 12036, 1882, 7046, 14365, 367, 14846, 14536, 13705, 15396, 12471, 13271, 13400, 15344, 9639, 382, 2679, 4534, 11882, 1318, 3035, 15391, 16162, 2916, 3324, 2782, 9098, 18033, 7406, 7034, 16483, 16066, 4424, 5184, 8843, 84, 6421, 9465, 5133, 3128, 17745, 3839, 1886, 7662, 14443, 6691, 11698, 3246, 6698, 17443, 2314, 10102, 16079, 3160, 14694, 17956, 2016, 4143, 186, 5300, 7569, 11739, 16612, 2752, 14494, 2397, 9442, 15592, 5355, 686, 788, 8803, 17898, 5299, 202, 4144, 509, 11545, 7808, 1757, 7272, 1150, 16283, 8558, 6057, 17846, 2043, 8757, 2828, 2954, 12433, 12507, 335, 113, 10368, 13719, 10153, 4018, 7392, 11273, 16723, 14946, 8883, 13469, 2640, 1812, 5348, 14802, 8374, 13264, 16847, 14197, 3669, 8024, 2822, 2196, 6242, 8250, 11737, 7571, 10702, 5525, 951, 17637, 8540, 9575, 8948, 17608, 4117, 12444, 5478, 14091, 733, 10478, 12198, 7948, 12094, 763, 9067, 2635, 12188, 5831, 5563, 17472, 14067, 13538, 10367, 167, 336, 6255, 7677, 15323, 13381, 6491, 16292, 1610, 6319, 17318, 8285, 10599, 4884, 5503, 4793, 12590, 1371, 17605, 10597, 8287, 4496, 3513, 2299, 17115, 17098, 17513, 5907, 6420, 225, 8844, 8035, 3952, 11298, 8344, 3623, 11010, 7934, 9800, 16047, 4391, 16499, 15141, 11049, 16680, 556, 16622, 6294, 9588, 2362, 15895, 1525, 5269, 11661, 16350, 8482, 333, 12509, 12052, 12981, 3219, 16042, 2604, 11005, 6586, 16616, 16573, 7025, 15636, 16432, 12839, 17687, 7903, 16687, 3426, 1006, 8781, 11688, 14766, 14650, 582, 13196, 10537, 14106, 665, 5510, 6437, 5207, 13171, 14552, 12678, 7084, 15805, 6851, 17561, 10938, 1163, 2480, 1329, 12873, 7748, 6762, 13016, 16528, 2325, 2657, 15495, 7438, 4649, 12396, 9297, 18593]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-product-permutation-l6-s1/tests/check.py b/tasks/construct-rlve-prefix-product-permutation-l6-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3d93850acd79cc0f8fff05cdbb0c63aabc484815 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l6-s1/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("perm"), n, 1, n, "perm") + if len(set(p)) != n: + raise Invalid("not a permutation") + seen, acc = set(), 1 + for v in p: + acc = acc * v % n + if acc in seen: + raise Invalid(f"prefix product residue {acc} repeats") + seen.add(acc) + return None, {} diff --git a/tasks/construct-rlve-prefix-product-permutation-l6-s1/tests/instance.json b/tasks/construct-rlve-prefix-product-permutation-l6-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..69c121c6174fff7a31874c600882d260e3293587 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l6-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 18593, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l6-s1/tests/run.py b/tasks/construct-rlve-prefix-product-permutation-l6-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l6-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prefix-product-permutation-l6-s1/tests/test.sh b/tasks/construct-rlve-prefix-product-permutation-l6-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l6-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prefix-product-permutation-l6-s6/environment/Dockerfile b/tasks/construct-rlve-prefix-product-permutation-l6-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l6-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prefix-product-permutation-l6-s6/environment/instance.json b/tasks/construct-rlve-prefix-product-permutation-l6-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a8674d27c514255e9ab362cdbcb7162c38e8181c --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l6-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 21247, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l6-s6/solution/solve.sh b/tasks/construct-rlve-prefix-product-permutation-l6-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..862192a703eb56a17c754d7b71fdd56bde2420f0 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l6-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"perm": [1, 2, 10625, 14166, 5313, 8500, 17707, 9107, 2657, 11805, 14874, 17385, 8854, 8173, 4554, 2834, 1329, 7500, 5903, 16775, 18061, 17201, 8693, 12934, 15051, 14449, 4087, 11018, 12901, 2199, 12041, 12338, 665, 12878, 14374, 10321, 2952, 2298, 8388, 2725, 9031, 4665, 8601, 8401, 4347, 15110, 17091, 14015, 7526, 13443, 7225, 9583, 2044, 3609, 16133, 16226, 6451, 19757, 1100, 15126, 6021, 5574, 16793, 19899, 333, 18633, 17063, 7929, 17811, 4312, 5161, 20051, 12100, 5240, 11773, 4817, 14818, 8555, 1363, 5380, 4516, 17838, 2333, 257, 4301, 14249, 4201, 7816, 2174, 6208, 18179, 7239, 8546, 18278, 7008, 16104, 14387, 5258, 6722, 18458, 3613, 6312, 4792, 14647, 11646, 3441, 1805, 1391, 8067, 7993, 18737, 7849, 3226, 14103, 9879, 6837, 11174, 909, 18187, 19284, 3011, 7376, 13411, 8638, 8397, 7140, 9950, 1674, 167, 2801, 9317, 17842, 8532, 20609, 3965, 19202, 8906, 8841, 12780, 1071, 2581, 18837, 10026, 4607, 16674, 4690, 13244, 11564, 5887, 10981, 2409, 17871, 18033, 3195, 4278, 19466, 682, 407, 13314, 8286, 12882, 17025, 19543, 2608, 1167, 19574, 129, 18449, 2151, 2264, 7125, 20751, 2101, 17932, 14532, 2065, 11711, 12125, 13728, 7479, 9090, 12444, 3620, 8941, 14897, 17458, 19763, 12272, 14128, 13716, 18676, 15241, 7194, 3744, 13253, 13294, 13985, 3668, 19853, 1389, 1807, 9726, 13780, 315, 13020, 13682, 7324, 1438, 16447, 5389, 1721, 12286, 903, 20849, 696, 1681, 4034, 7834, 3997, 15912, 9369, 5481, 3925, 19533, 12237, 15771, 7052, 469, 4940, 13176, 3419, 17017, 16211, 8208, 455, 15552, 9094, 1794, 20266, 890, 1506, 15253, 14312, 13029, 6706, 19687, 14943, 12732, 4199, 14251, 14194, 14730, 15599, 12766, 11461, 18915, 84, 16949, 1401, 9435, 4659, 2606, 19545, 12523, 14890, 4972, 10305, 2070, 1983, 15956, 20225, 14035, 15077, 9496, 4421, 3246, 17014, 9589, 536, 20258, 1291, 12477, 9419, 6758, 15637, 12451, 2304, 18879, 18961, 15440, 12969, 15918, 17246, 9428, 16406, 3026, 2944, 20318, 5491, 5899, 1205, 1201, 8936, 9187, 9017, 5365, 1598, 19587, 12763, 4883, 20357, 19745, 10965, 7468, 204, 8230, 17281, 13272, 14767, 7927, 17065, 14629, 8513, 5987, 9772, 20725, 11928, 2665, 584, 2003, 20411, 1349, 65, 2617, 9225, 5836, 1076, 1325, 11756, 11784, 3563, 20438, 10376, 20133, 1051, 9362, 19590, 797, 17890, 14673, 1033, 7386, 5856, 13002, 6063, 4011, 17488, 13511, 3740, 13199, 15169, 14303, 16846, 16624, 12434, 13797, 4471, 9264, 7449, 2880, 19353, 6587, 9882, 4558, 16760, 9463, 17688, 8342, 17482, 19398, 19962, 7641, 7621, 13426, 14221, 14460, 12496, 15099, 6627, 5026, 17271, 13260, 6993, 5948, 12458, 13825, 9927, 15575, 695, 21035, 904, 3551, 15487, 950, 17514, 20566, 158, 7936, 17134, 2027, 17465, 10030, 14286, 5197, 11343, 8551, 8224, 7440, 2695, 4007, 861, 7874, 16767, 13362, 452, 7100, 10425, 9903, 10972, 15701, 841, 13114, 12641, 4957, 14541, 1564, 1999, 6273, 18580, 7164, 4685, 18020, 2741, 20001, 1963, 18240, 9767, 3661, 6119, 2509, 7886, 425, 14150, 13040, 235, 5698, 13094, 18226, 17212, 8148, 1710, 19174, 8509, 15833, 8106, 20654, 14728, 14196, 228, 16310, 18400, 14301, 15171, 16217, 11521, 7471, 20757, 9845, 11069, 622, 11377, 9984, 7627, 12758, 17780, 18050, 6515, 16318, 13977, 870, 9844, 20772, 7472, 16378, 16990, 20690, 2100, 21077, 7126, 10220, 17721, 20315, 17989, 8956, 7800, 9762, 17007, 14920, 5731, 5678, 9458, 6820, 10666, 14000, 8475, 11429, 701, 1275, 4718, 5978, 2330, 1306, 11927, 20923, 9773, 689, 6262, 5726, 18069, 6106, 13110, 18207, 5153, 18338, 11659, 279, 992, 9576, 18602, 1223, 10113, 4164, 7018, 11231, 7539, 18597, 15372, 15072, 2211, 2981, 12247, 5708, 19131, 6840, 4795, 5820, 10892, 2099, 20753, 16991, 646, 18256, 6239, 14455, 4710, 19819, 14003, 11655, 7819, 19605, 6226, 16113, 11776, 5081, 9440, 9867, 9481, 7292, 18344, 8331, 6485, 15214, 18583, 329, 19247, 4432, 15338, 8869, 18827, 16306, 12137, 15388, 12096, 14727, 20783, 8107, 2746, 7546, 2950, 10323, 603, 10925, 601, 10325, 15092, 1476, 4594, 10607, 4509, 7188, 2683, 1079, 11423, 1942, 9794, 18726, 6382, 9953, 2442, 9303, 10179, 480, 9873, 3923, 5483, 14177, 14358, 1797, 10726, 15134, 14739, 6365, 8641, 4096, 17260, 4585, 7384, 1035, 3964, 21115, 8533, 2487, 7315, 20488, 4257, 561, 2994, 1840, 15510, 1376, 10363, 2612, 16588, 18645, 1333, 12068, 10916, 12387, 1002, 11092, 10206, 15880, 675, 8910, 33, 8372, 1309, 19496, 4613, 13594, 13542, 15960, 11162, 5368, 663, 12340, 16502, 4332, 16516, 752, 1782, 157, 20843, 17515, 15812, 1769, 10067, 11475, 526, 14988, 15305, 4275, 20419, 5673, 399, 215, 19569, 2775, 7337, 9819, 517, 19975, 14317, 9068, 13552, 12267, 17125, 16079, 3032, 5545, 2006, 7681, 19368, 10699, 6756, 9421, 12494, 14462, 6600, 9605, 7585, 20305, 7152, 5085, 19047, 13687, 18936, 8681, 16841, 11426, 6899, 15493, 2236, 6378, 15256, 6563, 3725, 12311, 12064, 7045, 9677, 11327, 3294, 13670, 15565, 2197, 12903, 4751, 19004, 15376, 4732, 680, 19468, 11993, 14795, 3575, 19365, 7916, 20323, 4256, 20605, 7316, 3821, 4178, 3811, 13388, 17337, 7702, 7111, 8649, 17854, 19815, 16872, 11133, 7550, 3894, 3314, 10228, 13137, 2483, 8636, 13413, 17254, 15034, 3497, 8581, 13598, 10638, 16853, 4175, 6913, 17192, 4964, 10236, 7788, 1658, 348, 3360, 10518, 3325, 11076, 7773, 1776, 10135, 7744, 16154, 11099, 19484, 19381, 10375, 20907, 3564, 10703, 4679, 14592, 17520, 19191, 12744, 1014, 3166, 8733, 12449, 15639, 18434, 17767, 8165, 2599, 3084, 5672, 20556, 4276, 3197, 14736, 5791, 14344, 7940, 1348, 20918, 2004, 5547, 431, 8136, 14561, 11242, 8384, 4703, 17305, 16231, 10850, 16418, 14174, 3796, 5213, 12804, 4952, 4151, 16110, 3224, 7851, 17241, 421, 13376, 17181, 14576, 6321, 12086, 2479, 19312, 7271, 490, 11406, 5514, 1000, 12389, 3137, 13162, 19914, 9183, 14206, 17308, 2343, 9696, 19634, 14294, 1371, 15174, 10001, 5702, 982, 240, 19744, 20938, 4884, 15276, 1831, 5746, 3060, 1967, 1255, 5555, 14567, 8962, 213, 401, 17699, 6739, 17144, 10074, 118, 3063, 13473, 5132, 17171, 9682, 19737, 1789, 19230, 5585, 14698, 15260, 11479, 13612, 20211, 12984, 4255, 20490, 7917, 15793, 14677, 5490, 20951, 2945, 17988, 20747, 17722, 10954, 10738, 16146, 18779, 2490, 19824, 15829, 7151, 20527, 7586, 2744, 8109, 13171, 5761, 404, 3736, 11507, 10379, 1740, 4923, 3049, 5535, 2643, 10935, 13405, 5689, 9309, 15616, 4877, 3814, 4999, 17003, 8658, 19514, 16161, 19649, 1664, 3258, 12295, 18783, 6909, 6989, 3872, 11059, 10223, 15546, 889, 21010, 1795, 14360, 17732, 18813, 14833, 19119, 1290, 20969, 537, 11674, 14615, 10539, 4528, 14187, 18712, 15734, 873, 8861, 659, 10158, 5890, 8995, 1946, 15102, 9137, 14524, 19416, 15505, 14607, 8504, 819, 18084, 12812, 2866, 11011, 13463, 17474, 15353, 2082, 14034, 20978, 15957, 11236, 17624, 18393, 4238, 13794, 5715, 6575, 351, 13864, 638, 17286, 12983, 20326, 13613, 13559, 11789, 14431, 11277, 16746, 5964, 5328, 10462, 11974, 4887, 1115, 345, 11888, 13755, 9545, 13487, 2458, 9035, 14695, 13677, 11417, 17179, 13378, 9104, 14712, 2577, 8420, 19793, 4342, 5830, 8468, 140, 18669, 11120, 13268, 15412, 337, 19925, 18565, 612, 9827, 5057, 6153, 12706, 18933, 14133, 5817, 5616, 8836, 3770, 5542, 9299, 16613, 18310, 17574, 18160, 11682, 1106, 7206, 1491, 59, 6124, 10171, 13478, 8573, 9566, 1097, 14044, 8043, 2398, 11228, 13534, 12164, 16070, 16361, 1050, 20905, 10377, 11509, 8496, 1520, 10947, 17571, 19752, 5431, 3120, 3155, 7228, 2433, 12979, 13645, 9910, 16946, 7002, 3264, 5828, 4344, 3910, 13549, 9803, 2967, 13737, 6444, 8057, 9630, 16512, 2636, 2541, 15839, 15344, 4476, 4934, 17593, 4741, 2673, 14270, 11903, 19796, 7016, 4166, 15950, 3243, 12116, 18231, 14324, 9292, 18640, 165, 1676, 9624, 8707, 12840, 1761, 18293, 11503, 4435, 11610, 9414, 5922, 18777, 16148, 6069, 15455, 18318, 18536, 16672, 4609, 7364, 7143, 10392, 10419, 4054, 19357, 11997, 8425, 14397, 12927, 12099, 21177, 5162, 20043, 302, 12314, 5463, 15349, 301, 20049, 5163, 11179, 18170, 14482, 11362, 17739, 12921, 10896, 5304, 6856, 2255, 8416, 14218, 3853, 1342, 2646, 540, 11137, 5712, 12437, 11595, 14841, 15521, 3182, 19987, 7371, 13815, 3344, 4977, 11046, 11845, 17057, 4652, 1733, 5090, 1559, 10864, 1283, 4937, 2851, 1962, 20805, 2742, 7588, 7089, 9563, 17803, 19281, 899, 15695, 15987, 15501, 18191, 11578, 7370, 20018, 3183, 16790, 4321, 2554, 12672, 16955, 19254, 11537, 2293, 2893, 14316, 20547, 518, 16532, 12606, 17155, 10558, 14437, 4267, 10384, 1244, 16313, 3658, 7640, 20868, 19399, 2129, 990, 281, 8773, 12121, 4372, 11544, 14636, 18379, 8929, 11312, 1653, 5182, 2663, 11930, 3409, 18918, 522, 9323, 12876, 667, 1754, 16658, 9174, 16082, 7024, 6194, 19503, 11125, 9471, 16170, 11293, 15727, 1915, 18564, 20172, 338, 9494, 15079, 18414, 17, 13750, 14810, 2603, 655, 9182, 20372, 13163, 2307, 11284, 17421, 2762, 17395, 1221, 18604, 10316, 16205, 3192, 13308, 837, 332, 21185, 16794, 3571, 18875, 14307, 12790, 15556, 18882, 11744, 11000, 18512, 11515, 12693, 79, 15870, 10422, 1900, 8758, 14347, 18530, 6954, 885, 6076, 5034, 6160, 5738, 650, 10887, 9799, 18118, 12666, 7653, 7709, 2138, 6392, 10210, 6168, 2837, 1395, 200, 19443, 108, 13183, 9785, 18411, 1388, 21050, 3669, 17537, 4910, 4299, 259, 11815, 9988, 5786, 7159, 10995, 15158, 19602, 17400, 15367, 6134, 7515, 8563, 11850, 8040, 18350, 12140, 18594, 2773, 19571, 11627, 12187, 3841, 15828, 20308, 2491, 5350, 8473, 14002, 20683, 4711, 17447, 16871, 20477, 17855, 8026, 13924, 208, 4803, 6350, 3793, 5486, 10153, 10411, 14200, 15837, 2543, 3202, 9524, 18418, 6844, 7015, 20092, 11904, 4341, 20182, 8421, 3880, 16337, 16952, 3450, 5440, 7747, 3806, 11742, 18884, 13813, 7373, 18252, 19064, 3282, 15196, 1863, 14007, 6156, 606, 16656, 1756, 3523, 5460, 4839, 16485, 5664, 2279, 12271, 21062, 17459, 13918, 7783, 14042, 1099, 21191, 6452, 17676, 2376, 5430, 20126, 17572, 18312, 6025, 12990, 12585, 10964, 20937, 20358, 241, 5997, 16257, 7398, 2986, 1788, 20334, 9683, 15364, 14582, 10337, 10162, 4721, 12752, 1120, 10303, 4974, 14282, 3684, 1911, 13822, 12713, 16058, 1906, 9756, 17318, 1819, 8669, 2274, 14475, 12417, 3556, 5254, 4325, 18832, 19551, 16050, 9908, 13647, 19060, 17975, 5567, 12925, 14399, 15295, 12571, 7508, 12281, 13436, 15738, 16698, 6569, 16158, 1242, 10386, 14942, 21003, 6707, 436, 19251, 18492, 18141, 17343, 1749, 6975, 4291, 2760, 17423, 12009, 15943, 14395, 8427, 2251, 2088, 7644, 3457, 16074, 19220, 3786, 13106, 11154, 15742, 2036, 14518, 12209, 11453, 2525, 10798, 13152, 12304, 10085, 15883, 307, 1663, 20278, 16162, 2204, 3887, 10989, 11512, 7176, 5068, 6387, 14496, 10882, 18701, 10275, 5550, 14293, 20366, 9697, 9691, 14573, 5188, 19017, 10454, 2321, 12406, 8471, 5352, 16894, 2340, 4206, 17920, 17909, 19384, 7244, 9596, 8263, 16996, 13282, 11131, 16874, 12207, 14520, 4367, 12107, 6225, 20679, 7820, 17399, 19841, 15159, 8884, 9059, 4083, 9936, 1300, 16068, 12166, 4520, 13460, 796, 20902, 9363, 12762, 20941, 1599, 972, 17992, 9023, 2896, 5864, 17796, 17518, 14594, 14865, 11298, 128, 21083, 1168, 11626, 19829, 2774, 20552, 216, 17216, 14692, 6086, 7281, 13014, 16245, 14321, 14816, 4819, 2352, 5919, 8653, 7167, 8116, 6607, 16049, 19708, 18833, 5591, 17711, 10968, 12522, 20986, 2607, 21086, 17026, 13618, 13100, 461, 2076, 14443, 18679, 12454, 12236, 21025, 3926, 9121, 8621, 15859, 211, 8964, 17312, 19127, 8591, 10372, 17912, 3901, 3161, 4855, 16667, 16596, 1240, 16160, 20280, 8659, 3636, 9860, 10869, 954, 16327, 15622, 13381, 5072, 11124, 19933, 6195, 3905, 1569, 14275, 17205, 4612, 20581, 1310, 4592, 1478, 17727, 11211, 19278, 8408, 1172, 2957, 15472, 19380, 20441, 11100, 17771, 5436, 686, 11183, 18211, 17001, 5001, 5130, 13475, 803, 11115, 17661, 10744, 11992, 20496, 681, 21093, 4279, 13066, 2703, 18262, 1511, 916, 2020, 13497, 2516, 12154, 238, 984, 6890, 628, 10524, 2778, 11528, 7284, 16824, 15105, 17807, 107, 19859, 201, 11524, 8850, 17607, 3370, 4119, 19196, 4384, 15661, 7575, 10683, 3930, 1532, 12581, 6737, 17701, 13190, 11621, 8586, 11259, 15465, 9479, 9869, 5972, 895, 15504, 20239, 14525, 2793, 6103, 17973, 19062, 18254, 648, 5740, 13931, 17430, 5869, 10106, 13325, 17116, 3268, 2128, 19961, 20869, 17483, 3959, 15469, 7897, 9817, 7339, 10184, 13369, 11796, 10476, 6052, 1473, 7243, 19618, 17910, 10374, 20440, 19485, 15473, 16101, 6860, 15993, 16926, 18697, 18891, 9390, 14626, 11869, 10698, 20536, 7682, 7915, 20492, 3576, 10168, 10264, 19210, 14417, 18751, 11996, 20057, 4055, 16287, 6586, 20878, 2881, 14147, 10826, 1366, 12492, 9423, 5754, 19015, 5190, 1529, 11494, 11254, 2462, 17564, 1525, 7428, 2768, 5521, 1322, 2686, 5468, 7039, 6703, 8161, 2845, 4580, 4655, 7912, 18432, 15641, 2439, 5525, 12531, 6830, 2500, 17705, 8502, 14609, 14953, 7270, 20381, 2480, 8081, 4406, 9825, 614, 11456, 3205, 12253, 1006, 6148, 14624, 9392, 15383, 3455, 7646, 3495, 15036, 12560, 15401, 5530, 14191, 5112, 13298, 18397, 1247, 445, 3010, 21129, 18188, 898, 19995, 17804, 8407, 19490, 11212, 9407, 16542, 7417, 15514, 9560, 3698, 11269, 3705, 10485, 19178, 269, 5294, 16461, 15864, 7308, 8256, 5270, 10053, 12888, 14653, 7094, 11536, 19980, 16956, 18491, 19684, 437, 14977, 4431, 20664, 330, 839, 15703, 711, 13569, 4532, 4498, 14839, 11597, 13250, 18175, 12403, 4569, 12939, 17886, 5584, 20332, 1790, 7753, 9221, 7304, 17383, 14876, 4114, 410, 3785, 19666, 16075, 17030, 8527, 12057, 7902, 5506, 1588, 6732, 14416, 19361, 10265, 7677, 3301, 11665, 53, 17641, 8905, 21113, 3966, 7979, 5839, 16242, 4383, 19436, 4120, 9197, 14755, 12743, 20432, 17521, 3623, 2858, 10908, 3288, 6716, 176, 9539, 17556, 12079, 10943, 268, 19267, 10486, 6492, 8508, 20787, 1711, 6807, 7796, 6780, 8974, 5895, 1022, 7216, 10599, 5639, 14237, 18997, 1579, 13606, 13630, 13288, 8008, 15855, 16020, 16611, 9301, 2444, 10356, 558, 497, 173, 3318, 16568, 6659, 6878, 5825, 4773, 6243, 6744, 17188, 11853, 17836, 4518, 12168, 7348, 11172, 6839, 20696, 5709, 14911, 8590, 19525, 17313, 9999, 15176, 14169, 17980, 1849, 1289, 20260, 14834, 7758, 9897, 2561, 12795, 18979, 13539, 1383, 14858, 3567, 10694, 4824, 9335, 4413, 16184, 3141, 17258, 4098, 18330, 2799, 169, 18986, 9963, 3830, 9283, 6873, 10930, 17367, 4914, 10098, 2529, 17502, 3077, 6769, 16977, 9491, 9467, 6129, 7067, 8778, 2909, 9592, 13432, 89, 15042, 4563, 12509, 17998, 13395, 6066, 4650, 17059, 8307, 3281, 19779, 18253, 19411, 17974, 19704, 13648, 16465, 4103, 11177, 5165, 14227, 5683, 746, 8347, 30, 9209, 13686, 20524, 5086, 1602, 17363, 16353, 4287, 14355, 15407, 6176, 549, 18269, 17646, 15449, 4022, 4001, 11823, 2349, 16238, 14038, 17391, 6267, 16706, 17941, 18659, 16397, 8181, 18548, 11149, 18722, 10453, 19629, 5189, 19345, 5755, 733, 14872, 11807, 11384, 11303, 5474, 15749, 8786, 15375, 20500, 4752, 2716, 5126, 12184, 12821, 1578, 19162, 14238, 14392, 1217, 12834, 6490, 10488, 6823, 18163, 15579, 9962, 19097, 170, 14125, 15357, 12256, 9542, 13538, 19113, 12796, 16804, 12579, 1534, 6775, 18138, 4902, 15584, 1484, 8979, 6869, 4351, 13846, 16604, 4029, 3646, 15439, 20960, 18880, 15558, 11942, 9711, 1271, 18357, 7920, 18628, 18296, 38, 12862, 8217, 13091, 2568, 8797, 287, 2371, 8085, 1337, 9966, 17759, 16187, 5952, 8680, 20522, 13688, 14132, 20165, 12707, 15370, 18599, 10794, 1622, 8844, 16682, 10437, 9116, 8381, 17786, 3845, 15270, 521, 19944, 3410, 83, 20993, 11462, 2840, 15436, 14993, 4354, 1627, 17044, 3940, 881, 11554, 9147, 16011, 5752, 9425, 2218, 5012, 16429, 1691, 15331, 17302, 13585, 2861, 9389, 19373, 18698, 9296, 3035, 10629, 7728, 13812, 19783, 11743, 19892, 15557, 18960, 20961, 2305, 13165, 14306, 19896, 3572, 1495, 15820, 12953, 5210, 10495, 12651, 11325, 9679, 16255, 5999, 14718, 4213, 18097, 7199, 18153, 6464, 8203, 6050, 10478, 10589, 8624, 13205, 1109, 10022, 9451, 10775, 2877, 16781, 9674, 2732, 6247, 7675, 10267, 151, 3379, 10025, 21107, 2582, 16863, 5590, 19550, 19709, 4326, 17865, 2961, 16305, 20660, 8870, 5806, 6461, 16359, 16072, 3459, 13276, 3150, 14052, 14020, 1128, 8271, 14832, 20262, 17733, 5607, 1927, 15725, 11295, 619, 11947, 2097, 10894, 12923, 5569, 8571, 13480, 6343, 6219, 11331, 5798, 17229, 7421, 12654, 7761, 1056, 12215, 12331, 9994, 1909, 3686, 18315, 6908, 20274, 12296, 7313, 2489, 20310, 16147, 20070, 5923, 12055, 8529, 16887, 12950, 9162, 867, 1938, 13169, 8111, 780, 12614, 16056, 12715, 642, 13935, 2469, 940, 1426, 15900, 11605, 15231, 10403, 14793, 11995, 19359, 14418, 1931, 3545, 7392, 4782, 17148, 8902, 16812, 9641, 15129, 450, 13364, 7848, 21138, 7994, 7957, 7751, 1792, 9096, 8932, 16413, 12788, 14309, 6381, 20633, 9795, 1592, 10452, 19019, 11150, 2161, 3748, 11901, 14272, 16960, 6896, 8478, 15733, 20251, 14188, 5769, 18612, 1147, 5411, 1447, 18048, 17782, 18134, 10274, 19638, 10883, 9295, 18890, 19374, 16927, 1266, 8578, 14113, 15903, 11202, 7219, 11351, 2134, 8455, 15816, 18131, 11246, 15549, 8157, 2302, 12453, 19536, 14444, 15240, 21058, 13717, 9700, 6536, 1065, 12830, 11119, 20177, 141, 2413, 4387, 18624, 6061, 13004, 12810, 18086, 16396, 19024, 17942, 15926, 9190, 13349, 4465, 18194, 16280, 13083, 827, 18166, 13215, 6438, 1332, 20595, 16589, 262, 1705, 164, 20083, 9293, 10885, 652, 4662, 8921, 17062, 21183, 334, 12025, 11501, 18295, 18953, 7921, 15211, 6060, 18665, 4388, 14136, 12602, 13721, 7808, 9752, 10144, 5563, 13469, 4736, 1146, 18709, 5770, 5647, 16369, 7864, 15713, 958, 10315, 19906, 1222, 20710, 9577, 10793, 18930, 15371, 20703, 7540, 2772, 19831, 12141, 9, 9445, 17499, 9350, 18029, 16066, 1302, 9320, 328, 20666, 15215, 7163, 20810, 6274, 6582, 16507, 1154, 6980, 16266, 4306, 8711, 18105, 12005, 12175, 8698, 14060, 611, 20171, 19926, 1916, 15782, 7766, 8103, 18522, 12220, 14821, 17278, 13808, 419, 17243, 10790, 16017, 10593, 11148, 19021, 8182, 1786, 2988, 9438, 5083, 7154, 16209, 17019, 14299, 18402, 16671, 20065, 18319, 16496, 2247, 16124, 6953, 19880, 14348, 5758, 10441, 6347, 12860, 40, 12219, 18559, 8104, 15835, 14202, 11574, 2405, 15003, 15876, 7174, 11514, 19889, 11001, 14101, 3228, 443, 1249, 13662, 946, 13141, 597, 13704, 6413, 13493, 17569, 10949, 16027, 5444, 18076, 4900, 18140, 19683, 19252, 16957, 1572, 3827, 1340, 3855, 4538, 11693, 14117, 13820, 1913, 15729, 11411, 13708, 2654, 1419, 1679, 698, 13913, 10724, 1799, 9722, 14367, 10678, 5265, 6592, 3093, 4893, 4670, 9206, 8913, 11318, 3612, 21149, 6723, 1835, 15147, 8769, 3399, 13079, 2918, 2150, 21081, 130, 11933, 5908, 4875, 15618, 3652, 13517, 9614, 3580, 14501, 5498, 12465, 18203, 17766, 20425, 15640, 19324, 7913, 7684, 4169, 13691, 15313, 3758, 5277, 4282, 8214, 16549, 13131, 14644, 6843, 19799, 9525, 16694, 16, 19921, 15080, 1387, 19855, 9786, 2336, 5814, 4391, 6094, 13087, 1921, 16670, 18538, 14300, 20778, 16311, 1246, 19288, 13299, 18001, 4237, 20221, 17625, 2061, 10342, 7663, 2356, 11861, 8724, 6361, 8436, 1017, 10239, 17298, 8928, 19952, 14637, 7964, 17586, 15132, 10728, 10473, 2402, 4469, 13799, 370, 1897, 7103, 13367, 10186, 5077, 9958, 5206, 10952, 17724, 15791, 7919, 18955, 1272, 6934, 12225, 1667, 15386, 12139, 19833, 8041, 14046, 9969, 3508, 8330, 20670, 7293, 16576, 12470, 2171, 11658, 20715, 5154, 4211, 14720, 12564, 4316, 8169, 2798, 19100, 4099, 12349, 7464, 13344, 11057, 3874, 9386, 12527, 6476, 16495, 18535, 20066, 15456, 6907, 18785, 3687, 6024, 19750, 17573, 20156, 16614, 12265, 13554, 18222, 297, 932, 3262, 7004, 4161, 13702, 599, 10927, 37, 18952, 18629, 11502, 20076, 1762, 5778, 13354, 3383, 2420, 4945, 8243, 8441, 13456, 11445, 1140, 7513, 6136, 7007, 21155, 8547, 8730, 7262, 17583, 10121, 3892, 7552, 17645, 19037, 550, 9003, 10596, 11205, 13850, 1510, 19462, 2704, 11812, 16592, 13339, 6238, 20687, 647, 19410, 19063, 19780, 7374, 3013, 4769, 17119, 10713, 6293, 14385, 16106, 14934, 10469, 9766, 20803, 1964, 121, 13874, 2999, 16481, 8129, 14814, 14323, 20086, 12117, 15843, 11518, 17211, 20791, 13095, 4842, 296, 18306, 13555, 17915, 12073, 5169, 709, 15705, 11952, 2361, 10621, 17000, 19478, 11184, 7356, 5152, 20717, 13111, 6690, 17765, 18436, 12466, 16325, 956, 15715, 17535, 3671, 6357, 16279, 18653, 4466, 11577, 19990, 15502, 897, 19283, 21130, 910, 7777, 4335, 8888, 11761, 6222, 7238, 21158, 6209, 14364, 12402, 19236, 13251, 3746, 2163, 14481, 20040, 11180, 9776, 13214, 18649, 828, 15578, 18989, 6824, 11681, 20154, 17575, 8988, 14656, 2784, 16357, 6463, 18859, 7200, 3493, 7648, 4622, 6286, 11964, 14378, 16900, 6141, 12845, 17342, 19682, 18493, 4901, 18973, 6776, 3285, 10273, 18703, 17783, 11245, 18685, 15817, 1125, 18095, 4215, 10502, 4811, 3354, 11335, 10842, 8705, 9626, 12665, 19870, 9800, 9071, 4443, 8672, 8859, 875, 8088, 3488, 5064, 2146, 3992, 12004, 18571, 8712, 7277, 6005, 14537, 7972, 2430, 7198, 18861, 4214, 18128, 1126, 14022, 11668, 15238, 14446, 17347, 1729, 16395, 18661, 12811, 20234, 820, 12517, 13989, 17177, 11419, 16201, 4899, 18495, 5445, 11642, 13666, 17883, 17971, 6105, 20720, 5727, 1230, 1263, 4460, 16023, 12956, 17200, 21228, 16776, 11987, 5043, 1346, 7942, 3215, 154, 16972, 832, 6514, 20763, 17781, 18705, 1448, 11726, 9792, 1944, 8997, 5495, 16988, 16380, 15779, 14212, 12421, 13158, 13306, 3194, 21096, 17872, 15218, 16065, 18588, 9351, 15021, 5138, 858, 13399, 113, 7147, 2740, 20807, 4686, 4849, 6189, 4846, 7723, 7287, 13117, 13218, 17441, 9509, 16197, 15851, 5298, 1161, 9134, 16827, 276, 4236, 18395, 13300, 13394, 19071, 12510, 11794, 13371, 12727, 9022, 19584, 973, 8955, 20746, 20316, 2946, 14246, 1134, 15422, 16478, 4132, 1848, 19122, 14170, 17265, 7328, 5566, 19703, 19061, 19412, 6104, 18071, 17884, 12941, 2184, 1471, 6054, 14472, 3113, 10977, 10340, 2063, 14534, 14058, 8700, 9485, 9921, 743, 7580, 10718, 15066, 14185, 4530, 13571, 2042, 9585, 15592, 3391, 11274, 15925, 18658, 19025, 16707, 17023, 12884, 17494, 17354, 777, 11022, 14531, 21075, 2102, 4682, 8656, 17005, 9764, 10471, 10730, 800, 10174, 11110, 17908, 19620, 4207, 4512, 7381, 12072, 18220, 13556, 3900, 19522, 10373, 19383, 19619, 17921, 11111, 7433, 1234, 16273, 6969, 10688, 15649, 10542, 5216, 11208, 3837, 16437, 3125, 9915, 15941, 12011, 14672, 20900, 798, 10732, 5583, 19232, 12940, 17970, 18072, 13667, 10533, 3641, 1811, 17131, 8762, 8123, 10993, 7161, 15217, 18032, 21097, 2410, 11225, 11800, 7894, 2960, 18830, 4327, 9366, 3584, 4549, 14682, 5656, 3304, 9976, 8025, 19814, 20478, 8650, 9417, 12479, 2796, 8171, 8856, 14932, 16108, 4153, 16885, 8531, 21117, 9318, 1304, 2332, 21167, 4517, 19137, 11854, 17433, 16252, 17174, 8072, 231, 4233, 11662, 5659, 7222, 9231, 9340, 4604, 16851, 10640, 16742, 10293, 10513, 10962, 12587, 12998, 4561, 15044, 4311, 21180, 7930, 9602, 106, 19445, 15106, 8406, 19280, 19996, 9564, 8575, 4296, 1461, 15810, 17517, 19580, 5865, 1951, 13604, 1581, 5176, 2428, 7974, 8334, 3844, 18922, 8382, 11244, 18133, 18704, 18049, 20764, 12759, 4330, 16504, 12442, 9092, 15554, 12792, 5435, 19482, 11101, 15153, 8164, 20424, 18435, 18204, 6691, 13304, 13160, 3139, 16186, 18940, 9967, 14048, 3098, 13602, 1953, 6214, 785, 12669, 7138, 8399, 8603, 14724, 12930, 5939, 10291, 16744, 11279, 2903, 12920, 20037, 11363, 10331, 8864, 7670, 5606, 18812, 20263, 14361, 14828, 3835, 11210, 19492, 1479, 15790, 18360, 10953, 20314, 20748, 10221, 11061, 16174, 9057, 8886, 4337, 13342, 7466, 10967, 19548, 5592, 14710, 9106, 21242, 8501, 19317, 2501, 13858, 13189, 19427, 6738, 20344, 402, 5763, 5558, 14066, 8831, 1537, 15996, 11631, 16620, 8341, 20872, 9464, 341, 812, 10547, 6390, 2140, 10556, 17157, 4454, 1352, 2375, 19755, 6453, 756, 1885, 11082, 10081, 11634, 2809, 6749, 5335, 11882, 3387, 16701, 11392, 10743, 19471, 11116, 7034, 14069, 14142, 10938, 12230, 15886, 14670, 12013, 13764, 16388, 4777, 14266, 15448, 19036, 18270, 7553, 16810, 8904, 19204, 54, 5117, 9930, 2790, 101, 14938, 16386, 13766, 15049, 12936, 8804, 183, 12309, 3727, 2060, 18392, 20222, 11237, 12816, 4828, 7831, 13104, 3788, 7333, 5342, 12996, 12589, 1737, 11390, 16703, 6291, 10715, 3369, 19439, 8851, 6469, 17219, 2286, 5811, 6258, 14917, 11035, 5630, 2806, 7733, 10767, 4740, 20097, 4935, 1285, 13610, 11481, 448, 15131, 18376, 7965, 10120, 18274, 7263, 198, 1397, 3713, 3052, 14893, 8987, 18159, 20155, 18311, 19751, 20127, 10948, 18499, 13494, 12030, 6966, 1524, 19339, 2463, 2935, 15226, 15677, 12960, 6663, 12078, 19182, 9540, 12258, 14158, 11688, 1978, 9981, 15280, 10435, 16684, 8742, 9979, 1980, 10765, 7735, 5916, 3949, 12323, 4909, 19851, 3670, 18198, 15716, 15483, 6685, 14743, 16522, 4800, 15862, 16463, 13650, 14685, 737, 8939, 3622, 19190, 20433, 14593, 19579, 17797, 15811, 20565, 20844, 951, 9743, 5914, 7737, 359, 8051, 14018, 14054, 194, 7997, 3076, 19087, 2530, 9349, 18590, 9446, 5722, 15319, 17353, 17937, 12885, 5935, 2823, 15973, 13510, 20892, 4012, 14465, 15613, 3958, 19397, 20870, 8343, 12412, 1089, 15708, 12250, 15756, 15352, 20229, 13464, 7209, 3860, 9376, 8339, 16622, 16848, 10029, 20838, 2028, 1584, 8144, 3631, 13917, 19762, 21063, 14898, 1441, 15764, 7074, 852, 16037, 10756, 11307, 13804, 16870, 19817, 4712, 16555, 13501, 1464, 9508, 18011, 13219, 17070, 765, 7862, 16371, 965, 16251, 17834, 11855, 5868, 19406, 13932, 763, 17072, 14338, 14262, 12008, 19676, 2761, 19910, 11285, 2154, 11967, 5719, 13358, 6420, 3520, 10040, 3352, 4813, 4081, 9061, 1423, 5422, 12914, 3462, 2328, 5980, 14580, 15366, 19840, 19603, 7821, 7030, 1220, 19908, 2763, 16712, 6266, 19028, 14039, 3778, 11874, 6467, 8853, 21237, 14875, 19225, 7305, 7413, 7477, 13730, 14259, 978, 10191, 2925, 11864, 5029, 4041, 13888, 12827, 1458, 4913, 19091, 10931, 5046, 16352, 19044, 1603, 10261, 6127, 9469, 11127, 2977, 13698, 776, 17936, 17495, 15320, 7634, 7692, 3336, 1728, 18089, 14447, 15053, 1748, 19681, 18142, 12846, 16904, 1137, 7701, 20482, 13389, 11534, 7096, 7257, 13180, 13258, 17273, 14753, 9199, 11375, 624, 15767, 223, 1717, 12129, 14750, 10565, 1818, 19718, 9757, 11073, 10141, 9998, 19126, 19526, 8965, 4204, 2342, 20369, 14207, 16230, 20402, 4704, 13584, 18895, 15332, 3709, 8927, 18381, 10240, 15404, 14180, 12473, 11938, 5635, 3765, 1853, 5781, 5243, 12982, 20213, 639, 135, 2048, 13271, 20932, 8231, 13807, 18556, 14822, 14278, 10563, 14752, 17330, 13259, 20858, 5027, 11866, 17068, 13221, 7327, 17978, 14171, 13421, 16392, 4584, 20614, 4097, 19102, 3142, 9246, 15033, 20466, 13414, 219, 5338, 7489, 17226, 2216, 9427, 20956, 15919, 10789, 18553, 420, 20389, 7852, 15185, 356, 3762, 6785, 14651, 12890, 14776, 12873, 15086, 7420, 18795, 5799, 2215, 17249, 7490, 9088, 7481, 6202, 4644, 2285, 17604, 6470, 14691, 19567, 217, 13416, 8147, 20790, 18227, 11519, 16219, 3877, 7362, 4611, 19498, 14276, 14824, 8692, 21227, 18062, 12957, 12681, 5377, 10829, 1191, 1893, 4963, 20457, 6914, 8038, 11852, 19139, 6745, 4264, 16301, 6029, 5186, 14575, 20386, 13377, 20188, 11418, 18080, 13990, 8071, 17832, 16253, 9681, 20336, 5133, 16435, 3839, 12189, 1651, 11314, 5833, 6799, 27, 10232, 8821, 12373, 4453, 17680, 10557, 19971, 12607, 634, 3990, 2148, 2920, 8901, 18745, 4783, 2192, 10073, 20342, 6740, 12684, 9401, 4599, 13409, 7378, 4146, 6372, 2026, 20840, 7937, 8761, 17878, 1812, 2054, 12053, 5925, 16078, 20542, 12268, 14382, 13982, 6632, 10712, 18248, 4770, 3267, 19402, 13326, 6040, 4867, 5472, 11305, 10758, 10586, 9634, 7410, 15867, 16735, 13870, 4112, 14878, 10417, 10394, 16296, 856, 5140, 3404, 4365, 14522, 9139, 14014, 21202, 15111, 14244, 2948, 7548, 11135, 542, 14232, 1159, 5300, 13564, 2820, 7559, 7119, 7535, 9499, 4395, 790, 14337, 17427, 764, 17439, 13220, 17268, 11867, 14628, 20928, 7928, 21182, 18634, 8922, 8306, 19067, 4651, 20011, 11846, 16652, 15802, 9609, 10903, 8516, 249, 6999, 87, 13434, 12283, 3939, 18908, 1628, 3330, 16738, 14063, 16094, 2913, 6530, 2387, 3153, 3122, 10748, 13996, 8526, 19218, 16076, 5927, 13617, 19542, 21087, 12883, 17939, 16708, 5123, 14298, 18540, 16210, 21017, 3420, 9588, 20972, 3247, 2855, 1029, 7456, 11033, 14919, 20742, 9763, 17928, 8657, 20282, 5000, 19477, 18212, 10622, 7085, 13281, 19614, 8264, 925, 760, 645, 20689, 20754, 16379, 18041, 5496, 14503, 4063, 4949, 6811, 1281, 10866, 6398, 12359, 9490, 19084, 6770, 5943, 692, 831, 18053, 155, 1784, 8184, 15971, 2825, 13036, 10751, 4668, 4895, 2207, 6895, 18716, 14273, 1571, 18490, 19253, 19981, 12673, 3449, 19789, 16338, 1400, 20991, 85, 7001, 20117, 9911, 4982, 2676, 12539, 9813, 4642, 6204, 3437, 70, 16089, 10090, 8684, 2916, 13081, 16282, 15673, 4458, 1265, 18696, 19375, 15994, 1539, 2418, 3385, 11884, 8489, 3471, 4746, 678, 4734, 13471, 3065, 12362, 3534, 7908, 15013, 9344, 1455, 1068, 15420, 1136, 17340, 12847, 45, 6140, 18145, 14379, 2282, 7404, 6255, 2339, 19623, 5353, 6698, 8018, 13657, 11051, 12949, 18773, 8530, 17844, 4154, 6728, 1641, 9143, 9890, 14746, 9127, 1294, 9706, 12206, 19611, 11132, 20476, 19816, 17448, 13805, 8233, 5006, 2052, 1814, 5589, 18835, 2583, 2626, 7114, 15434, 2842, 15156, 10997, 11749, 4174, 20460, 10639, 17822, 4605, 10028, 17467, 16623, 20886, 14304, 13167, 1940, 11425, 20520, 8682, 10092, 8177, 11913, 2144, 5066, 7178, 7109, 7704, 10016, 13712, 11752, 275, 18004, 9135, 15104, 19447, 7285, 7725, 4906, 12635, 6271, 2001, 586, 5912, 9745, 1175, 9640, 18743, 8903, 17643, 7554, 8696, 12177, 3134, 12578, 18977, 12797, 8971, 10603, 9330, 14925, 8199, 8875, 4091, 3570, 19898, 21186, 5575, 4320, 19985, 3184, 5227, 4640, 9815, 7899, 2595, 3056, 9673, 18846, 2878, 7451, 367, 11986, 18060, 21229, 5904, 1150, 16316, 6517, 5652, 12975, 13361, 20826, 7875, 5622, 15017, 8893, 7688, 9462, 20874, 4559, 13000, 5858, 11982, 7345, 13187, 13860, 16716, 2009, 6411, 13706, 11413, 5963, 20205, 11278, 17743, 10292, 17820, 10641, 609, 14062, 17041, 3331, 13869, 17105, 15868, 81, 3412, 2113, 9082, 1656, 7790, 12502, 15605, 7658, 9549, 5598, 10709, 996, 7063, 3299, 7679, 2008, 16752, 13861, 15395, 6265, 17393, 2764, 9557, 5122, 17022, 17940, 19026, 6268, 6290, 17611, 11391, 17664, 3388, 6568, 19693, 15739, 13075, 15, 18416, 9526, 11366, 374, 4490, 8250, 3435, 6206, 2176, 8741, 17547, 10436, 18926, 8845, 2015, 8311, 12447, 8735, 7720, 4689, 21104, 4608, 20064, 18537, 18403, 1922, 16595, 19518, 4856, 3988, 636, 13866, 9179, 10335, 14584, 9173, 19938, 1755, 19772, 607, 10643, 15801, 17055, 11847, 4109, 7841, 6546, 11398, 11908, 3426, 4399, 11222, 144, 4576, 1186, 13886, 4043, 1752, 669, 7656, 15607, 6847, 8880, 6278, 8094, 10636, 13600, 3100, 14964, 12433, 20885, 16847, 17468, 8340, 17690, 11632, 10083, 12306, 6354, 12264, 18309, 20157, 9300, 19154, 16021, 4462, 11435, 4309, 15046, 4028, 18965, 13847, 5219, 5099, 15182, 2181, 4191, 1239, 19517, 16668, 1923, 13338, 18259, 11813, 261, 18644, 20596, 2613, 12329, 12217, 42, 12649, 10497, 4285, 16355, 2786, 12044, 12469, 18342, 7294, 7497, 6441, 12801, 10545, 814, 6658, 19146, 3319, 12594, 14084, 441, 3230, 16401, 13528, 4574, 146, 8006, 13290, 13500, 17445, 4713, 13247, 11733, 14422, 13130, 18422, 8215, 12864, 846, 3945, 7666, 7416, 19275, 9408, 6793, 565, 1431, 3803, 4695, 8003, 9687, 12605, 19973, 519, 15272, 11086, 1518, 8498, 5315, 9808, 14488, 4799, 17530, 14744, 9892, 7612, 5872, 751, 20570, 4333, 7779, 2635, 20104, 9631, 10481, 3655, 1153, 18577, 6583, 12441, 17777, 4331, 20572, 12341, 12410, 8345, 748, 2246, 18534, 18320, 6477, 10801, 13229, 7594, 5248, 11917, 6326, 14844, 5663, 19767, 4840, 13097, 8128, 18235, 3000, 4131, 17983, 15423, 2107, 15007, 9049, 4860, 3600, 6984, 9077, 11467, 13856, 2503, 4102, 19058, 13649, 17527, 15863, 19264, 5295, 10467, 14936, 103, 6603, 14408, 555, 15430, 15635, 6760, 4726, 3720, 5388, 21040, 1439, 14900, 8391, 6112, 15461, 14092, 11990, 10746, 3124, 17896, 3838, 17169, 5134, 9475, 76, 6432, 1690, 18898, 5013, 9212, 10554, 2142, 11915, 5250, 8432, 3628, 13419, 14173, 20399, 10851, 9855, 10508, 12787, 18730, 8933, 15788, 1481, 4765, 8153, 3025, 20954, 9429, 15059, 3233, 13527, 16562, 3231, 15061, 8180, 19023, 18660, 18087, 1730, 4583, 17262, 13422, 12199, 4776, 17650, 13765, 17634, 14939, 11188, 15208, 4136, 15778, 18040, 16989, 20755, 7473, 8867, 15340, 2804, 5632, 964, 17436, 7863, 18609, 5648, 8485, 310, 893, 5974, 9274, 1049, 20135, 16071, 18823, 6462, 18155, 2785, 16580, 4286, 19043, 17364, 5047, 3172, 2755, 3110, 2277, 5666, 10618, 13523, 4428, 8615, 8925, 3711, 1399, 16951, 19790, 3881, 2159, 11152, 13108, 6108, 11923, 6166, 10212, 15621, 19508, 955, 18201, 12467, 12046, 9158, 9665, 14078, 13976, 20761, 6516, 16772, 1151, 3657, 19965, 1245, 18399, 20779, 229, 8074, 12136, 20659, 18828, 2962, 13007, 6028, 17185, 4265, 14439, 8444, 855, 17099, 10395, 15205, 8607, 434, 6709, 11593, 12439, 6585, 19355, 4056, 793, 11014, 15672, 16931, 13082, 18652, 18195, 6358, 266, 10945, 1522, 6968, 17904, 1235, 10204, 11094, 10840, 11337, 4305, 18574, 6981, 5803, 12242, 7616, 14640, 5202, 7407, 7397, 19741, 5998, 18865, 9680, 17173, 17833, 17434, 966, 4247, 1773, 16120, 14320, 19562, 13015, 4382, 19198, 5840, 15075, 14037, 19030, 2350, 4821, 12038, 7565, 13927, 10849, 20401, 17306, 14208, 14548, 6450, 21193, 16134, 14621, 390, 3979, 9384, 3876, 17209, 11520, 20775, 15172, 1373, 15090, 10327, 8207, 21016, 17018, 18541, 7155, 9261, 3191, 19904, 10317, 3884, 4898, 18078, 11420, 16194, 15850, 18009, 9510, 15849, 16199, 11421, 1081, 15097, 12498, 5318, 5951, 18939, 17760, 3140, 19104, 4414, 14072, 1607, 14863, 14596, 7867, 1744, 10126, 9056, 17718, 11062, 2885, 11292, 19930, 9472, 574, 11810, 2706, 14096, 724, 2203, 19648, 20279, 19515, 1241, 19691, 6570, 15761, 11098, 20443, 7745, 5442, 16029, 4648, 6068, 20069, 18778, 20311, 10739, 8464, 8916, 11257, 8588, 14913, 6996, 7057, 1959, 7952, 14620, 16225, 21194, 3610, 11320, 5676, 5733, 11691, 4540, 4228, 6952, 18532, 2248, 9066, 14319, 16247, 1774, 7775, 912, 4079, 4815, 11775, 20677, 6227, 3223, 20392, 4152, 17846, 14933, 18244, 14386, 21153, 7009, 6859, 19378, 15474, 10804, 13892, 3041, 533, 2912, 17039, 14064, 5560, 5287, 10089, 16936, 71, 1199, 1207, 10071, 2194, 7023, 19936, 9175, 3031, 20541, 17126, 5926, 17029, 19219, 19667, 3458, 18822, 16360, 20136, 12165, 19595, 1301, 18587, 18030, 15219, 4066, 6675, 1619, 2233, 1905, 19721, 12714, 18764, 12615, 6542, 6962, 414, 9907, 19707, 19552, 6608, 4989, 13843, 14996, 11290, 2887, 10298, 5224, 8295, 2379, 10755, 17452, 853, 8446, 10706, 3350, 10042, 7401, 4647, 16151, 5443, 18497, 10950, 5208, 12955, 18064, 4461, 16610, 19155, 15856, 10592, 18551, 10791, 9579, 6013, 6645, 5751, 18903, 9148, 74, 9477, 15467, 3961, 8268, 7606, 12972, 13654, 4759, 9333, 4826, 12818, 11630, 17692, 1538, 16925, 19376, 6861, 98, 14528, 14602, 15500, 19992, 15696, 10570, 2782, 14658, 6735, 12583, 12992, 1989, 11197, 10820, 9355, 7129, 13509, 17490, 2824, 16968, 8185, 13625, 14556, 7947, 7857, 15151, 11103, 15688, 5158, 11161, 20577, 13543, 11235, 20224, 20979, 1984, 4789, 10783, 5397, 3242, 20089, 4167, 7686, 8895, 10352, 1215, 14394, 19674, 12010, 17893, 9916, 15453, 6071, 7082, 5, 12750, 4723, 11442, 8750, 5060, 15299, 8793, 9015, 9189, 18657, 17943, 11275, 14433, 15284, 1046, 10788, 17245, 20957, 12970, 7608, 14499, 3582, 9368, 21029, 3998, 13761, 10722, 13915, 3633, 8254, 7310, 11201, 18692, 14114, 11604, 18757, 1427, 12777, 1625, 4356, 14552, 9053, 7984, 6003, 7279, 6088, 12367, 14973, 14669, 17654, 12231, 306, 19652, 10086, 674, 20587, 10207, 11582, 7173, 18515, 15004, 14507, 8567, 4052, 10421, 19885, 80, 16734, 17106, 7411, 7307, 19263, 16462, 17528, 4801, 210, 19529, 8622, 10591, 16019, 19156, 8009, 10465, 5297, 18008, 16198, 16195, 9511, 11547, 14715, 12691, 11517, 18229, 12118, 9314, 15343, 20101, 2542, 19803, 14201, 18520, 8105, 20785, 8510, 10246, 7150, 20307, 19825, 3842, 8336, 9216, 10033, 9663, 9160, 12952, 18872, 1496, 1124, 18130, 18686, 8456, 3477, 1768, 20564, 17516, 17798, 1462, 13503, 5097, 5221, 2753, 3174, 9608, 17054, 16653, 10644, 11921, 6110, 8393, 9280, 15532, 14676, 20321, 7918, 18359, 17725, 1480, 16411, 8934, 1203, 5901, 7502, 7765, 18562, 1917, 14211, 18039, 16381, 4137, 9945, 2241, 5501, 10836, 7051, 21023, 12238, 11879, 222, 17325, 625, 7073, 17455, 1442, 11097, 16156, 6571, 930, 299, 15351, 17476, 12251, 3207, 4262, 6747, 2811, 8785, 19007, 5475, 10414, 8014, 11055, 13346, 2035, 19662, 11155, 13074, 16697, 19694, 13437, 9842, 872, 20250, 18713, 8479, 7299, 11410, 18480, 1914, 19928, 11294, 18809, 1928, 8719, 12893, 11007, 5847, 1957, 7059, 15482, 17534, 18199, 957, 18607, 7865, 14598, 5706, 12249, 17478, 1090, 11951, 18216, 710, 19244, 840, 20819, 10973, 1613, 6957, 10569, 15986, 19993, 900, 6683, 15485, 3553, 7184, 5157, 15963, 11104, 2633, 7781, 13920, 3273, 1547, 8325, 2447, 12679, 12959, 17560, 15227, 62, 4457, 16930, 16283, 11015, 12430, 12622, 10575, 10516, 3362, 2018, 918, 6552, 7574, 19434, 4385, 2415, 1700, 3539, 6540, 12617, 12083, 13053, 11699, 4526, 10541, 17901, 10689, 6814, 5967, 10816, 13578, 3515, 2438, 19323, 18433, 20426, 12450, 20964, 6759, 16452, 15431, 1087, 12414, 10581, 7251, 12725, 13373, 4484, 6233, 11401, 9102, 13380, 19507, 16328, 10213, 3651, 18444, 4876, 20286, 9310, 3957, 17485, 14466, 10649, 2085, 7013, 6846, 16634, 7657, 16726, 12503, 15478, 2639, 4881, 12765, 20996, 14731, 4479, 8275, 7597, 6566, 3390, 17946, 9586, 3422, 14028, 9900, 6404, 4763, 1483, 18971, 4903, 10632, 6251, 9961, 18988, 18164, 829, 694, 20851, 9928, 5119, 15517, 510, 11792, 12512, 13531, 7021, 2196, 20504, 13671, 6960, 6544, 7843, 961, 11941, 18959, 18881, 19893, 12791, 17774, 9093, 21013, 456, 8156, 18683, 11247, 888, 20268, 10224, 6650, 5539, 9001, 552, 2119, 6339, 10111, 1225, 8813, 7454, 1031, 14675, 15795, 9281, 3832, 7892, 11802, 3752, 5931, 5852, 14986, 528, 3181, 20020, 14842, 6328, 509, 15572, 5120, 9559, 19273, 7418, 15088, 1375, 20600, 1841, 7319, 15234, 14606, 20238, 19417, 896, 18190, 19991, 15988, 14603, 5237, 2347, 11825, 1903, 2235, 20517, 6900, 2721, 10809, 8077, 949, 20846, 3552, 15692, 6684, 17533, 15717, 7060, 2539, 2638, 15603, 12504, 13227, 10803, 16100, 19379, 19486, 2958, 7896, 19395, 3960, 16007, 9478, 19422, 11260, 1404, 14091, 16442, 6113, 6512, 834, 6906, 18317, 20067, 6070, 15939, 9917, 2453, 4021, 19035, 17647, 14267, 4985, 9008, 12378, 2424, 14789, 12968, 20959, 18962, 3647, 14992, 18912, 2841, 16859, 7115, 1086, 15634, 16453, 556, 10358, 15167, 13201, 14370, 2106, 16477, 17984, 1135, 16906, 1069, 12782, 9934, 4085, 14451, 12023, 336, 20174, 13269, 2050, 5008, 6175, 19040, 14356, 14179, 17296, 10241, 5529, 19293, 12561, 11193, 15317, 5724, 6264, 16714, 13862, 353, 8248, 4492, 9268, 12095, 20657, 12138, 18352, 1668, 3454, 19299, 9393, 3818, 1844, 11144, 13636, 4731, 20499, 19005, 8787, 15071, 20702, 18598, 18931, 12708, 6133, 19839, 17401, 14581, 19735, 9684, 149, 10269, 11090, 1004, 12255, 18983, 14126, 12274, 2081, 20228, 17475, 15757, 300, 20045, 5464, 13748, 19, 4475, 20100, 15840, 9315, 2803, 16375, 8868, 20662, 4433, 11505, 3738, 13513, 3708, 17301, 18896, 1692, 12597, 11834, 1178, 2473, 9195, 4122, 5172, 4221, 7633, 17352, 17496, 5723, 15398, 11194, 8363, 3757, 18427, 13692, 8318, 3504, 10959, 10578, 14478, 4274, 20558, 14989, 6334, 14255, 394, 8792, 15930, 5061, 2311, 12570, 19699, 14400, 12371, 8823, 9649, 9519, 12352, 10899, 9835, 4502, 1045, 15922, 14434, 5603, 10434, 17549, 9982, 11379, 1830, 20355, 4885, 11976, 11085, 16530, 520, 18920, 3846, 6670, 8676, 13743, 7661, 10344, 12735, 324, 11478, 20329, 14699, 9532, 6562, 20514, 6379, 14311, 21007, 1507, 4993, 2385, 6532, 8560, 13264, 5357, 13971, 3147, 6713, 7193, 21057, 18677, 14445, 18091, 11669, 5235, 14605, 15507, 7320, 10402, 18755, 11606, 6122, 61, 15676, 17561, 2936, 1500, 8260, 8241, 4947, 4065, 16064, 18031, 17873, 7162, 18582, 20667, 6486, 6059, 18626, 7922, 4135, 16383, 11189, 8606, 16294, 10396, 11396, 6548, 11719, 13045, 2393, 10772, 1862, 19777, 3283, 6778, 7798, 8958, 14762, 6037, 2624, 2585, 8246, 355, 17239, 7853, 2180, 16600, 5100, 1181, 5795, 5311, 14168, 19124, 10000, 20363, 1372, 16216, 20776, 14302, 20888, 13200, 15427, 10359, 12212, 6556, 1684, 13969, 5359, 8883, 19601, 19842, 10996, 16857, 2843, 8163, 17769, 11102, 15965, 7858, 9717, 8768, 18455, 1836, 3277, 3179, 530, 8140, 4917, 9327, 5451, 12857, 4806, 5789, 14738, 20619, 10727, 18375, 17587, 449, 18741, 9642, 6020, 21189, 1101, 11079, 10987, 3889, 11781, 2168, 14183, 15068, 8540, 5881, 1411, 13735, 2969, 14243, 17090, 21203, 4348, 3105, 8405, 17806, 19446, 16825, 9136, 20242, 1947, 6626, 20861, 12497, 16191, 1082, 8544, 7241, 1475, 20644, 10326, 16214, 1374, 15512, 7419, 17231, 12874, 9325, 4919, 11038, 1386, 18413, 19922, 9495, 20976, 14036, 16240, 5841, 2210, 20701, 15373, 8788, 8539, 15118, 14184, 17952, 10719, 12016, 11911, 8179, 16399, 3232, 16404, 9430, 14947, 14224, 1315, 1747, 17345, 14448, 21224, 12935, 17632, 13767, 4027, 16606, 4310, 17813, 4562, 19074, 90, 3071, 6886, 6423, 12559, 19295, 3496, 20465, 17255, 9247, 14905, 2451, 9919, 9487, 3068, 14012, 9141, 1643, 571, 5137, 18027, 9352, 14849, 8892, 16764, 5623, 9849, 9343, 16910, 7909, 2992, 563, 6795, 9048, 16475, 2108, 14506, 15875, 18516, 2406, 13575, 12301, 10616, 5668, 11289, 16045, 13844, 4353, 18911, 15437, 3648, 6333, 15304, 20559, 527, 15524, 5853, 4536, 3857, 2222, 4544, 14960, 8613, 4430, 19249, 438, 2670, 14668, 15888, 12368, 4618, 13156, 12423, 11697, 13055, 12620, 12432, 16626, 3101, 9286, 8612, 14980, 4545, 3639, 10535, 3003, 6865, 7269, 19314, 14610, 14331, 11839, 14458, 14223, 15057, 9431, 8189, 12731, 21002, 19688, 10387, 11187, 16385, 17635, 102, 16458, 10468, 18243, 16107, 17847, 8857, 8674, 6672, 865, 9164, 8198, 16799, 9331, 4761, 6406, 5730, 20741, 17008, 11034, 17600, 6259, 5946, 6995, 16140, 8589, 19129, 5710, 11139, 8101, 7768, 2450, 15031, 9248, 10807, 2723, 8390, 16445, 1440, 17457, 21064, 8942, 4633, 8986, 17577, 3053, 4971, 20984, 12524, 2864, 12814, 11239, 6509, 632, 12609, 12854, 11971, 8012, 10416, 17102, 4113, 19224, 17384, 21238, 11806, 19012, 734, 5994, 6939, 2522, 617, 11297, 19577, 14595, 16180, 1608, 6754, 10701, 3566, 19110, 1384, 11040, 9669, 13881, 11387, 10382, 4269, 8891, 15019, 9353, 10822, 11348, 5662, 16487, 6327, 15520, 20021, 11596, 19239, 4499, 7544, 2748, 7757, 19118, 20261, 18814, 8272, 7890, 3834, 17730, 14362, 6211, 8691, 17203, 14277, 17277, 18557, 12221, 8554, 21172, 4818, 19560, 14322, 18233, 8130, 8033, 2602, 19918, 13751, 4676, 8449, 7511, 1142, 13193, 12947, 11053, 8016, 6700, 5022, 57, 1493, 3574, 20494, 11994, 18753, 10404, 14328, 12967, 15442, 2425, 4891, 3095, 2391, 13047, 9374, 3862, 12397, 3644, 4031, 6559, 12872, 17233, 12891, 8721, 2928, 4755, 10449, 8099, 11141, 7926, 20930, 13273, 12917, 581, 6036, 15191, 8959, 8414, 2257, 10762, 2073, 12742, 19193, 9198, 17329, 17274, 10564, 17321, 12130, 9536, 9126, 16879, 9891, 16521, 17531, 6686, 10009, 6364, 20618, 15135, 5790, 20416, 3198, 487, 4932, 4478, 15598, 20997, 14195, 20782, 20655, 12097, 12929, 17747, 8604, 11191, 12563, 18335, 4212, 18863, 6000, 12690, 15846, 11548, 2576, 20185, 9105, 17709, 5593, 8633, 5195, 14288, 5687, 13407, 4601, 9852, 6047, 9531, 15259, 20330, 5586, 13676, 20191, 9036, 6085, 19566, 17217, 6471, 8378, 11716, 5992, 736, 17525, 13651, 5655, 17860, 4550, 1557, 5092, 5489, 20320, 15794, 15533, 1032, 20899, 17891, 12012, 17653, 15887, 14974, 2671, 4743, 8809, 4961, 1895, 372, 11368, 14414, 6734, 15983, 2783, 18157, 8989, 7093, 19257, 12889, 17235, 6786, 719, 11645, 21145, 4793, 6842, 18420, 13132, 1696, 5201, 16261, 7617, 7963, 18378, 19953, 11545, 9513, 12534, 8354, 10244, 8512, 20927, 17066, 11868, 19371, 9391, 19301, 6149, 389, 16224, 16135, 7953, 7266, 4128, 10538, 20255, 11675, 7933, 12965, 14330, 14952, 19315, 8503, 20237, 15506, 15235, 5236, 15499, 15989, 14529, 11024, 5705, 15711, 7866, 16179, 14864, 19578, 17519, 20434, 4680, 2104, 14372, 12880, 8288, 3691, 9172, 16660, 10336, 19734, 15365, 17402, 5981, 12574, 6320, 20385, 17182, 5187, 19631, 9692, 14486, 9810, 8412, 8961, 20348, 5556, 5765, 3717, 6507, 11241, 20406, 8137, 3044, 3485, 7946, 15968, 13626, 7825, 9052, 15895, 4357, 13232, 6449, 16228, 14209, 1919, 13089, 8219, 245, 1563, 20814, 4958, 9657, 7971, 18101, 6006, 14057, 17960, 2064, 21074, 17933, 11023, 14601, 15990, 99, 2792, 19415, 20240, 9138, 17094, 4366, 19609, 12208, 19660, 2037, 6834, 6590, 5267, 8667, 1821, 3549, 906, 4106, 8566, 15874, 15005, 2109, 4062, 16986, 5497, 18439, 3581, 15915, 7609, 10881, 19640, 6388, 10549, 715, 11829, 284, 5613, 4798, 16524, 9809, 14571, 9693, 12104, 11361, 20039, 18171, 2164, 4273, 15307, 10579, 12416, 19714, 2275, 3112, 17965, 6055, 13452, 2079, 12276, 10648, 15612, 17486, 4013, 6599, 20531, 12495, 20863, 14222, 14949, 11840, 4709, 20685, 6240, 12202, 12022, 15415, 4086, 21223, 15052, 17346, 18090, 15239, 18678, 19537, 2077, 13454, 8443, 16299, 4266, 19969, 10559, 5602, 15283, 15923, 11276, 20207, 11790, 512, 10584, 10760, 2259, 3087, 9569, 13129, 16551, 11734, 8717, 1930, 18750, 19360, 19211, 6733, 14660, 11369, 116, 10076, 2117, 554, 16455, 6604, 2830, 1451, 14235, 5641, 4616, 12370, 15294, 19700, 12926, 20054, 8426, 19673, 15944, 1216, 18995, 14239, 5147, 1872, 5257, 21152, 16105, 18245, 6294, 13981, 17123, 12269, 2281, 16899, 18146, 11965, 2156, 10320, 21214, 12879, 14589, 2105, 15425, 13202, 10677, 18469, 9723, 12401, 18177, 6210, 14827, 17731, 20264, 1796, 20622, 14178, 15406, 19041, 4288, 2534, 12772, 9822, 731, 5757, 18529, 19881, 8759, 7939, 20414, 5792, 2933, 2465, 976, 14261, 17426, 17073, 791, 4058, 13212, 9778, 11838, 14951, 14611, 12966, 14791, 10405, 12546, 9291, 20085, 18232, 14815, 19561, 16246, 16121, 9067, 20546, 19976, 2894, 9025, 13028, 21006, 15254, 6380, 18728, 12789, 19895, 18876, 13166, 16845, 20887, 15170, 20777, 18401, 18539, 17020, 5124, 2718, 1370, 20365, 19635, 5551, 10681, 7577, 5686, 14706, 5196, 20836, 10031, 9218, 3683, 19726, 4975, 3346, 10562, 17276, 14823, 17204, 19499, 1570, 16959, 18717, 11902, 20094, 2674, 4984, 15447, 17648, 4778, 12173, 12007, 17425, 14339, 977, 17378, 13731, 7988, 393, 15302, 6335, 5110, 14193, 20999, 4200, 21163, 4302, 1133, 17986, 2947, 17089, 15112, 2970, 95, 5146, 14391, 18996, 19163, 5640, 14404, 1452, 1158, 17084, 543, 10019, 7717, 5682, 19054, 5166, 1314, 15056, 14948, 14459, 20864, 13427, 3852, 20030, 8417, 10132, 3590, 7181, 12420, 18038, 15780, 1918, 14547, 16229, 17307, 20370, 9184, 740, 11573, 18519, 15836, 19804, 10412, 5477, 227, 20781, 14729, 20998, 14252, 5111, 19291, 5531, 5768, 18711, 20252, 4529, 17951, 15067, 15119, 2169, 12472, 17295, 15405, 14357, 20623, 5484, 3795, 20398, 16419, 13420, 17264, 17979, 19123, 15177, 5312, 21245, 10626, 4251, 7969, 9659, 13660, 1251, 11687, 17553, 12259, 6595, 1993, 9714, 3915, 13993, 13039, 20796, 426, 10825, 19351, 2882, 7883, 13403, 10937, 17657, 14070, 4416, 13546, 769, 12601, 18622, 4389, 5816, 20164, 18934, 13689, 4171, 13715, 21060, 12273, 15356, 18984, 171, 499, 11030, 11893, 5274, 7741, 13819, 18483, 11694, 11603, 15902, 18693, 8579, 3499, 12851, 126, 11300, 13884, 1188, 10858, 9878, 21135, 3227, 18510, 11002, 5419, 943, 723, 16165, 2707, 5041, 11989, 16441, 15462, 1405, 10255, 3375, 6033, 2668, 440, 16565, 12595, 1694, 13134, 8351, 13975, 16320, 9666, 5372, 2735, 9736, 1606, 16182, 4415, 14141, 17658, 7035, 8830, 17695, 5559, 16093, 17040, 16739, 610, 18567, 8699, 17959, 14535, 6007, 193, 17506, 14019, 18818, 3151, 2389, 3097, 17757, 9968, 18348, 8042, 20142, 1098, 19759, 7784, 3777, 17390, 19029, 16239, 15076, 20977, 20226, 2083, 10651, 10046, 2559, 9899, 15589, 3423, 12019, 7805, 51, 11667, 18093, 1127, 18817, 14053, 17507, 8052, 7525, 21201, 17092, 9140, 15026, 3069, 92, 12704, 6155, 19775, 1864, 1632, 11654, 20682, 19820, 8474, 20735, 10667, 5619, 8525, 17032, 10749, 13038, 14152, 3916, 8070, 17176, 18081, 12518, 2974, 3667, 21052, 13295, 6631, 17122, 14383, 6295, 1936, 869, 20760, 16319, 14079, 8352, 12536, 3146, 15245, 5358, 15162, 1685, 8236, 9720, 1801, 4426, 13525, 3235, 8133, 8610, 9288, 11767, 578, 2906, 4674, 13753, 11890, 7459, 12769, 5518, 9840, 13439, 11499, 12027, 2023, 3867, 13837, 5384, 1987, 12994, 5344, 10049, 8952, 2468, 18761, 643, 762, 17429, 19407, 5741, 6016, 10848, 16233, 7566, 207, 19812, 8027, 3983, 3272, 15684, 7782, 19761, 17460, 3632, 15908, 10723, 18473, 699, 11431, 1857, 11066, 12150, 9940, 7447, 9266, 4494, 8063, 9080, 2115, 10078, 11979, 9156, 12048, 9876, 10860, 10064, 3040, 16098, 10805, 9250, 12826, 17371, 4042, 16639, 1187, 14107, 11301, 11386, 14854, 9670, 1261, 1232, 7435, 1468, 2998, 18237, 122, 7839, 4111, 17104, 16736, 3332, 9178, 16663, 637, 20215, 352, 15394, 16715, 16753, 13188, 17703, 2502, 16468, 11468, 11613, 13841, 4991, 1509, 18264, 11206, 5218, 16603, 18966, 4352, 14995, 16046, 4990, 13853, 11614, 4142, 5383, 13943, 3868, 13773, 13582, 4706, 1975, 5736, 6162, 4019, 2455, 8596, 9926, 20853, 12459, 12712, 19723, 1912, 18482, 14118, 7742, 10137, 3343, 20016, 7372, 19782, 18885, 7729, 13024, 418, 18555, 17279, 8232, 16869, 17449, 11308, 7343, 11984, 369, 18370, 4470, 20883, 12435, 5714, 20219, 4239, 10217, 9358, 7297, 8481, 9790, 11728, 8899, 2922, 7906, 3536, 10283, 314, 21046, 9727, 476, 493, 4872, 12383, 13581, 13835, 3869, 7520, 180, 12160, 4026, 15048, 17633, 16387, 17651, 12014, 10721, 15910, 3999, 4024, 12162, 13536, 9544, 20196, 11889, 13954, 4675, 14809, 19919, 18, 15347, 5465, 13485, 9547, 7660, 15266, 8677, 1552, 8969, 12799, 6443, 20108, 2968, 15114, 1412, 12687, 7987, 14258, 17379, 7478, 21070, 12126, 12630, 13196, 7233, 49, 7807, 18620, 12603, 9689, 9699, 18675, 21059, 14129, 4172, 11751, 16830, 10017, 545, 2653, 18478, 11412, 16749, 6412, 18502, 598, 18300, 4162, 10115, 775, 17356, 2978, 3605, 4440, 12554, 8317, 15312, 18428, 4170, 14131, 18935, 20523, 19048, 9210, 5015, 7323, 21043, 13021, 11638, 10348, 11416, 20190, 14696, 5587, 1816, 10567, 6959, 15564, 20505, 3295, 10532, 17882, 18073, 11643, 721, 945, 18506, 1250, 14161, 9660, 11050, 16890, 8019, 4758, 16002, 12973, 5654, 14684, 17526, 16464, 19059, 19705, 9909, 20119, 12980, 5245, 8278, 5333, 6751, 10369, 11356, 4730, 15378, 11145, 9006, 4987, 6610, 13287, 19159, 13607, 383, 7824, 14555, 15969, 8186, 11264, 483, 8492, 8126, 13099, 19541, 17027, 5928, 3898, 13558, 20210, 20327, 11480, 17590, 1286, 382, 13629, 19160, 1580, 17793, 1952, 17755, 3099, 16628, 10637, 20462, 8582, 1381, 13541, 20579, 4614, 5643, 4524, 11701, 7505, 5984, 10906, 2860, 18894, 17303, 4705, 13834, 13774, 12384, 3514, 15644, 10817, 12300, 15001, 2407, 10983, 2041, 17949, 4531, 19242, 712, 1882, 13335, 2819, 17081, 5301, 12355, 4487, 11788, 20209, 13614, 3899, 17914, 18221, 18307, 12266, 20544, 9069, 9802, 20111, 3911, 768, 14139, 4417, 11234, 15959, 20578, 13595, 1382, 19112, 18980, 9543, 13757, 12163, 20138, 11229, 7020, 15568, 12513, 4573, 16561, 16402, 3234, 13963, 4427, 16344, 10619, 2363, 7438, 8226, 9613, 18442, 3653, 10483, 3707, 15334, 3739, 20891, 17489, 15974, 7130, 7431, 11113, 805, 5096, 15808, 1463, 17444, 16556, 13291, 2515, 19458, 2021, 12029, 17568, 18500, 6414, 2132, 11353, 8594, 2457, 20194, 9546, 13746, 5466, 2688, 13147, 6342, 18800, 8572, 20146, 10172, 802, 19474, 5131, 20338, 3064, 16915, 4735, 18615, 5564, 7330, 1489, 7208, 17473, 20230, 11012, 795, 19592, 4521, 8748, 11444, 18284, 8442, 14441, 2078, 14470, 6056, 12292, 505, 11488, 11541, 9045, 9229, 7224, 21199, 7527, 2630, 11498, 13948, 9841, 15737, 19695, 12282, 17047, 88, 19076, 9593, 569, 1645, 3851, 14220, 20865, 7622, 6695, 12198, 16391, 17263, 14172, 16420, 3629, 8146, 17214, 218, 17253, 20467, 8637, 21126, 7377, 17139, 4600, 14704, 5688, 20289, 10936, 14144, 7884, 2511, 112, 18024, 859, 4009, 6065, 19070, 17999, 13301, 5283, 6099, 11533, 17336, 20483, 3812, 4879, 2641, 5537, 6652, 5071, 19506, 15623, 9103, 20187, 17180, 20387, 422, 4483, 15628, 12726, 17995, 11795, 19390, 10185, 18366, 7104, 7847, 18739, 451, 20825, 16768, 12976, 6419, 17416, 5720, 9448, 3382, 18290, 5779, 1855, 11433, 4464, 18655, 9191, 2034, 15744, 11056, 18326, 7465, 17714, 4338, 6237, 18258, 16593, 1924, 2818, 13566, 1883, 758, 927, 5457, 2891, 2295, 2622, 6039, 17115, 19403, 10107, 6481, 320, 4185, 68, 3439, 11648, 9573, 6636, 8285, 21090, 408, 4116, 12489, 6904, 836, 19902, 3193, 18035, 13159, 17763, 6692, 5282, 13393, 18000, 18396, 19289, 5113, 6630, 13984, 21053, 13254, 2514, 13499, 16557, 8007, 19158, 13631, 6611, 2872, 3664, 11130, 19613, 16997, 7086, 11591, 6711, 3149, 18820, 3460, 12916, 14766, 20931, 17282, 2049, 15411, 20175, 11121, 12195, 5356, 15247, 8561, 7517, 6992, 20857, 17272, 17331, 13181, 110, 2513, 13293, 21054, 3745, 18174, 19237, 11598, 11732, 16553, 4714, 11563, 21102, 4691, 7960, 2092, 5395, 10785, 9277, 6369, 10834, 5503, 10195, 6448, 14550, 4358, 7593, 16492, 10802, 15476, 12505, 11272, 3393, 1436, 7326, 17267, 17069, 17440, 18012, 13118, 6437, 18648, 18167, 9777, 14334, 4059, 9398, 1415, 2900, 7204, 1108, 18852, 8625, 10676, 14369, 15426, 15168, 20889, 3741, 7232, 13725, 12631, 12946, 14804, 1143, 11620, 19426, 17702, 13859, 16754, 7346, 12170, 9784, 19857, 109, 13257, 17332, 7258, 4074, 3418, 21019, 4941, 9114, 10439, 5760, 20301, 8110, 18768, 1939, 16844, 14305, 18877, 2306, 19913, 20373, 3138, 17762, 13305, 18036, 12422, 14970, 4619, 10614, 12303, 19655, 10799, 6479, 10109, 6341, 13482, 2689, 2728, 5415, 465, 596, 18504, 947, 8079, 2482, 20470, 10229, 8350, 14081, 1695, 14643, 18421, 16550, 14423, 9570, 12486, 3373, 10257, 12756, 7629, 8151, 4767, 3015, 6436, 13217, 18013, 7288, 12640, 20817, 842, 6689, 18206, 20718, 6107, 16333, 11153, 19664, 3787, 17619, 7832, 4036, 460, 19540, 13619, 8127, 16483, 4841, 18225, 20792, 5699, 2567, 18948, 8218, 14545, 1920, 18405, 6095, 3481, 826, 18651, 16281, 16932, 2917, 18452, 3400, 12394, 14, 16696, 15740, 11156, 4411, 9337, 6187, 4851, 2227, 2702, 19464, 4280, 5279, 7625, 9986, 11817, 6304, 8519, 10941, 12081, 12619, 14967, 11698, 15653, 12084, 6323, 4451, 12375, 9373, 14784, 2392, 15200, 11720, 10921, 5037, 234, 20795, 14151, 13994, 10750, 16966, 2826, 4701, 8386, 2300, 8159, 6705, 21005, 14313, 9026, 12697, 417, 13810, 7730, 11637, 13681, 21044, 316, 3969, 7443, 4381, 16244, 19563, 7282, 11530, 12483, 11651, 12988, 6027, 16303, 2963, 12809, 18663, 6062, 20895, 5857, 16758, 4560, 17815, 12588, 17615, 5343, 13940, 1988, 15980, 12584, 19748, 6026, 13009, 11652, 1634, 4254, 20325, 20212, 17287, 5244, 13644, 20120, 2434, 6418, 13360, 16769, 5653, 13653, 16003, 7607, 15917, 20958, 15441, 14790, 14329, 14612, 7934, 160, 8368, 6662, 17559, 15678, 12680, 17199, 18063, 16024, 5209, 18871, 15821, 9161, 18772, 16888, 11052, 14803, 13194, 12632, 12326, 4189, 2183, 17969, 17885, 19233, 4570, 8803, 17631, 15050, 21225, 8694, 7556, 5938, 17746, 14725, 12098, 20053, 14398, 19701, 5568, 18803, 10895, 20036, 17740, 2904, 580, 14765, 13274, 3461, 17406, 5423, 12034, 11872, 3780, 4628, 3560, 378, 3768, 8838, 4750, 20502, 2198, 21220, 11019, 8114, 7169, 7275, 8714, 6617, 11006, 15722, 8720, 14775, 17234, 14652, 19258, 10054, 5934, 17493, 17938, 17024, 21088, 8287, 14588, 14373, 21215, 666, 19941, 9324, 15085, 17232, 14777, 6560, 9534, 12132, 2326, 3464, 10006, 845, 16547, 8216, 18950, 39, 18525, 6348, 4805, 15138, 5452, 11970, 14882, 12610, 125, 14110, 3500, 12647, 44, 16903, 17341, 18143, 6142, 3444, 1970, 1760, 20078, 8708, 11438, 6680, 12289, 6489, 18993, 1218, 7032, 11118, 18671, 1066, 1457, 17370, 13889, 9251, 1194, 6853, 1577, 18999, 12185, 11629, 15998, 4827, 17622, 11238, 14887, 2865, 20233, 18085, 18662, 13005, 2964, 7794, 6809, 4951, 20395, 5214, 10544, 16572, 6442, 13739, 8970, 16803, 18978, 19114, 2562, 5434, 17773, 15555, 19894, 14308, 18729, 16414, 10509, 5105, 12334, 9933, 15418, 1070, 21110, 8842, 1624, 15898, 1428, 7248, 515, 9821, 14352, 2535, 5517, 13951, 7460, 11460, 20995, 15600, 4882, 20940, 19588, 9364, 4329, 17779, 20765, 7628, 13124, 10258, 9739, 1119, 19730, 4722, 15935, 6, 3543, 1933, 6641, 1013, 20431, 19192, 14756, 2074, 463, 5417, 11004, 6619, 323, 15263, 10345, 4198, 21001, 14944, 8190, 10309, 9021, 17994, 13372, 15629, 7252, 4218, 2032, 9193, 2475, 4363, 3406, 133, 641, 18763, 16057, 19722, 13823, 12460, 6180, 6132, 15369, 18932, 20166, 6154, 14009, 93, 2972, 12520, 10970, 9905, 416, 13026, 9027, 6430, 78, 19887, 11516, 15845, 14716, 6001, 7986, 13733, 1413, 9400, 17142, 6741, 5376, 17198, 12958, 15679, 2448, 7770, 1104, 11684, 3448, 16954, 19982, 2555, 7137, 17751, 786, 7652, 19869, 18119, 9627, 1825, 9991, 5108, 6337, 2121, 1725, 10878, 9895, 7760, 18793, 7422, 11324, 18868, 10496, 16583, 43, 12849, 3501, 6526, 10059, 6043, 4956, 20816, 13115, 7289, 11962, 6288, 6270, 16820, 4907, 12325, 12945, 13195, 13726, 12127, 1719, 5391, 10659, 2396, 8045, 10574, 15669, 12431, 14966, 13056, 12082, 15655, 6541, 16055, 18765, 781, 7837, 124, 12853, 14883, 633, 17154, 19972, 16533, 9688, 13720, 18621, 14137, 770, 3396, 11833, 15329, 1693, 14083, 16566, 3320, 4245, 968, 1736, 17614, 12997, 17816, 10963, 19747, 12991, 15981, 6736, 19429, 1533, 18976, 16805, 3135, 12391, 6319, 14578, 5982, 7507, 19698, 15296, 2312, 728, 4409, 11158, 4315, 18334, 14721, 11192, 15400, 19294, 15037, 6424, 4047, 23, 8316, 13694, 4441, 9073, 2681, 7190, 3291, 11765, 9290, 14326, 10406, 3128, 11624, 1170, 8410, 9812, 16942, 2677, 3145, 13973, 8353, 14633, 9514, 6829, 19320, 5526, 8357, 6475, 18322, 9387, 2863, 14889, 20985, 19546, 10969, 12701, 2973, 13988, 18082, 821, 8801, 4572, 13530, 15569, 11793, 17997, 19072, 4564, 3703, 11271, 13226, 15477, 15604, 16727, 7791, 9806, 5317, 16190, 15098, 20862, 14461, 20532, 9422, 19348, 1367, 6903, 13311, 4117, 3372, 13127, 9571, 11650, 13011, 11531, 6101, 2795, 17851, 9418, 20967, 1292, 9129, 11937, 17294, 14181, 2170, 18341, 16577, 12045, 16324, 18202, 18437, 5499, 2243, 5875, 6179, 12711, 13824, 20854, 5949, 5320, 12235, 19535, 18680, 2303, 20963, 15638, 20427, 8734, 16678, 8312, 3619, 21067, 9091, 17776, 16505, 6584, 16289, 11594, 20023, 5713, 13796, 20884, 16625, 14965, 12621, 15670, 11016, 4089, 8877, 5957, 11601, 11696, 14969, 13157, 18037, 14213, 7182, 3555, 19713, 14476, 10580, 15632, 1088, 17480, 8344, 16500, 12342, 138, 8470, 19626, 2322, 4568, 19235, 18176, 14365, 9724, 1809, 3643, 14781, 3863, 13, 13077, 3401, 6318, 12576, 3136, 20375, 1001, 20591, 10917, 3513, 13580, 13775, 4873, 5910, 588, 2423, 15444, 9009, 9372, 13049, 4452, 17159, 8822, 15293, 14401, 4617, 14972, 15889, 6089, 1649, 12191, 3533, 16913, 3066, 9489, 16979, 6399, 6231, 4486, 13562, 5302, 10898, 15289, 9520, 7463, 18328, 4100, 2505, 4438, 3607, 2046, 137, 12409, 16501, 20573, 664, 21217, 12042, 2788, 9932, 12784, 5106, 9993, 18789, 12216, 16586, 2614, 4188, 12944, 12633, 4908, 17539, 3950, 2869, 1298, 9938, 12152, 2518, 4837, 5462, 20047, 303, 12063, 20511, 3726, 17628, 184, 6353, 16617, 10084, 19654, 13153, 10615, 15000, 13576, 10818, 11199, 7312, 18782, 20275, 3259, 504, 13450, 6057, 6488, 12836, 6681, 902, 21037, 1722, 3938, 17046, 13435, 19696, 7509, 8451, 4447, 10647, 14468, 2080, 15355, 14127, 21061, 19764, 2280, 14381, 17124, 20543, 13553, 18308, 16615, 6355, 3673, 3091, 6594, 14157, 17554, 9541, 18982, 15358, 1005, 19304, 3206, 15755, 17477, 15709, 5707, 20698, 2982, 10654, 10103, 7615, 16263, 5804, 8872, 11878, 15770, 21024, 19534, 12455, 5321, 12061, 305, 15885, 17655, 10939, 8521, 3256, 1666, 18354, 6935, 8222, 8553, 14820, 18558, 18523, 41, 16585, 12330, 18790, 1057, 6555, 15165, 10360, 11452, 19659, 14519, 19610, 16875, 9707, 7803, 12021, 14453, 6241, 4775, 16390, 13423, 6696, 5355, 13266, 11122, 5074, 3532, 12364, 1650, 17167, 3840, 19827, 11628, 12820, 19000, 5127, 6931, 704, 7698, 11448, 3133, 16807, 8697, 18569, 12006, 14264, 4779, 9783, 13185, 7347, 19135, 4519, 19594, 16069, 20137, 13535, 13758, 4025, 13769, 181, 8806, 3474, 5696, 237, 19456, 2517, 12318, 9939, 13908, 11067, 9847, 5625, 7870, 1063, 6538, 3541, 8, 18593, 19832, 18351, 15387, 20658, 16307, 8075, 10811, 2325, 12869, 9535, 14749, 17322, 1718, 12629, 13727, 21071, 11712, 6502, 4371, 19956, 8774, 9313, 15842, 18230, 20087, 3244, 4423, 6146, 1008, 6726, 4156, 7236, 6224, 19607, 4368, 11360, 14484, 9694, 2345, 5239, 21176, 20052, 12928, 14726, 20656, 15389, 9269, 7351, 9202, 4927, 11585, 5427, 8298, 2478, 20383, 6322, 13052, 15654, 12618, 13057, 10942, 19181, 17557, 6664, 4590, 1312, 5168, 18219, 17916, 7382, 4587, 10915, 20593, 1334, 878, 7044, 20510, 12312, 304, 12233, 5322, 2593, 7901, 19216, 8528, 18775, 5924, 17128, 2055, 6495, 3921, 9875, 13897, 9157, 16323, 12468, 16578, 2787, 12337, 21218, 2200, 7564, 16235, 4822, 10696, 11871, 12912, 5424, 11217, 6965, 17567, 13495, 2022, 13946, 11500, 18631, 335, 15414, 14452, 12203, 7804, 14026, 3424, 11910, 15064, 10720, 13763, 17652, 14671, 17892, 15942, 19675, 17424, 14263, 12174, 18570, 18106, 3993, 6217, 6345, 10443, 7359, 8424, 20056, 19358, 18752, 14794, 20495, 19469, 10745, 16440, 14093, 5042, 18059, 16777, 368, 13801, 7344, 16756, 5859, 9155, 13899, 10079, 11084, 15274, 4886, 20201, 10463, 8011, 14881, 12855, 5453, 5718, 17418, 2155, 14377, 18147, 6287, 12638, 7290, 9483, 8702, 6924, 1165, 2610, 10365, 2550, 2360, 18215, 15706, 1091, 4637, 2096, 18806, 620, 11071, 9759, 9710, 18958, 15559, 962, 5634, 17293, 12474, 9130, 5408, 5907, 18447, 131, 3408, 19946, 2664, 20922, 20726, 1307, 8374, 6165, 16331, 6109, 15799, 10645, 4449, 6325, 16489, 5249, 16424, 2143, 16837, 8178, 15063, 12017, 3425, 16646, 11399, 6235, 4340, 19795, 20093, 14271, 18718, 3749, 2660, 3221, 6229, 6401, 10428, 5273, 14121, 11031, 7458, 13953, 13754, 20197, 346, 1660, 8488, 16921, 3386, 17666, 5336, 221, 15769, 12239, 8873, 8201, 6466, 17388, 3779, 12911, 12035, 10697, 19370, 14627, 17067, 17269, 5028, 17374, 2926, 8723, 18387, 2357, 1877, 6624, 1949, 5867, 17432, 17835, 19138, 17189, 8039, 19835, 8564, 4108, 16651, 17056, 20012, 11047, 10036, 1973, 4708, 14457, 14950, 14332, 9779, 9638, 1177, 15328, 12598, 3397, 8771, 283, 14492, 716, 8756, 1902, 15496, 2348, 19032, 4002, 294, 4844, 6191, 6303, 13061, 9987, 19847, 260, 16591, 18260, 2705, 16167, 575, 11383, 19011, 14873, 21239, 2658, 3751, 15528, 7893, 17868, 11226, 2400, 10475, 19389, 13370, 17996, 12511, 15570, 511, 14430, 20208, 13560, 4488, 376, 3562, 20909, 11757, 2167, 15121, 3890, 10123, 1318, 5080, 20676, 16114, 4816, 21174, 5241, 5783, 1828, 11381, 577, 13958, 9289, 12548, 3292, 11329, 6221, 18182, 8889, 4271, 2166, 11783, 20910, 1326, 6171, 274, 16829, 13713, 4173, 16855, 10998, 11746, 11747, 10999, 19891, 18883, 19784, 3807, 3239, 5053, 5401, 9703, 6615, 8716, 14421, 16552, 13248, 11599, 5959, 8898, 13787, 9791, 18046, 1449, 2832, 4556, 9884, 10920, 13044, 15201, 6549, 5991, 14688, 8379, 9118, 6501, 12124, 21072, 2066, 3694, 8992, 2268, 7712, 7493, 1054, 7763, 7504, 13590, 4525, 15652, 13054, 14968, 12424, 11602, 14116, 18484, 4539, 16128, 5734, 1977, 17552, 14159, 1252, 3447, 12675, 1105, 20153, 18161, 6825, 8121, 8764, 9600, 7932, 14614, 20256, 538, 2648, 10457, 5234, 15237, 18092, 14023, 52, 19206, 3302, 5658, 17828, 4234, 278, 20714, 18339, 2172, 7818, 20681, 14004, 1633, 12987, 13010, 12484, 9572, 13318, 3440, 21144, 14648, 720, 13665, 18074, 5446, 4196, 10347, 13680, 13022, 7731, 2808, 17670, 10082, 16619, 17691, 15997, 12819, 12186, 19828, 19572, 1169, 12543, 3129, 8585, 19425, 13191, 1144, 4738, 10769, 10662, 4141, 13840, 13854, 11469, 9413, 20073, 4436, 2507, 6121, 15230, 18756, 15901, 14115, 11695, 12425, 5958, 11731, 13249, 19238, 14840, 20022, 12438, 16290, 6710, 13279, 7087, 7590, 10200, 11215, 5426, 12090, 4928, 7172, 15878, 10208, 6394, 7369, 19989, 18192, 4467, 2404, 18518, 14203, 741, 9923, 2383, 4995, 4077, 914, 1513, 5886, 21101, 13245, 4715, 8645, 7530, 11551, 1617, 6677, 6764, 9146, 18905, 882, 1616, 11559, 7531, 2575, 14714, 15847, 9512, 14635, 19954, 4373, 9044, 13447, 11489, 9306, 2292, 19979, 19255, 7095, 17335, 13390, 6100, 12482, 13012, 7283, 19449, 2779, 6883, 8849, 19441, 202, 7470, 20774, 16218, 17210, 18228, 15844, 12692, 19888, 18513, 7175, 19644, 10990, 8495, 20131, 10378, 20297, 3737, 15336, 4434, 20075, 18294, 18630, 12026, 13947, 13440, 2631, 11106, 11253, 19342, 1530, 3932, 10177, 9305, 11540, 13448, 506, 4243, 3322, 10779, 3008, 447, 17589, 13611, 20328, 15261, 325, 525, 20561, 10068, 3081, 8036, 6916, 9412, 11612, 13855, 16469, 9078, 8065, 1393, 2839, 18914, 20994, 12767, 7461, 9522, 3204, 19306, 615, 2524, 19658, 12210, 10361, 1378, 3132, 12179, 7699, 1139, 18283, 13457, 8749, 15933, 4724, 6762, 6679, 12838, 8709, 4308, 16608, 4463, 13351, 1856, 13911, 700, 20733, 8476, 6898, 20519, 16842, 1941, 20636, 1080, 16193, 16200, 18079, 17178, 20189, 13678, 10349, 5962, 16748, 13707, 18479, 15730, 7300, 7811, 5513, 20378, 491, 478, 10181, 9101, 15625, 6234, 11907, 16647, 6547, 15203, 10397, 4833, 10742, 17663, 16702, 17612, 1738, 10381, 14853, 13882, 11302, 19010, 11808, 576, 11769, 1829, 15278, 9983, 20768, 623, 17327, 9200, 7353, 10390, 7145, 115, 14413, 14661, 373, 16692, 9527, 10330, 17738, 20038, 14483, 12105, 4369, 6504, 4729, 13638, 10370, 8593, 13490, 2133, 18689, 7220, 5661, 14846, 10823, 428, 10278, 8550, 20834, 5198, 1543, 7603, 1131, 4304, 16268, 10841, 18123, 3355, 5309, 5797, 18797, 6220, 11763, 3293, 20507, 9678, 18867, 12652, 7423, 397, 5675, 16131, 3611, 18460, 8914, 8466, 5832, 17165, 1652, 19950, 8930, 9098, 7342, 13803, 17450, 10757, 17111, 5473, 19009, 11385, 13883, 14108, 127, 19576, 14866, 618, 18808, 15726, 19929, 16171, 2886, 16044, 14997, 5669, 2262, 2153, 17420, 19911, 2308, 3491, 7202, 2902, 17742, 16745, 20206, 14432, 15924, 17944, 3392, 13225, 12506, 3704, 19270, 3699, 5970, 9871, 482, 13623, 8187, 9433, 1403, 15464, 19423, 8587, 16142, 8917, 2461, 19341, 11495, 11107, 3935, 2124, 6074, 887, 15548, 18684, 18132, 17784, 8383, 20405, 14562, 6508, 14886, 12815, 17623, 20223, 15958, 13544, 4418, 7538, 20705, 7019, 13533, 20139, 2399, 11799, 17869, 2411, 143, 16643, 4400, 3783, 412, 6964, 12032, 5425, 11587, 10201, 9406, 19277, 19491, 17728, 3836, 17898, 5217, 13849, 18265, 10597, 7218, 18691, 15904, 7311, 12298, 10819, 15978, 1990, 8362, 15316, 15399, 12562, 14722, 8605, 15207, 16384, 14940, 10388, 7355, 18210, 19479, 687, 9775, 18169, 20041, 5164, 19056, 4104, 908, 21132, 6838, 19133, 7349, 9271, 10166, 3578, 9616, 4631, 8944, 1596, 5367, 20576, 15961, 5159, 4314, 12566, 4410, 13073, 15741, 19663, 13107, 16334, 2160, 18721, 19020, 18549, 10594, 9005, 13635, 15379, 1845, 7925, 14769, 8100, 14909, 5711, 20025, 541, 17086, 7549, 20475, 16873, 19612, 13283, 3665, 2976, 17358, 9470, 19932, 19504, 5073, 12194, 13267, 20176, 18670, 12831, 7033, 17660, 19472, 804, 13506, 7432, 17907, 17922, 10175, 3934, 11252, 11496, 2632, 15687, 15964, 15152, 17770, 19483, 20442, 16155, 15762, 1443, 10839, 16270, 10205, 20589, 1003, 15360, 10270, 10911, 1517, 16529, 15273, 11977, 10080, 17672, 1886, 10986, 15124, 1102, 7772, 20448, 3326, 10140, 17316, 9758, 11945, 621, 20770, 9846, 12149, 13909, 1858, 7881, 2884, 16173, 17719, 10222, 20270, 3873, 18325, 13345, 15745, 8015, 14802, 12948, 16889, 13658, 9661, 10035, 11844, 20013, 4978, 10156, 661, 5370, 9668, 14856, 1385, 15082, 4920, 5629, 17599, 14918, 17009, 7457, 11892, 14122, 500, 3529, 10189, 980, 5704, 14600, 14530, 17934, 778, 8113, 12900, 21221, 4088, 12429, 15671, 16284, 794, 13462, 20231, 2867, 3952, 5846, 15721, 12894, 6618, 12738, 5418, 14100, 18511, 19890, 11745, 11748, 16856, 15157, 19843, 7160, 17875, 8124, 8494, 11511, 19645, 3888, 15123, 11080, 1887, 2040, 13573, 2408, 21099, 5888, 10160, 10339, 17963, 3114, 2547, 1612, 15700, 20820, 9904, 12700, 12521, 19547, 17712, 7467, 20936, 19746, 12586, 17817, 10514, 10577, 15309, 3505, 4506, 3430, 10737, 20313, 17723, 18361, 5207, 16026, 18498, 17570, 20128, 1521, 16276, 267, 19180, 12080, 13058, 8520, 12229, 17656, 14143, 13404, 20290, 2644, 1344, 5045, 17366, 19092, 6874, 36, 18298, 600, 20647, 604, 6158, 5036, 13043, 11721, 9885, 3512, 12386, 20592, 12069, 4588, 6666, 1516, 11088, 10271, 3287, 19187, 2859, 13587, 5985, 8515, 17052, 9610, 7570, 9834, 15288, 12353, 5303, 20035, 12922, 18804, 2098, 20692, 5821, 6083, 9038, 9798, 19872, 651, 18638, 9294, 18700, 19639, 14497, 7610, 9894, 12657, 1726, 3338, 1867, 810, 343, 1117, 9741, 953, 19510, 9861, 6397, 16981, 1282, 20006, 1560, 6308, 10063, 13895, 9877, 14105, 1189, 10831, 4149, 4954, 6045, 9854, 16417, 20400, 16232, 13928, 6017, 2495, 6457, 6922, 8704, 18122, 11336, 16269, 11095, 1444, 7050, 15773, 5502, 13236, 6370, 4148, 10856, 1190, 17196, 5378, 1365, 19350, 14148, 427, 11347, 14847, 9354, 15977, 11198, 12299, 13577, 15645, 5968, 3701, 4566, 2324, 12134, 8076, 15490, 2722, 14903, 9249, 13891, 16099, 15475, 13228, 16493, 6478, 13151, 19656, 2526, 2231, 1621, 18929, 18600, 9578, 16016, 18552, 17244, 15920, 1047, 9276, 13239, 5396, 15953, 4790, 6314, 3007, 11484, 3323, 10520, 2876, 18848, 9452, 1861, 15198, 2394, 10661, 11617, 4739, 17595, 7734, 17543, 1981, 2072, 14758, 2258, 14427, 10585, 17110, 11306, 17451, 16038, 2380, 8599, 4667, 16965, 13037, 13995, 17033, 3123, 16439, 11991, 19470, 17662, 11393, 4834, 8463, 16145, 20312, 10955, 3431, 10288, 10673, 5582, 17888, 799, 17925, 10472, 18374, 15133, 20620, 1798, 18472, 13914, 15909, 13762, 12015, 15065, 17953, 7581, 3368, 17609, 6292, 18247, 17120, 6633, 995, 16722, 5599, 3349, 16034, 8447, 4678, 20436, 3565, 14860, 6755, 20535, 19369, 11870, 12036, 4823, 19108, 3568, 4093, 1279, 6813, 15648, 17902, 6970, 3974, 6498, 3929, 19432, 7576, 14291, 5552, 5264, 18468, 14368, 13203, 8626, 5581, 10734, 10289, 5941, 6772, 8834, 5618, 13999, 20736, 6821, 10490, 4140, 11616, 10770, 2395, 12626, 5392, 5231, 2699, 10102, 12245, 2983, 10045, 14032, 2084, 15611, 14467, 12277, 4448, 11920, 15800, 16654, 608, 16741, 17821, 16852, 20461, 13599, 16629, 8095, 8947, 6250, 15582, 4904, 7727, 18887, 3036, 4250, 14165, 21246, 3, 7084, 16999, 18213, 2362, 13522, 16345, 5667, 14999, 12302, 13154, 4620, 7650, 788, 4397, 3428, 4508, 20641, 4595, 5449, 9329, 16801, 8972, 6782, 5638, 19165, 7217, 11204, 18266, 9004, 11147, 18550, 16018, 15857, 8623, 18854, 10479, 9633, 17109, 10759, 14428, 513, 7250, 15631, 12415, 14477, 15308, 10960, 10515, 15668, 12623, 8046, 6881, 2781, 15985, 15697, 6958, 13673, 1817, 17320, 14751, 17275, 14279, 3347, 5601, 14436, 19970, 17156, 17681, 2141, 16426, 9213, 9379, 1880, 714, 14494, 6389, 17684, 813, 16571, 12802, 5215, 17900, 15650, 4527, 20254, 14616, 4129, 3002, 14957, 3640, 17881, 13668, 3296, 6184, 9234, 7487, 5340, 7335, 2777, 19451, 629, 6116, 2875, 10777, 3324, 20450, 3361, 15667, 10576, 10961, 17818, 10294, 937, 5104, 12786, 16415, 9856, 3587, 1779, 9258, 4810, 18126, 4216, 7254, 8212, 4284, 16582, 12650, 18869, 5211, 3798, 9943, 4139, 10664, 6822, 18991, 6491, 19177, 19268, 3706, 13515, 3654, 16510, 9632, 10588, 18855, 6051, 19388, 11797, 2401, 18373, 10729, 17926, 9765, 18242, 14935, 16459, 5296, 15853, 8010, 11973, 20202, 5329, 4005, 2697, 5233, 11671, 2649, 2320, 19628, 19018, 18723, 1593, 8098, 14771, 4756, 8021, 5774, 5150, 7358, 12000, 6346, 18527, 5759, 13173, 9115, 18925, 16683, 17548, 15281, 5604, 7672, 8950, 10051, 5272, 11895, 6402, 9902, 20822, 7101, 1899, 19884, 15871, 4053, 20059, 10393, 17101, 14879, 8013, 15747, 5476, 14199, 19805, 10154, 4980, 9913, 3127, 12545, 14327, 14792, 18754, 15232, 7321, 5017, 849, 4832, 11395, 15204, 16295, 17100, 10418, 20060, 7144, 11372, 7354, 11186, 14941, 19689, 1243, 19967, 4268, 14852, 11388, 1739, 20296, 11508, 20132, 20906, 20439, 19382, 17911, 19523, 8592, 11355, 13639, 6752, 1610, 2549, 11955, 2611, 20598, 1377, 11451, 12211, 15166, 15428, 557, 19151, 2445, 8327, 1214, 15946, 8896, 5961, 11415, 13679, 11639, 4197, 12734, 15264, 7662, 18390, 2062, 17962, 10978, 10161, 19733, 14583, 16661, 9180, 657, 8863, 17737, 11364, 9528, 8206, 16213, 15091, 20645, 602, 20649, 2951, 21213, 14375, 2157, 3883, 16204, 19905, 18605, 959, 7845, 7106, 3593, 9020, 12729, 8191, 9169, 2069, 20982, 4973, 19728, 1121, 3679, 2751, 5223, 16042, 2888, 3526, 936, 10512, 17819, 16743, 17744, 5940, 10672, 10735, 3432, 8663, 1503, 313, 13782, 3537, 1702, 8728, 8549, 11345, 429, 5549, 19637, 18702, 18135, 3286, 10910, 11089, 15361, 150, 18841, 7676, 19209, 19362, 10169, 6126, 17361, 1604, 9738, 12755, 13125, 3374, 14089, 1406, 6092, 4393, 9501, 9504, 1359, 2738, 7149, 15831, 8511, 14631, 8355, 5528, 15403, 17297, 18382, 1018, 7787, 20455, 4965, 5578, 8820, 17161, 28, 8349, 13136, 20471, 3315, 6719, 6649, 15545, 20269, 11060, 17720, 20749, 7127, 9357, 13792, 4240, 6331, 3650, 15620, 16329, 6167, 19864, 6393, 11581, 15879, 20588, 11093, 16271, 1236, 9405, 11214, 11588, 7591, 4360, 8301, 6447, 13234, 5504, 7904, 2924, 17376, 979, 11027, 3530, 5076, 18365, 13368, 19391, 7340, 9100, 11403, 479, 20628, 9304, 11491, 3933, 11109, 17923, 801, 13477, 20147, 6125, 10263, 19363, 3577, 11169, 9272, 5976, 4720, 19732, 10338, 10979, 5889, 20246, 660, 11044, 4979, 10410, 19806, 5487, 5094, 807, 1766, 3479, 6097, 5285, 5562, 18617, 9753, 9997, 17315, 11074, 3327, 3342, 13817, 7743, 20445, 1777, 3589, 14216, 8418, 2579, 1073, 7982, 9055, 16176, 1745, 1317, 11779, 3891, 18273, 17584, 7966, 1637, 4376, 774, 13700, 4163, 20708, 1224, 15538, 6340, 13149, 6480, 13324, 19404, 5870, 7614, 12244, 10655, 2700, 2229, 2528, 19089, 4915, 8142, 1586, 5508, 8176, 16839, 8683, 16935, 16090, 5288, 673, 15882, 19653, 12305, 16618, 11633, 17671, 11083, 11978, 13900, 2116, 14411, 117, 20341, 17145, 2193, 16085, 1208, 3080, 11474, 20562, 1770, 3039, 13894, 10861, 6309, 4865, 6042, 12644, 6527, 8687, 5850, 5933, 12887, 19259, 5271, 10430, 8951, 13938, 5345, 2558, 14031, 10652, 2984, 7400, 16032, 3351, 17413, 3521, 1758, 1972, 11843, 11048, 9662, 15824, 9217, 14285, 20837, 17466, 16849, 4606, 21106, 18838, 3380, 9450, 18850, 1110, 7716, 14230, 544, 13711, 16831, 7705, 5291, 1026, 3626, 8434, 6363, 14741, 6687, 844, 12866, 3465, 3117, 2565, 5701, 20362, 15175, 19125, 17314, 10142, 9754, 1908, 18788, 12332, 5107, 12662, 1826, 5785, 19846, 11816, 13062, 7626, 20767, 11378, 15279, 17550, 1979, 17545, 8743, 8024, 17857, 3305, 5325, 6817, 1043, 4504, 3507, 18347, 14047, 17758, 18941, 1338, 3829, 19096, 18987, 15580, 6252, 5205, 18363, 5078, 1320, 5523, 2441, 20631, 6383, 1673, 21122, 7141, 7366, 9864, 2240, 15776, 4138, 10492, 3799, 7446, 13907, 12151, 12319, 1299, 19597, 4084, 15417, 12783, 12335, 2789, 17638, 5118, 15574, 20852, 13826, 8597, 2382, 11571, 742, 17956, 9486, 15029, 2452, 15452, 15940, 17894, 3126, 10408, 4981, 16945, 20118, 13646, 19706, 16051, 415, 12699, 10971, 20821, 10426, 6403, 15588, 14029, 2560, 19116, 7759, 12656, 10879, 7611, 16520, 14745, 16880, 9144, 6766, 1211, 3511, 10919, 11722, 4557, 20876, 6588, 6836, 21134, 14104, 10859, 13896, 12049, 3922, 20626, 481, 11266, 5971, 19420, 9480, 20673, 9441, 2239, 9947, 7367, 6396, 10868, 19511, 3637, 4547, 3586, 10507, 16416, 10852, 6046, 14702, 4602, 9342, 15015, 5624, 12148, 11068, 20771, 20758, 871, 15736, 13438, 13949, 5519, 2770, 7542, 4501, 15287, 10900, 7571, 1060, 4071, 3170, 5049, 5056, 20169, 613, 19308, 4407, 730, 14351, 12773, 516, 20549, 7338, 19393, 7898, 16786, 4641, 16941, 12540, 8411, 14570, 14487, 16525, 5316, 12500, 7792, 2966, 20110, 13550, 9070, 18117, 19871, 10888, 9039, 1591, 18725, 20634, 1943, 18045, 11727, 13788, 8482, 255, 2335, 18410, 19856, 13184, 12171, 4780, 7394, 9637, 11837, 14333, 13213, 18168, 11181, 688, 20724, 20924, 5988, 921, 7638, 3660, 20802, 18241, 10470, 17927, 17006, 20743, 7801, 9709, 11944, 11072, 17317, 19719, 1907, 9996, 10143, 18618, 7809, 7302, 9223, 2619, 2955, 1174, 16815, 5913, 17512, 952, 10871, 1118, 12754, 10259, 1605, 14074, 2736, 1361, 8557, 5405, 3021, 4039, 5031, 475, 13779, 21047, 1808, 12400, 14366, 18470, 1800, 13966, 8237, 8767, 15149, 7859, 3914, 14154, 1994, 1270, 18957, 11943, 9760, 7802, 12205, 16876, 1295, 6614, 11737, 5402, 6535, 18674, 13718, 9690, 19633, 20367, 2344, 12103, 14485, 14572, 19632, 9698, 13719, 12604, 16534, 8004, 148, 15363, 19736, 20335, 17172, 16254, 18866, 11326, 20508, 7046, 2731, 18845, 16782, 3057, 1260, 13880, 14855, 11041, 5371, 14077, 16321, 9159, 15823, 10034, 11049, 13659, 14162, 7970, 14539, 4959, 8811, 1227, 6409, 2011, 8000, 9518, 15291, 8824, 9554, 7134, 5348, 2493, 6019, 15128, 18742, 16813, 1176, 11836, 9780, 7395, 7409, 17108, 10587, 10480, 16511, 20105, 8058, 1824, 12664, 18120, 8706, 20080, 1677, 1421, 9063, 8430, 5252, 3558, 4630, 11167, 3579, 18441, 13518, 8227, 7569, 10902, 17053, 15803, 3175, 7584, 20529, 6601, 105, 17809, 7931, 11677, 8765, 8239, 8262, 19616, 7245, 568, 13431, 19077, 2910, 535, 20971, 17015, 3421, 15591, 17947, 2043, 21197, 7226, 3157, 6012, 16015, 10792, 18601, 20711, 993, 6635, 13317, 11649, 12485, 13128, 14424, 3088, 1096, 20144, 8574, 17802, 19997, 7090, 3697, 19272, 15515, 5121, 16710, 2765, 7133, 9647, 8825, 6281, 8195, 5597, 16724, 7659, 13745, 13486, 20195, 13756, 13537, 18981, 12257, 17555, 19183, 177, 9125, 14748, 12131, 12870, 6561, 15258, 14700, 6048, 8205, 10329, 11365, 16693, 18417, 19800, 3203, 11458, 7462, 12351, 15290, 9650, 8001, 4697, 6828, 12533, 14634, 11546, 15848, 16196, 18010, 17442, 1465, 2366, 1358, 10250, 9502, 9503, 10251, 4394, 17076, 7536, 4420, 20975, 15078, 19923, 339, 9466, 19083, 16978, 12360, 3067, 15028, 9920, 17957, 8701, 11960, 7291, 20672, 9868, 19421, 15466, 16008, 75, 16433, 5135, 573, 16169, 19931, 11126, 17359, 6128, 19082, 9492, 340, 17687, 20873, 16761, 7689, 1041, 6819, 20738, 5679, 8738, 3253, 7879, 1860, 10774, 18849, 10023, 3381, 13356, 5721, 17498, 18591, 10, 6376, 2238, 9866, 20674, 5082, 18544, 2989, 4658, 20989, 1402, 11262, 8188, 14946, 15058, 16405, 20955, 17247, 2217, 18901, 5753, 19347, 12493, 20533, 6757, 20966, 12478, 17852, 8651, 5921, 20072, 11611, 11470, 6917, 6299, 6792, 16541, 19276, 11213, 10202, 1237, 4193, 4598, 17141, 12685, 1414, 13210, 4060, 2111, 3414, 3817, 15382, 19300, 14625, 19372, 18892, 2862, 12526, 18323, 3875, 16221, 3980, 4182, 6622, 1879, 10552, 9214, 8338, 17470, 3861, 14783, 13048, 12376, 9010, 5480, 21028, 15913, 3583, 17863, 4328, 12761, 19589, 20903, 1052, 7495, 7296, 13791, 10218, 7128, 15976, 10821, 14848, 15020, 18028, 18589, 17500, 2531, 6978, 1156, 1454, 16909, 15014, 9850, 4603, 17824, 9232, 6186, 13071, 4412, 19106, 4825, 16000, 4760, 14924, 16800, 10604, 5450, 15140, 4918, 15084, 12875, 19942, 523, 327, 18585, 1303, 17841, 21118, 2802, 15342, 15841, 12119, 8775, 3956, 15615, 20287, 5690, 2291, 11539, 11490, 10178, 20629, 2443, 19153, 16612, 20158, 5543, 3034, 18889, 18699, 10884, 18639, 20084, 14325, 12547, 11766, 13959, 8611, 14962, 3102, 6872, 19094, 3831, 15531, 15796, 8394, 6368, 13238, 10786, 1048, 16363, 5975, 10165, 11170, 7350, 12094, 15390, 4493, 13905, 7448, 20881, 4472, 3190, 16207, 7156, 4809, 10504, 1780, 754, 6455, 2497, 1891, 1193, 12825, 13890, 10806, 14904, 15032, 17256, 3143, 2679, 9075, 6986, 3825, 1574, 5307, 3357, 6578, 3597, 7486, 10529, 6185, 9339, 17825, 7223, 13445, 9046, 6797, 5835, 20914, 2618, 9749, 7303, 19227, 7754, 3682, 14284, 10032, 15825, 8337, 9378, 10553, 16427, 5014, 13685, 19049, 31, 8912, 18462, 4671, 8781, 4926, 12092, 7352, 11374, 17328, 14754, 19194, 4121, 15325, 2474, 12721, 2033, 13348, 18656, 15927, 9016, 20945, 8937, 739, 14205, 20371, 19915, 656, 10334, 16662, 13867, 3333, 3030, 16081, 19937, 16659, 14585, 3692, 2068, 10307, 8192, 8631, 5595, 8197, 14927, 866, 18771, 12951, 15822, 9664, 16322, 12047, 13898, 11980, 5860, 593, 6523, 8321, 1197, 73, 16010, 18904, 11555, 6765, 9889, 16881, 1642, 15025, 14013, 17093, 14523, 20241, 15103, 16826, 18005, 1162, 3019, 5407, 11936, 12475, 1293, 16878, 14747, 9537, 178, 7522, 8620, 19531, 3927, 6500, 11714, 8380, 18924, 10438, 13174, 4942, 591, 5862, 2898, 1417, 2656, 21241, 17708, 14711, 20186, 13379, 15624, 11402, 10182, 7341, 11310, 8931, 18732, 1793, 21012, 15553, 17775, 12443, 21068, 7480, 17224, 7491, 7714, 1112, 5180, 1655, 16730, 2114, 13902, 8064, 11466, 16470, 6985, 9243, 2680, 12552, 4442, 18116, 9801, 13551, 20545, 14318, 16122, 2249, 8429, 9621, 1422, 17409, 4082, 19599, 8885, 17717, 16175, 10127, 7983, 15894, 14553, 7826, 4859, 16474, 15008, 6796, 9228, 13446, 11542, 4374, 1639, 6730, 1590, 9797, 10889, 6084, 14694, 20192, 2459, 8919, 4664, 21208, 2726, 2691, 6429, 12696, 13027, 14314, 2895, 19583, 17993, 12728, 10310, 3594, 5364, 20944, 9188, 15928, 8794, 1715, 225, 5479, 9371, 12377, 15445, 4986, 13634, 11146, 10595, 18267, 551, 15542, 5540, 3772, 5494, 18043, 1945, 20244, 5891, 2267, 11708, 3695, 7092, 14655, 18158, 17576, 14894, 4634, 2941, 7696, 706, 4125, 6868, 18969, 1485, 188, 7122, 5894, 19169, 6781, 10602, 16802, 12798, 13740, 1553, 7814, 4203, 17311, 19527, 212, 20347, 14568, 8413, 14761, 15192, 7799, 20745, 17990, 974, 2467, 13937, 10050, 10431, 7673, 6249, 10634, 8096, 1595, 11165, 4632, 14896, 21065, 3621, 17523, 738, 9186, 20946, 1202, 15787, 16412, 18731, 9097, 11311, 19951, 18380, 17299, 3710, 16341, 8616, 8305, 17061, 18635, 4663, 9033, 2460, 11256, 16143, 8465, 11317, 18461, 9207, 32, 20585, 676, 4748, 8840, 21112, 19203, 17642, 16811, 18744, 17149, 2921, 13786, 11729, 5960, 10351, 15947, 7687, 16763, 15018, 14850, 4270, 11760, 18183, 4336, 17716, 9058, 19600, 15160, 5360, 6277, 16632, 6848, 5956, 12427, 4090, 16797, 8200, 11877, 12240, 5805, 18826, 20661, 15339, 16376, 7474, 7669, 17736, 10332, 658, 20248, 874, 18113, 8673, 14931, 17848, 8172, 21236, 17386, 6468, 17606, 19440, 11525, 6884, 3073, 2014, 16681, 18927, 1623, 12779, 21111, 8907, 4749, 12905, 3769, 20161, 5617, 10669, 6773, 1536, 17694, 14067, 7036, 3212, 8092, 6280, 9553, 9648, 15292, 12372, 17160, 10233, 5579, 8628, 6284, 4624, 365, 7453, 15536, 1226, 9655, 4960, 14665, 4744, 3473, 12158, 182, 17630, 12937, 4571, 12515, 822, 5611, 286, 18946, 2569, 1714, 9014, 15929, 15300, 395, 7425, 8538, 15070, 15374, 19006, 15750, 2812, 3047, 4925, 9204, 4672, 2908, 19079, 7068, 3955, 9312, 12120, 19957, 282, 11831, 3398, 18454, 15148, 9718, 8238, 9599, 11678, 8122, 17877, 17132, 7938, 14346, 19882, 1901, 11827, 717, 6788, 387, 6151, 5059, 15932, 11443, 13458, 4522, 5645, 5772, 8023, 9978, 17546, 16685, 2177, 3252, 9456, 5680, 7719, 16677, 12448, 20428, 3167, 7261, 18276, 8548, 10280, 1703, 264, 6360, 18386, 11862, 2927, 14774, 12892, 15723, 1929, 14420, 11735, 6616, 12896, 7276, 18104, 18572, 4307, 11437, 12839, 20079, 9625, 18121, 10843, 6923, 11959, 9484, 17958, 14059, 18568, 12176, 16808, 7555, 12933, 21226, 17202, 14825, 6212, 1955, 5849, 10057, 6528, 2915, 16934, 10091, 16840, 20521, 18937, 5953, 1551, 13742, 15267, 6671, 14930, 8858, 18114, 4444, 2273, 19716, 1820, 14513, 5268, 8258, 1502, 10286, 3433, 8252, 3635, 19513, 20281, 17004, 17929, 4683, 7166, 19556, 5920, 9416, 17853, 20479, 7112, 2628, 7529, 11561, 4716, 1277, 4095, 20616, 6366, 8396, 21125, 13412, 20468, 2484, 5194, 14708, 5594, 9167, 8193, 6283, 8818, 5580, 10675, 13204, 18853, 10590, 15858, 19530, 9122, 7523, 8054, 8304, 8924, 16342, 4429, 14979, 14961, 9287, 13960, 8134, 433, 16293, 15206, 11190, 14723, 17748, 8400, 21206, 4666, 10753, 2381, 9925, 13827, 2456, 13489, 11354, 10371, 19524, 19128, 14912, 16141, 11258, 19424, 11622, 3130, 1380, 13597, 20463, 3498, 14112, 18694, 1267, 4295, 17801, 9565, 20145, 13479, 18801, 5570, 8291, 4051, 15873, 14508, 4107, 11849, 19836, 7516, 13263, 15248, 6533, 5404, 9733, 1362, 21171, 14819, 12222, 8223, 20833, 11344, 10279, 8729, 18277, 21156, 7240, 15095, 1083, 2317, 5880, 15117, 15069, 8789, 7426, 1527, 5192, 2486, 20608, 21116, 17843, 16886, 18774, 12056, 19217, 17031, 13997, 5620, 7877, 3255, 12228, 10940, 13059, 6305, 248, 17051, 10904, 5986, 20926, 14630, 10245, 15832, 20786, 19175, 6493, 2057, 818, 20236, 14608, 19316, 17706, 21243, 5314, 16527, 1519, 20130, 11510, 10991, 8125, 13621, 484, 3470, 16920, 11885, 1661, 309, 16367, 5649, 254, 9789, 13789, 7298, 15732, 18714, 6897, 11428, 20734, 14001, 19821, 5351, 19625, 12407, 139, 20179, 5831, 11316, 8915, 16144, 10740, 4835, 2520, 6941, 1355, 5694, 3476, 15815, 18687, 2135, 2271, 4446, 12279, 7510, 14807, 4677, 10705, 16035, 854, 16298, 14440, 13455, 18285, 8244, 2587, 3164, 1016, 18384, 6362, 10011, 3627, 16422, 5251, 9620, 9064, 2250, 19672, 14396, 20055, 11998, 7360, 3879, 19792, 20183, 2578, 10131, 14217, 20031, 2256, 14760, 8960, 14569, 9811, 12541, 1171, 19489, 19279, 17805, 15107, 3106, 3908, 4346, 21205, 8602, 17749, 7139, 21124, 8639, 6367, 9279, 15797, 6111, 16444, 14901, 2724, 21210, 2299, 13033, 4702, 20404, 11243, 17785, 18923, 9117, 11715, 14689, 6472, 4017, 6164, 11925, 1308, 20583, 34, 6876, 6661, 12962, 161, 4225, 3311, 3756, 15315, 11195, 1991, 6597, 4015, 6474, 12529, 5527, 10243, 14632, 12535, 13974, 14080, 13135, 10230, 29, 19051, 747, 16499, 12411, 17481, 20871, 17689, 16621, 17469, 9377, 9215, 15826, 3843, 17788, 7975, 6484, 20669, 18345, 3509, 1213, 10354, 2446, 15681, 1548, 6851, 1196, 9151, 6524, 3503, 15311, 13693, 12555, 24, 6199, 3618, 12446, 16679, 2016, 3364, 3280, 19066, 17060, 8923, 8617, 8055, 6446, 10197, 4361, 2477, 12088, 5428, 2378, 16040, 5225, 3186, 4050, 8569, 5571, 3690, 14587, 12881, 21089, 13315, 6637, 6920, 6459, 5808, 291, 5332, 13642, 5246, 7596, 15596, 4480, 7889, 14831, 18815, 1129, 7605, 16005, 3962, 1037, 924, 16995, 19615, 9597, 8240, 15223, 1501, 8665, 5269, 19261, 7309, 15906, 3634, 8661, 3434, 16689, 4491, 15392, 354, 15187, 2586, 8440, 18286, 4946, 15222, 8261, 9598, 8766, 9719, 13967, 1686, 5005, 16868, 13806, 17280, 20933, 205, 7568, 9612, 13519, 7439, 20832, 8552, 12223, 6936, 244, 14544, 13090, 18949, 12863, 16548, 18423, 4283, 10499, 7255, 7098, 454, 21015, 16212, 10328, 9529, 6049, 18857, 6465, 11876, 8874, 16798, 14926, 9165, 5596, 9551, 6282, 8630, 9168, 10308, 12730, 14945, 9432, 11263, 13624, 15970, 16969, 1785, 18547, 19022, 16398, 15062, 11912, 16838, 10093, 5509, 4553, 21235, 8855, 17849, 2797, 18332, 4317, 4968, 2598, 20423, 17768, 15154, 2844, 19329, 6704, 13031, 2301, 18682, 15550, 457, 3024, 16408, 4766, 13122, 7630, 1709, 20789, 17213, 13417, 3630, 17462, 1585, 10096, 4916, 15142, 531, 3043, 14560, 20407, 432, 8609, 13961, 3236, 8032, 14813, 18234, 16482, 13098, 13620, 8493, 10992, 17876, 8763, 11679, 6826, 4699, 2828, 6606, 19554, 7168, 12899, 11020, 779, 18767, 13170, 20302, 2745, 20653, 20784, 15834, 18521, 18560, 7767, 14908, 11140, 14770, 10450, 1594, 8946, 10635, 16630, 6279, 8827, 3213, 7944, 3487, 18111, 876, 1336, 18943, 2372, 6944, 4405, 19310, 2481, 13139, 948, 15489, 10810, 12135, 16308, 230, 17831, 17175, 13991, 3917, 7992, 21140, 1392, 11465, 9079, 13903, 4495, 7390, 3547, 1823, 9629, 20106, 6445, 8303, 8618, 7524, 14017, 17508, 360, 6081, 5823, 6880, 10573, 12624, 2397, 20141, 14045, 18349, 19834, 11851, 17190, 6915, 11472, 3082, 2601, 14812, 8131, 3237, 3809, 4180, 3982, 13923, 19813, 17856, 9977, 8744, 5773, 10447, 4757, 13656, 16891, 6699, 14801, 11054, 15746, 10415, 14880, 11972, 10464, 15854, 19157, 13289, 16558, 147, 9686, 16535, 4696, 9517, 9651, 2012, 3075, 17504, 195, 7956, 18736, 21139, 8068, 3918, 3977, 392, 14257, 13732, 12688, 6002, 15893, 9054, 10128, 1074, 5838, 19200, 3967, 318, 6483, 8333, 17789, 2429, 18100, 14538, 9658, 14163, 4252, 1636, 10119, 17585, 18377, 14638, 7618, 2091, 13242, 4692, 7750, 18735, 7995, 196, 7265, 14619, 16136, 1960, 2853, 3249, 7856, 15967, 14557, 3486, 8090, 3214, 18056, 1347, 20413, 14345, 8760, 17133, 20841, 159, 12964, 14613, 11676, 9601, 17810, 21181, 17064, 20929, 14768, 11142, 1846, 4134, 15210, 18627, 18954, 18358, 15792, 20322, 20491, 19366, 7683, 18431, 19325, 4656, 2991, 15012, 16911, 3535, 13784, 2923, 10193, 5505, 19215, 12058, 2594, 16785, 9816, 19394, 15470, 2959, 17867, 11801, 15529, 3833, 14830, 8273, 4481, 424, 20798, 2510, 13402, 14145, 2883, 11064, 1859, 9454, 3254, 8523, 5621, 16766, 20827, 862, 4069, 1062, 12146, 5626, 1743, 16178, 14597, 15712, 18608, 16370, 17437, 766, 3913, 9716, 15150, 15966, 7948, 3250, 2179, 15184, 17240, 20390, 3225, 21137, 18738, 13365, 7105, 10313, 960, 15561, 6545, 16649, 4110, 13872, 123, 12612, 782, 3996, 21031, 4035, 13103, 17620, 4829, 7077, 3986, 4858, 9051, 14554, 13627, 384, 7029, 17398, 19604, 20680, 11656, 2173, 21161, 4202, 8967, 1554, 5512, 11408, 7301, 9751, 18619, 13722, 50, 14025, 12020, 12204, 9708, 9761, 20744, 8957, 15193, 6779, 19171, 6808, 12807, 2965, 9805, 12501, 16728, 1657, 20454, 10237, 1019, 3776, 14041, 19760, 13919, 15685, 2634, 16514, 4334, 18185, 911, 16118, 1775, 20447, 11077, 1103, 12677, 2449, 14907, 8102, 18561, 15783, 7503, 11703, 1055, 18792, 12655, 9896, 19117, 14835, 2749, 3681, 9220, 19228, 1791, 18734, 7958, 4693, 3805, 19786, 5441, 16153, 20444, 10136, 13818, 14119, 5275, 3760, 358, 17510, 5915, 17542, 10766, 17596, 2807, 11636, 13023, 13811, 18886, 10630, 4905, 16822, 7286, 18015, 4847, 4688, 16676, 8736, 5681, 14229, 10020, 1111, 9086, 7492, 11706, 2269, 2137, 19867, 7654, 671, 5290, 10015, 16832, 7110, 20481, 17338, 1138, 11447, 12180, 705, 8983, 2942, 3028, 3335, 17350, 7635, 1040, 9461, 16762, 8894, 15948, 4168, 18430, 7914, 19367, 20537, 2007, 16718, 3300, 19208, 10266, 18842, 6248, 8949, 10432, 5605, 17735, 8865, 7475, 7415, 16544, 3946, 2355, 18389, 10343, 15265, 13744, 9548, 16725, 15606, 16635, 670, 7708, 19868, 12667, 787, 10612, 4621, 18150, 3494, 19297, 3456, 19669, 2089, 7620, 20867, 19963, 3659, 9769, 922, 1039, 7691, 17351, 15321, 4222, 1708, 8150, 13123, 12757, 20766, 9985, 13063, 5280, 6694, 13425, 20866, 7642, 2090, 7962, 14639, 16262, 12243, 10104, 5871, 16519, 9893, 10880, 14498, 15916, 12971, 16004, 8269, 1130, 11340, 1544, 2190, 4785, 3723, 6565, 15595, 8276, 5247, 16491, 13230, 4359, 10199, 11589, 7088, 19999, 2743, 20304, 20528, 9606, 3176, 3367, 10717, 17954, 744, 5685, 14290, 10682, 19433, 15662, 6553, 1059, 9833, 10901, 9611, 8228, 206, 13926, 16234, 12039, 2201, 726, 2314, 7118, 17079, 2821, 5937, 12932, 8695, 16809, 17644, 18271, 3893, 20474, 11134, 17087, 2949, 20651, 2747, 14837, 4500, 9837, 2771, 18596, 20704, 11232, 4419, 9498, 17077, 7120, 190, 2574, 11550, 11560, 8646, 2629, 13442, 21200, 14016, 8053, 8619, 9123, 179, 13771, 3870, 6991, 13262, 8562, 19837, 6135, 18281, 1141, 14806, 8450, 12280, 19697, 12572, 5983, 13589, 11702, 7764, 15784, 5902, 21231, 1330, 6440, 16574, 7295, 9360, 1053, 11705, 7713, 9087, 17225, 17250, 5339, 10528, 9235, 3598, 4862, 3616, 6201, 17223, 9089, 21069, 13729, 17380, 7414, 7668, 8866, 16377, 20756, 20773, 11522, 203, 20935, 10966, 17713, 13343, 18327, 12350, 9521, 11459, 12768, 13952, 11891, 11032, 17010, 1030, 15535, 8814, 366, 16779, 2879, 20880, 9265, 13906, 9941, 3800, 4380, 13017, 3970, 2694, 20831, 8225, 13520, 2364, 1467, 13877, 1233, 17906, 11112, 13507, 7131, 2767, 19337, 1526, 8537, 8790, 396, 11323, 12653, 18794, 17230, 15087, 15513, 19274, 16543, 7667, 7476, 17381, 7306, 15866, 17107, 9635, 7396, 16259, 5203, 6254, 16897, 2283, 4646, 16031, 10043, 2985, 19740, 16258, 7408, 9636, 9781, 4781, 18747, 3546, 8061, 4496, 4534, 5855, 20897, 1034, 20612, 4586, 12071, 17917, 4513, 4145, 17138, 13410, 21127, 3012, 18251, 19781, 13814, 20017, 19988, 11579, 6395, 9863, 9948, 7142, 20062, 4610, 17207, 3878, 8423, 11999, 10444, 5151, 18209, 11185, 10389, 11373, 9201, 12093, 9270, 11171, 19134, 12169, 13186, 16755, 11983, 13802, 11309, 9099, 10183, 19392, 9818, 20550, 2776, 10526, 5341, 17617, 3789, 1488, 13467, 5565, 17977, 17266, 13222, 1437, 21042, 13683, 5016, 10401, 15233, 15508, 1842, 3820, 20487, 20606, 2488, 18781, 12297, 11200, 15905, 8255, 19262, 15865, 7412, 17382, 19226, 9222, 9750, 7810, 11409, 15731, 8480, 13790, 9359, 7496, 16575, 18343, 20671, 9482, 11961, 12639, 13116, 18014, 7724, 16823, 19448, 11529, 13013, 19564, 6087, 15891, 6004, 18103, 8713, 12897, 7170, 4930, 489, 20380, 19313, 14954, 6866, 4127, 14618, 7954, 197, 17582, 18275, 8731, 3168, 4073, 13179, 17333, 7097, 8211, 10500, 4217, 12724, 15630, 10582, 514, 12775, 1429, 567, 9595, 19617, 19385, 1474, 15094, 8545, 21157, 18180, 6223, 12109, 4157, 48, 13724, 13197, 3742, 7196, 2432, 20122, 3156, 9582, 21198, 13444, 9230, 17826, 5660, 11350, 18690, 11203, 10598, 19166, 1023, 272, 6173, 5010, 2220, 3859, 17472, 13465, 1490, 20151, 1107, 13207, 2901, 11281, 3492, 18152, 18860, 18098, 2431, 7230, 3743, 21056, 15242, 6714, 3290, 12550, 2682, 20639, 4510, 4209, 5156, 15690, 3554, 12419, 14214, 3591, 7108, 16834, 5067, 19643, 11513, 18514, 15877, 11583, 4929, 7274, 12898, 8115, 19555, 8654, 4684, 20809, 18581, 15216, 17874, 10994, 19844, 5787, 4808, 9260, 16208, 18542, 5084, 20526, 20306, 15830, 10247, 2739, 18022, 114, 11371, 10391, 20061, 7365, 9949, 21123, 8398, 17750, 12670, 2556, 5347, 9646, 9555, 2766, 7430, 13508, 15975, 9356, 10219, 20750, 21078, 2265, 5893, 8976, 189, 7534, 17078, 7560, 2315, 1085, 15433, 16860, 2627, 8648, 20480, 7703, 16833, 7179, 3592, 10312, 7846, 13366, 18367, 1898, 10424, 20823, 453, 8210, 7256, 17334, 11535, 19256, 14654, 8990, 3696, 9562, 19998, 7589, 11590, 13280, 16998, 10623, 4, 15937, 6072, 2126, 3270, 3985, 7829, 4830, 851, 17454, 15765, 626, 6892, 5844, 3954, 8777, 19080, 6130, 6182, 3298, 16720, 997, 2538, 15481, 15718, 1958, 16138, 6997, 251, 6520, 468, 21022, 15772, 10837, 1445, 5413, 2730, 9676, 20509, 12065, 879, 3942, 5020, 6702, 19331, 5469, 3211, 8829, 14068, 17659, 11117, 12832, 1219, 17397, 7822, 385, 6790, 6301, 6193, 19935, 16083, 2195, 15567, 13532, 11230, 20706, 4165, 20091, 19797, 6845, 15609, 2086, 2253, 6858, 16103, 21154, 18279, 6137, 4160, 18302, 3263, 20116, 16947, 86, 17049, 250, 7056, 16139, 14914, 5947, 20856, 13261, 7518, 3871, 20272, 6910, 3824, 9242, 9076, 16471, 3601, 5802, 16265, 18575, 1155, 9347, 2532, 4290, 19679, 1750, 4045, 6426, 3973, 10687, 17903, 16274, 1523, 17566, 12031, 11218, 413, 16053, 6543, 15563, 13672, 10568, 15698, 1614, 884, 19879, 18531, 16125, 4229, 2710, 2848, 472, 6079, 362, 4404, 8083, 2373, 1354, 8460, 2521, 14869, 5995, 243, 8221, 12224, 18355, 1273, 703, 12182, 5128, 5003, 1688, 6434, 3017, 1164, 11958, 8703, 10844, 6458, 8283, 6638, 6298, 9411, 11471, 8037, 17191, 20458, 4176, 3823, 6988, 20273, 18784, 18316, 15457, 835, 13310, 12490, 1368, 2720, 15492, 20518, 11427, 8477, 18715, 16961, 2208, 5843, 7071, 627, 19453, 985, 3518, 6422, 15039, 3072, 8848, 11526, 2780, 10572, 8047, 5824, 19144, 6660, 8370, 35, 10929, 19093, 9284, 3103, 4350, 18968, 8980, 4126, 7268, 14955, 3004, 5144, 97, 15992, 19377, 16102, 7010, 2254, 20033, 5305, 1576, 12823, 1195, 8323, 1549, 5955, 8879, 16633, 15608, 7014, 19798, 18419, 14645, 4794, 20695, 19132, 11173, 21133, 9880, 6589, 14516, 2038, 1889, 2499, 19319, 12532, 9515, 4698, 8120, 11680, 18162, 18990, 10489, 10665, 20737, 9459, 1042, 9973, 5326, 5966, 15647, 10690, 1280, 16983, 4950, 12806, 7795, 19172, 1712, 2571, 6010, 3159, 3903, 6197, 26, 17163, 5834, 9227, 9047, 15009, 564, 16540, 9409, 6300, 7027, 386, 8754, 718, 14650, 17236, 3763, 5637, 10601, 8973, 19170, 7797, 15194, 3284, 18137, 18974, 1535, 8833, 10670, 5942, 16976, 19085, 3078, 1210, 9888, 9145, 11556, 6678, 11440, 4725, 16451, 15636, 20965, 9420, 20534, 10700, 14861, 1609, 10368, 13640, 5334, 17668, 2810, 15752, 4263, 17187, 19140, 6244, 5375, 12683, 17143, 20343, 17700, 19428, 12582, 15982, 14659, 14415, 19212, 1589, 9041, 1640, 16883, 4155, 12111, 1009, 1834, 18457, 21150, 5259, 6648, 10226, 3316, 175, 19185, 3289, 7192, 15243, 3148, 13278, 11592, 16291, 435, 19686, 21004, 13030, 8160, 19330, 7040, 5021, 14800, 8017, 16892, 5354, 12197, 13424, 7623, 5281, 13303, 17764, 18205, 13112, 843, 10008, 14742, 17532, 15484, 15693, 901, 12288, 12837, 11439, 6763, 11557, 1618, 16062, 4067, 864, 14929, 8675, 15268, 3847, 5884, 1515, 10913, 4589, 12077, 17558, 12961, 8369, 6877, 19145, 16569, 815, 3730, 1671, 6385, 5070, 13383, 5538, 15544, 10225, 6720, 5260, 5750, 16013, 6014, 5743, 1012, 12746, 1934, 6297, 6919, 8284, 13316, 9574, 994, 10711, 17121, 13983, 13296, 5114, 5025, 20860, 15100, 1948, 11858, 1878, 9381, 4183, 322, 12737, 11005, 12895, 8715, 11736, 9704, 1296, 2871, 13286, 13632, 4988, 16048, 19553, 8117, 2829, 14407, 16456, 104, 9604, 20530, 14463, 4014, 8360, 1992, 14156, 12260, 3092, 18466, 5266, 14515, 6835, 9881, 20877, 19354, 16288, 12440, 16506, 18578, 6275, 5362, 3596, 9237, 3358, 350, 20217, 5716, 5455, 929, 15760, 16157, 19692, 16699, 3389, 15594, 7598, 3724, 20513, 15257, 9533, 12871, 14778, 4032, 1683, 15164, 12213, 1058, 7573, 15663, 919, 5990, 11718, 15202, 11397, 16648, 7842, 15562, 6961, 16054, 12616, 15656, 3540, 12144, 1064, 18673, 9701, 5403, 8559, 15249, 2386, 17037, 2914, 8686, 10058, 12645, 3502, 8320, 9152, 594, 467, 7054, 252, 5651, 16771, 16317, 20762, 18051, 833, 15459, 6114, 631, 14885, 11240, 14563, 3718, 4728, 11358, 4370, 12123, 11713, 9119, 3928, 10685, 3975, 3920, 12051, 2056, 8507, 19176, 10487, 18992, 12835, 12290, 6058, 15213, 20668, 8332, 7976, 319, 13323, 10108, 13150, 10800, 16494, 18321, 12528, 8358, 4016, 8377, 14690, 17218, 17605, 8852, 17387, 11875, 8202, 18858, 18154, 16358, 18824, 5807, 8282, 6921, 10845, 2496, 9255, 755, 17675, 19756, 21192, 16227, 14549, 13233, 10196, 8302, 8056, 20107, 13738, 12800, 16573, 7498, 1331, 18647, 13216, 13119, 3016, 6927, 1689, 16431, 77, 12695, 9028, 2692, 3972, 6972, 4046, 12558, 15038, 6887, 3519, 17415, 13359, 12977, 2435, 988, 2131, 13492, 18501, 13705, 16750, 2010, 9653, 1228, 5729, 14922, 4762, 15587, 9901, 10427, 11896, 6230, 12358, 16980, 10867, 9862, 7368, 11580, 10209, 19865, 2139, 17683, 10548, 14495, 19641, 5069, 6654, 1672, 9952, 20632, 18727, 14310, 15255, 20515, 2237, 9443, 11, 3865, 2025, 17136, 4147, 10833, 13237, 9278, 8395, 8640, 20617, 14740, 10010, 8435, 18385, 8725, 265, 16278, 18196, 3672, 12263, 16616, 12307, 185, 3792, 19809, 4804, 12859, 18526, 10442, 12001, 6218, 18799, 13481, 13148, 10110, 15539, 2120, 12660, 5109, 14254, 15303, 14990, 3649, 10215, 4241, 508, 15519, 14843, 16488, 11918, 4450, 13051, 12085, 20384, 14577, 12575, 12392, 3402, 5142, 3006, 10781, 4791, 21147, 3614, 4864, 10062, 10862, 1561, 247, 8518, 13060, 11818, 6192, 7026, 6791, 9410, 6918, 6639, 1935, 13980, 14384, 18246, 10714, 17610, 16704, 6269, 12637, 11963, 18148, 4623, 8817, 8629, 8194, 9552, 8826, 8093, 16631, 8881, 5361, 6581, 18579, 20811, 2000, 16819, 12636, 6289, 16705, 19027, 17392, 16713, 15396, 5725, 20722, 690, 5945, 14916, 17601, 5812, 2338, 16896, 7405, 5204, 9960, 15581, 10633, 8948, 7674, 18843, 2733, 5374, 6743, 19141, 4774, 12201, 14454, 20686, 18257, 13340, 4339, 11906, 11400, 15626, 4485, 12357, 6400, 11897, 3222, 16112, 20678, 19606, 12108, 7237, 18181, 11762, 11330, 18798, 6344, 12002, 3994, 784, 17753, 1954, 8690, 14826, 14363, 18178, 21159, 2175, 16687, 3436, 16939, 4643, 17222, 7482, 3617, 8314, 25, 6801, 3904, 19502, 19934, 7025, 6302, 11819, 4845, 18017, 4850, 13070, 9338, 9233, 10530, 3297, 7065, 6131, 12710, 12461, 5876, 548, 19039, 15408, 5009, 7213, 273, 11754, 1327, 2836, 19863, 10211, 16330, 11924, 8375, 4018, 13830, 5737, 19875, 5035, 10923, 605, 19774, 14008, 12705, 20167, 5058, 8752, 388, 14623, 19302, 1007, 12113, 4424, 1803, 3443, 12844, 18144, 16901, 46, 4159, 7006, 18280, 7514, 19838, 15368, 12709, 6181, 7066, 19081, 9468, 17360, 10262, 10170, 20148, 60, 15229, 11607, 2508, 20800, 3662, 2874, 10522, 630, 6511, 15460, 16443, 8392, 15798, 11922, 16332, 13109, 20719, 18070, 17972, 19413, 2794, 12481, 11532, 13391, 5284, 10147, 3480, 13086, 18406, 4392, 10253, 1407, 1648, 12366, 15890, 7280, 19565, 14693, 9037, 10890, 5822, 8049, 361, 6947, 473, 5033, 19877, 886, 11249, 2125, 7081, 15938, 15454, 20068, 16149, 4649, 19069, 13396, 4010, 20894, 13003, 18664, 18625, 15212, 6487, 12291, 13451, 14471, 17966, 1472, 19387, 10477, 18856, 8204, 9530, 14701, 9853, 10853, 4955, 12643, 10060, 4866, 17114, 13327, 2623, 15190, 14763, 582, 2667, 14087, 3376, 3218, 5185, 17184, 16302, 13008, 12989, 19749, 18313, 3688, 5573, 21188, 15127, 9643, 2494, 10847, 13929, 5742, 6644, 16014, 9580, 3158, 6804, 2572, 192, 14056, 14536, 18102, 7278, 15892, 7985, 12689, 14717, 18864, 16256, 19742, 242, 6938, 14870, 735, 14687, 11717, 6550, 920, 9771, 20925, 8514, 10905, 13588, 7506, 12573, 14579, 17403, 2329, 20729, 4719, 10164, 9273, 16364, 894, 19419, 9870, 11267, 3700, 10815, 15646, 6815, 5327, 20204, 16747, 11414, 10350, 8897, 11730, 11600, 12426, 8878, 6849, 1550, 8679, 18938, 16188, 5319, 12457, 20855, 6994, 14915, 6260, 691, 16975, 6771, 10671, 10290, 17745, 12931, 7557, 2822, 17492, 12886, 10055, 5851, 15526, 3753, 3897, 13616, 17028, 16077, 17127, 12054, 18776, 20071, 9415, 8652, 19557, 2353, 3948, 17541, 7736, 17511, 9744, 16816, 587, 12381, 4874, 18446, 11934, 5409, 1149, 16774, 21230, 7501, 15785, 1204, 20949, 5492, 3774, 1021, 19168, 8975, 7123, 2266, 8994, 20245, 10159, 10980, 21100, 11565, 1514, 6668, 3848, 1410, 15116, 8541, 2318, 2651, 547, 6178, 12462, 2244, 750, 16518, 7613, 10105, 19405, 17431, 11856, 1950, 17795, 19581, 2897, 9111, 592, 9154, 11981, 16757, 13001, 20896, 7387, 4535, 14985, 15525, 5932, 10056, 8688, 1956, 15720, 11008, 3953, 7070, 6893, 2209, 15074, 16241, 19199, 7980, 1075, 20913, 9226, 6798, 17164, 11315, 8467, 20180, 4343, 20114, 3265, 4772, 19143, 6879, 8048, 6082, 10891, 20693, 4796, 5615, 20163, 14134, 4390, 18408, 2337, 6257, 17602, 2287, 290, 8281, 6460, 18825, 8871, 12241, 16264, 6982, 3602, 2214, 17228, 18796, 11332, 5310, 15179, 1182, 2932, 14343, 20415, 14737, 15136, 4807, 7158, 19845, 9989, 1827, 11771, 5242, 17289, 1854, 13353, 18291, 1763, 1870, 5149, 10446, 8022, 8745, 5646, 18611, 18710, 14189, 5532, 3716, 14565, 5557, 17697, 403, 20300, 13172, 10440, 18528, 14349, 732, 19014, 19346, 9424, 18902, 16012, 6646, 5261, 1258, 3059, 20353, 1832, 1011, 6643, 6015, 13930, 19408, 649, 19874, 6161, 13831, 1976, 11690, 16129, 5677, 20740, 14921, 6407, 1229, 18068, 20721, 6263, 15397, 15318, 17497, 9447, 13357, 17417, 11968, 5454, 6574, 20218, 13795, 12436, 20024, 11138, 14910, 19130, 20697, 12248, 15710, 14599, 11025, 981, 20361, 10002, 2566, 13093, 20793, 236, 12156, 3475, 8458, 1356, 2368, 2290, 9308, 20288, 13406, 14705, 14289, 7578, 745, 19053, 14228, 7718, 8737, 9457, 20739, 5732, 16130, 11321, 398, 20555, 20420, 3085, 2261, 11288, 14998, 10617, 16346, 2278, 19766, 16486, 14845, 11349, 7221, 17827, 11663, 3303, 17859, 14683, 13652, 12974, 16770, 6518, 253, 8484, 16368, 18610, 5771, 8746, 4523, 13592, 4615, 14403, 14236, 19164, 10600, 6783, 3764, 17292, 11939, 963, 16373, 2805, 17598, 11036, 4921, 1742, 7869, 12147, 9848, 15016, 16765, 7876, 8524, 13998, 10668, 8835, 20162, 5818, 4797, 14490, 285, 8799, 823, 2816, 1926, 18811, 17734, 7671, 10433, 15282, 14435, 10560, 3348, 10708, 16723, 9550, 8196, 9166, 8632, 14709, 17710, 19549, 18834, 16864, 1815, 13675, 14697, 20331, 19231, 17887, 10733, 10674, 8627, 8819, 10234, 4966, 4319, 16792, 21187, 6022, 3689, 8290, 8570, 18802, 12924, 19702, 17976, 7329, 13468, 18616, 10145, 5286, 16092, 14065, 17696, 5764, 14566, 20349, 1256, 5263, 10680, 14292, 19636, 10276, 430, 20409, 2005, 20539, 3033, 9298, 20159, 3771, 9000, 15543, 6651, 13384, 2642, 20292, 3050, 3715, 5767, 14190, 19292, 15402, 10242, 8356, 12530, 19321, 2440, 9955, 1321, 19335, 2769, 9839, 13950, 12770, 2536, 999, 20377, 11407, 7812, 1555, 4552, 8175, 10094, 1587, 19214, 7903, 10194, 13235, 10835, 15774, 2242, 12464, 18438, 14502, 16987, 18042, 8998, 3773, 5898, 20950, 20319, 14678, 5093, 10152, 19807, 3794, 14176, 20624, 3924, 21027, 9370, 9011, 226, 14198, 10413, 15748, 19008, 11304, 17112, 4868, 3210, 7038, 19332, 2687, 13484, 13747, 15348, 20046, 12315, 4838, 19769, 3524, 2890, 13331, 928, 6573, 5717, 11969, 12856, 15139, 9328, 10605, 4596, 4195, 11641, 18075, 18496, 16028, 16152, 7746, 19787, 3451, 3733, 685, 19481, 17772, 12793, 2563, 3119, 20125, 19753, 2377, 8297, 12089, 11586, 11216, 12033, 12913, 17407, 1424, 942, 14099, 11003, 12739, 464, 13144, 2729, 7048, 1446, 18707, 1148, 5906, 11935, 9131, 3020, 9732, 8558, 6534, 9702, 11738, 5054, 5051, 3241, 15952, 10784, 13240, 2093, 5230, 10658, 12627, 1720, 21039, 16448, 3721, 4787, 1986, 13942, 13838, 4143, 4515, 21169, 1364, 10828, 17197, 12682, 6742, 6245, 2734, 14076, 9667, 11042, 662, 20575, 11163, 1597, 20943, 9018, 3595, 6580, 6276, 8882, 15161, 13970, 15246, 13265, 12196, 6697, 16893, 19624, 8472, 19822, 2492, 9645, 7135, 2557, 10048, 13939, 12995, 17616, 7334, 10527, 7488, 17251, 220, 11881, 17667, 6750, 13641, 8279, 292, 4004, 10461, 20203, 5965, 6816, 9974, 3306, 2592, 12060, 12234, 12456, 5950, 16189, 12499, 9807, 16526, 8499, 21244, 14167, 15178, 5796, 11333, 3356, 9239, 1575, 6855, 20034, 10897, 12354, 13563, 17082, 1160, 18007, 15852, 10466, 16460, 19265, 270, 1025, 10014, 7706, 672, 10088, 16091, 5561, 10146, 6098, 13392, 13302, 6693, 7624, 13064, 4281, 18425, 3759, 7740, 14120, 11894, 10429, 10052, 19260, 8257, 8666, 14514, 6591, 18467, 10679, 5553, 1257, 5749, 6647, 6721, 21151, 14388, 1873, 4324, 19711, 3557, 9619, 8431, 16423, 11916, 16490, 7595, 8277, 13643, 12981, 17288, 5782, 11772, 21175, 12101, 2346, 15498, 14604, 15236, 11670, 10458, 2698, 10657, 5393, 2094, 4639, 16788, 3185, 8294, 16041, 10299, 2752, 15806, 5098, 16602, 13848, 11207, 17899, 10543, 12803, 20396, 3797, 10494, 18870, 12954, 16025, 10951, 18362, 9959, 6253, 7406, 16260, 14641, 1697, 1542, 11342, 20835, 14287, 14707, 8634, 2485, 8535, 1528, 19344, 19016, 19630, 14574, 17183, 6030, 3219, 2662, 19948, 1654, 9084, 1113, 4889, 2427, 17791, 1582, 2030, 4220, 15323, 4123, 708, 18218, 12074, 1313, 14226, 19055, 11178, 20042, 20050, 21178, 4313, 11160, 15962, 15689, 7185, 4210, 18337, 20716, 18208, 7357, 10445, 5775, 1871, 14390, 14240, 96, 6863, 3005, 6316, 3403, 17097, 857, 18026, 15022, 572, 9474, 16434, 17170, 20337, 13474, 19475, 5002, 6930, 12183, 19001, 2717, 14297, 17021, 16709, 9558, 15516, 15573, 9929, 17639, 55, 5024, 6629, 13297, 19290, 14192, 14253, 6336, 12661, 9992, 12333, 12785, 10510, 938, 2471, 1180, 15181, 16601, 5220, 15807, 13504, 806, 10151, 5488, 14679, 1558, 20008, 1734, 970, 1601, 19046, 20525, 7153, 18543, 9439, 20675, 11777, 1319, 9957, 18364, 10187, 3531, 12193, 11123, 19505, 13382, 6653, 6386, 19642, 7177, 16835, 2145, 18109, 3489, 2310, 15298, 15931, 8751, 6152, 20168, 9828, 5050, 5400, 11739, 3240, 5399, 5055, 9829, 3171, 16351, 17365, 10932, 1345, 18058, 11988, 14094, 2708, 4231, 233, 13042, 10922, 6159, 19876, 6077, 474, 9729, 4040, 17373, 11865, 17270, 20859, 6628, 5115, 56, 14799, 6701, 7041, 3943, 848, 10400, 7322, 13684, 9211, 16428, 18899, 2219, 7212, 6174, 15409, 2051, 16867, 8234, 1687, 6929, 5129, 19476, 17002, 20283, 3815, 3416, 4076, 11569, 2384, 15251, 1508, 13852, 13842, 16047, 6609, 13633, 9007, 15446, 14268, 2675, 16944, 9912, 10409, 10155, 11045, 20014, 3345, 14281, 19727, 10304, 20983, 14891, 3054, 2597, 8167, 4318, 5577, 10235, 20456, 17193, 1894, 14664, 8810, 9656, 14540, 20815, 12642, 6044, 10854, 4150, 20394, 12805, 6810, 16984, 4064, 15221, 8242, 18287, 2421, 590, 9113, 13175, 21020, 470, 2850, 20004, 1284, 17592, 20098, 4477, 14733, 488, 7273, 7171, 11584, 12091, 9203, 8782, 3048, 20294, 1741, 5628, 11037, 15083, 9326, 15141, 8141, 10097, 19090, 17368, 1459, 4298, 19850, 17538, 12324, 12634, 16821, 7726, 10631, 15583, 18972, 18139, 18494, 18077, 16202, 3885, 2206, 16963, 4669, 18464, 3094, 14787, 2426, 5178, 1114, 20200, 11975, 15275, 20356, 20939, 12764, 15601, 2640, 13386, 3813, 20285, 15617, 18445, 5909, 12382, 13776, 494, 4260, 3209, 5471, 17113, 6041, 10061, 6310, 3615, 7484, 3599, 16473, 9050, 7827, 3987, 16666, 19519, 3162, 2589, 2226, 13069, 6188, 18018, 4687, 7722, 18016, 6190, 11820, 295, 18224, 13096, 16484, 19768, 5461, 12316, 2519, 8462, 10741, 11394, 10398, 850, 7076, 7830, 17621, 12817, 15999, 9334, 19107, 10695, 12037, 16236, 2351, 19559, 14817, 21173, 11774, 16115, 4080, 17411, 3353, 18125, 10503, 9259, 7157, 5788, 15137, 12858, 6349, 19810, 209, 15861, 17529, 16523, 14489, 5614, 5819, 20694, 6841, 14646, 21146, 6313, 10782, 15954, 1985, 5386, 3722, 7600, 2191, 17147, 18746, 7393, 9782, 12172, 14265, 17649, 16389, 12200, 6242, 19142, 5826, 3266, 17118, 18249, 3014, 13121, 8152, 16409, 1482, 15586, 6405, 14923, 9332, 16001, 13655, 8020, 10448, 14772, 2929, 2715, 19003, 20501, 12904, 8839, 8908, 677, 16918, 3472, 8808, 14666, 2672, 20096, 17594, 10768, 11618, 1145, 18614, 13470, 16916, 679, 20498, 15377, 13637, 11357, 6505, 3719, 16450, 6761, 11441, 15934, 12751, 19731, 10163, 5977, 20730, 1276, 8644, 11562, 13246, 16554, 17446, 19818, 20684, 14456, 11841, 1974, 13833, 13583, 17304, 20403, 8385, 13034, 2827, 8119, 6827, 9516, 8002, 16536, 3804, 7749, 7959, 13243, 21103, 16675, 7721, 4848, 18019, 20808, 7165, 8655, 17930, 2103, 14591, 20435, 10704, 8448, 14808, 13752, 13955, 2907, 8780, 9205, 18463, 4894, 16964, 10752, 8600, 21207, 9032, 8920, 18636, 653, 2605, 20988, 9436, 2990, 7911, 19326, 4581, 1732, 20010, 17058, 19068, 6067, 16150, 16030, 7402, 2284, 17221, 6203, 16940, 9814, 16787, 5228, 2095, 11949, 1092, 2940, 8985, 14895, 8943, 11166, 9617, 3559, 12909, 3781, 4402, 364, 8816, 6285, 18149, 7649, 10613, 13155, 14971, 12369, 14402, 5642, 13593, 20580, 19497, 17206, 7363, 20063, 16673, 21105, 10027, 16850, 17823, 9341, 9851, 14703, 13408, 17140, 9402, 4194, 5448, 10606, 20642, 1477, 19494, 1311, 12076, 6665, 10914, 12070, 7383, 20613, 17261, 16393, 1731, 4654, 19327, 2846, 2712, 1185, 16641, 145, 16560, 13529, 12514, 8802, 12938, 19234, 12404, 2323, 10813, 3702, 12508, 19073, 15043, 17814, 12999, 16759, 20875, 9883, 11723, 2833, 21234, 8174, 5510, 1556, 14681, 17861, 3585, 9858, 3638, 14959, 14981, 2223, 3309, 4227, 16127, 11692, 18485, 3856, 14984, 5854, 7388, 4497, 19241, 13570, 17950, 14186, 20253, 10540, 15651, 11700, 13591, 5644, 8747, 13459, 19593, 12167, 19136, 17837, 21168, 5381, 4144, 7380, 17918, 4208, 7187, 20640, 10608, 3429, 10957, 3506, 9971, 1044, 15286, 9836, 7543, 14838, 19240, 4533, 7389, 8062, 13904, 9267, 15391, 8249, 16690, 375, 11787, 13561, 12356, 6232, 15627, 13374, 423, 7888, 8274, 15597, 14732, 4933, 20099, 15345, 20, 3189, 9263, 20882, 13798, 18371, 2403, 11576, 18193, 18654, 13350, 11434, 16609, 16022, 18065, 1264, 16929, 15674, 63, 1351, 17679, 17158, 12374, 13050, 6324, 11919, 10646, 12278, 8452, 2272, 8671, 18115, 9072, 12553, 13695, 3606, 12346, 2506, 11609, 20074, 11504, 15337, 20663, 19248, 14978, 8614, 16343, 13524, 13964, 1802, 6145, 12114, 3245, 20974, 9497, 7537, 11233, 13545, 14140, 14071, 16183, 19105, 9336, 13072, 11157, 12567, 729, 9824, 19309, 8082, 6945, 363, 4626, 3782, 11221, 16644, 3427, 10610, 789, 17075, 9500, 10252, 6093, 18407, 5815, 14135, 18623, 18666, 2414, 15660, 19435, 19197, 16243, 13016, 7444, 3801, 1433, 773, 10117, 1638, 9043, 11543, 19955, 12122, 6503, 11359, 12106, 19608, 14521, 17095, 3405, 12719, 2476, 8300, 10198, 7592, 13231, 14551, 15896, 1626, 18910, 14994, 13845, 18967, 6870, 3104, 15109, 21204, 8402, 3909, 20113, 5829, 20181, 19794, 11905, 6236, 13341, 17715, 8887, 18184, 7778, 16515, 20571, 16503, 17778, 12760, 9365, 17864, 18831, 19710, 5255, 1874, 2553, 19984, 16791, 5576, 4967, 8168, 18333, 12565, 11159, 5160, 21179, 17812, 15045, 16607, 11436, 8710, 18573, 16267, 11338, 1132, 14248, 21164, 258, 19849, 4911, 1460, 17800, 8576, 1268, 1996, 2759, 19678, 6976, 2533, 14354, 19042, 16354, 16581, 10498, 8213, 18424, 5278, 13065, 19465, 21094, 3196, 20418, 20557, 15306, 14479, 2165, 11759, 8890, 14851, 10383, 19968, 14438, 16300, 17186, 6746, 15753, 3208, 4870, 495, 560, 20604, 20489, 20324, 12985, 1635, 7968, 14164, 10627, 3037, 1772, 16249, 967, 12592, 3321, 11486, 507, 6330, 10216, 13793, 20220, 18394, 18002, 277, 11661, 17829, 232, 5039, 2709, 6951, 16126, 4541, 3310, 8366, 162, 1707, 7632, 15322, 5173, 2031, 12723, 7253, 10501, 18127, 18096, 18862, 14719, 18336, 5155, 7186, 4511, 17919, 19621, 2341, 17310, 8966, 7815, 21162, 14250, 21000, 12733, 10346, 11640, 5447, 4597, 9403, 1238, 16598, 2182, 12943, 12327, 2615, 67, 13321, 321, 6621, 9382, 3981, 8029, 3810, 20485, 3822, 6912, 20459, 16854, 11750, 13714, 14130, 13690, 18429, 7685, 15949, 20090, 7017, 20707, 10114, 13701, 18301, 7005, 6138, 47, 7235, 12110, 6727, 16884, 17845, 16109, 20393, 4953, 10855, 10832, 6371, 17137, 7379, 4514, 5382, 13839, 11615, 10663, 10491, 9944, 15777, 16382, 15209, 7923, 1847, 17982, 16479, 3001, 10537, 14617, 7267, 6867, 8981, 707, 5171, 15324, 9196, 19195, 19437, 3371, 12488, 13312, 409, 19223, 14877, 17103, 13871, 7840, 16650, 11848, 8565, 14509, 907, 11176, 19057, 16466, 2504, 12348, 18329, 19101, 17259, 20615, 8642, 1278, 10692, 3569, 16796, 8876, 12428, 11017, 21222, 14450, 15416, 9935, 19598, 9060, 17410, 4814, 16116, 913, 11568, 4996, 3417, 13178, 7259, 3169, 9831, 1061, 7872, 863, 6674, 16063, 15220, 4948, 16985, 14504, 2110, 9397, 13211, 14335, 792, 16286, 19356, 20058, 10420, 15872, 8568, 8292, 3187, 22, 12557, 6425, 6973, 1751, 16638, 13887, 17372, 5030, 9730, 3022, 459, 13102, 7833, 21032, 1682, 6558, 14779, 3645, 18964, 16605, 15047, 13768, 12161, 13759, 4000, 19034, 15450, 2454, 13829, 6163, 8376, 6473, 8359, 6598, 14464, 17487, 20893, 6064, 13397, 860, 20829, 2696, 10460, 5330, 293, 11822, 19033, 4023, 13760, 15911, 21030, 7835, 783, 6216, 12003, 18107, 2147, 17152, 635, 16665, 4857, 7828, 7078, 3271, 13922, 8028, 4181, 9383, 16222, 391, 7990, 3919, 6497, 10686, 6971, 6427, 2693, 7442, 13018, 317, 7978, 19201, 21114, 20610, 1036, 8267, 16006, 15468, 19396, 17484, 15614, 9311, 8776, 7069, 5845, 11009, 2868, 12322, 17540, 5917, 2354, 7665, 16545, 847, 5019, 7042, 880, 18907, 17045, 12284, 1723, 2123, 11251, 11108, 10176, 11492, 1531, 19431, 10684, 6499, 9120, 19532, 21026, 5482, 20625, 9874, 12050, 6496, 3976, 7991, 8069, 13992, 14153, 9715, 7860, 767, 13548, 20112, 4345, 8403, 3107, 1568, 19501, 6196, 6802, 3160, 19521, 17913, 13557, 13615, 5929, 3754, 3313, 20473, 7551, 18272, 10122, 11780, 15122, 10988, 19646, 2205, 4897, 16203, 10318, 2158, 16336, 19791, 8422, 7361, 17208, 16220, 9385, 18324, 11058, 20271, 6990, 7519, 13772, 13836, 13944, 2024, 6374, 12, 12396, 14782, 9375, 17471, 7210, 2221, 14983, 4537, 18486, 1341, 20029, 14219, 13428, 1646, 1409, 5883, 6669, 15269, 18921, 17787, 8335, 15827, 19826, 12188, 17168, 16436, 17897, 11209, 17729, 14829, 7891, 15530, 9282, 19095, 9964, 1339, 18488, 1573, 9241, 6987, 6911, 4177, 20486, 7317, 1843, 15381, 9394, 3415, 4998, 20284, 4878, 13387, 20484, 4179, 8030, 3238, 11741, 19785, 7748, 4694, 16537, 1432, 4379, 7445, 9942, 10493, 5212, 20397, 14175, 5485, 19808, 6351, 186, 1487, 7332, 17618, 13105, 19665, 19221, 411, 11220, 4401, 4627, 12910, 11873, 17389, 14040, 7785, 1020, 5897, 5493, 8999, 5541, 20160, 8837, 12906, 379, 1852, 17291, 5636, 6784, 17237, 357, 7739, 5276, 18426, 15314, 8364, 3312, 3896, 5930, 15527, 11803, 2659, 11900, 18719, 2162, 18173, 13252, 21055, 7195, 7231, 13198, 20890, 13512, 15335, 11506, 20298, 405, 684, 5438, 3452, 1670, 6656, 816, 2059, 17627, 12310, 20512, 6564, 7599, 4786, 5387, 16449, 4727, 6506, 14564, 5766, 5533, 3051, 17579, 1398, 16340, 8926, 17300, 15333, 13514, 10484, 19269, 11270, 12507, 4565, 10814, 5969, 11268, 19271, 9561, 7091, 8991, 11709, 2067, 9171, 14586, 8289, 5572, 6023, 18314, 18786, 1910, 19725, 14283, 9219, 7755, 2750, 10301, 1122, 1498, 2938, 1094, 3090, 12262, 6356, 18197, 17536, 19852, 21051, 13986, 2975, 11129, 13284, 2873, 6118, 20801, 9768, 7639, 19964, 16314, 1152, 16509, 10482, 13516, 18443, 15619, 10214, 6332, 14991, 15438, 18963, 4030, 14780, 12398, 1810, 17880, 10534, 14958, 4546, 9859, 19512, 8660, 8253, 15907, 13916, 17461, 8145, 13418, 16421, 8433, 10012, 1027, 2857, 19189, 17522, 8940, 21066, 12445, 8313, 6200, 7483, 4863, 6311, 21148, 18459, 11319, 16132, 21195, 2045, 12345, 4439, 13696, 2979, 2213, 5801, 6983, 16472, 4861, 7485, 9236, 6579, 5363, 9019, 10311, 7107, 7180, 14215, 10133, 1778, 10506, 9857, 4548, 17862, 9367, 15914, 14500, 18440, 9615, 11168, 10167, 19364, 20493, 14796, 1494, 18874, 19897, 16795, 4092, 10693, 19109, 14859, 10702, 20437, 20908, 11785, 377, 12908, 4629, 9618, 5253, 19712, 12418, 7183, 15691, 15486, 20847, 905, 14511, 1822, 8060, 7391, 18748, 1932, 12748, 7, 12143, 6539, 15657, 1701, 10282, 13783, 7907, 16912, 12363, 12192, 5075, 10188, 11028, 501, 935, 10296, 2889, 5459, 19770, 1757, 10039, 17414, 6421, 6888, 986, 2437, 15643, 13579, 12385, 10918, 9886, 1212, 8329, 18346, 9970, 4505, 10958, 15310, 8319, 6525, 12646, 12850, 14111, 8580, 20464, 15035, 19296, 7647, 18151, 7201, 11282, 2309, 5063, 18110, 8089, 7945, 14558, 3045, 2814, 825, 13085, 6096, 10148, 1767, 15814, 8457, 5695, 12157, 8807, 4745, 16919, 8490, 485, 3200, 2545, 3116, 10005, 12867, 2327, 17405, 12915, 13275, 18821, 16073, 19668, 7645, 19298, 15384, 1669, 3732, 5439, 19788, 16953, 12674, 11685, 1253, 1969, 12843, 6143, 1804, 21143, 11647, 13319, 69, 16938, 6205, 16688, 8251, 8662, 10287, 10736, 10956, 4507, 10609, 4398, 16645, 11909, 12018, 14027, 15590, 9587, 17016, 21018, 13177, 4075, 4997, 3816, 9395, 2112, 16732, 82, 18917, 19945, 11931, 132, 12718, 4364, 17096, 5141, 6317, 12393, 13078, 18453, 8770, 11832, 12599, 771, 1435, 13224, 11273, 17945, 15593, 6567, 16700, 17665, 11883, 16922, 2419, 18289, 13355, 9449, 10024, 18839, 152, 3217, 6032, 14088, 10256, 13126, 12487, 4118, 19438, 17608, 10716, 7582, 3177, 3279, 8309, 2017, 15666, 10517, 20451, 349, 6577, 9238, 5308, 11334, 18124, 4812, 17412, 10041, 16033, 10707, 5600, 10561, 14280, 4976, 20015, 13816, 10138, 3328, 1630, 1866, 10876, 1727, 17349, 7693, 3029, 9177, 13868, 16737, 17042, 1629, 3341, 10139, 11075, 20449, 10519, 10778, 11485, 4244, 12593, 16567, 19147, 174, 6718, 10227, 20472, 3895, 3755, 8365, 4226, 4542, 2224, 2591, 5324, 9975, 17858, 5657, 11664, 19207, 7678, 16719, 7064, 6183, 10531, 13669, 20506, 11328, 11764, 12549, 7191, 6715, 19186, 10909, 10272, 18136, 6777, 15195, 19778, 19065, 8308, 3365, 3178, 15145, 1837, 2188, 1546, 15683, 13921, 3984, 7079, 2127, 19401, 17117, 4771, 5827, 20115, 7003, 18303, 933, 503, 12294, 20276, 1665, 12227, 8522, 7878, 9455, 8739, 2178, 7855, 7949, 2854, 17013, 20973, 4422, 12115, 20088, 15951, 5398, 5052, 11740, 3808, 8031, 8132, 13962, 13526, 16403, 15060, 16400, 16563, 442, 18509, 14102, 21136, 7850, 20391, 16111, 6228, 11898, 2661, 5184, 6031, 3377, 153, 18055, 7943, 8091, 8828, 7037, 5470, 4869, 4261, 15754, 12252, 19305, 11457, 9523, 19801, 2544, 3468, 486, 14735, 20417, 4277, 21095, 18034, 13307, 19903, 16206, 9262, 4473, 21, 4049, 8293, 5226, 16789, 19986, 20019, 15522, 529, 15144, 3278, 3366, 7583, 9607, 15804, 2754, 16350, 5048, 9830, 4072, 7260, 8732, 20429, 1015, 8438, 2588, 4854, 19520, 3902, 6803, 6011, 9581, 7227, 20123, 3121, 17035, 2388, 14051, 18819, 13277, 6712, 15244, 13972, 12537, 2678, 9245, 17257, 19103, 16185, 17761, 13161, 20374, 12390, 12577, 16806, 12178, 11449, 1379, 8584, 11623, 12544, 10407, 9914, 17895, 16438, 10747, 17034, 3154, 20124, 5432, 2564, 10004, 3466, 2546, 10976, 17964, 14473, 2276, 16348, 2756, 1567, 3907, 8404, 15108, 4349, 6871, 9285, 14963, 16627, 13601, 17756, 14049, 2390, 14786, 4892, 18465, 6593, 12261, 3674, 1095, 9568, 14425, 2260, 5671, 20421, 2600, 8035, 11473, 10069, 1209, 6768, 19086, 17503, 7998, 2013, 8847, 6885, 15040, 91, 14011, 15027, 9488, 12361, 16914, 13472, 20339, 119, 1966, 20352, 5747, 1259, 9672, 16783, 2596, 4970, 14892, 17578, 3714, 5534, 20293, 4924, 8783, 2813, 3484, 14559, 8138, 532, 16097, 13893, 10065, 1771, 4249, 10628, 18888, 9297, 5544, 20540, 16080, 9176, 3334, 7694, 2943, 20953, 16407, 8154, 458, 4038, 9731, 5406, 9132, 1163, 6926, 6435, 13120, 4768, 18250, 7375, 21128, 19285, 446, 11483, 10780, 6315, 5143, 6864, 14956, 10536, 4130, 16480, 18236, 13875, 1469, 2186, 1839, 20602, 562, 15011, 7910, 4657, 9437, 18545, 1787, 19739, 7399, 10044, 10653, 12246, 20699, 2212, 3604, 13697, 17357, 11128, 3666, 13987, 12519, 12702, 94, 14242, 15113, 13736, 20109, 9804, 7793, 12808, 13006, 16304, 18829, 17866, 7895, 15471, 19487, 1173, 9747, 2620, 2297, 21212, 10322, 20650, 7547, 17088, 14245, 17987, 20317, 20952, 3027, 7695, 8984, 4635, 1093, 3676, 1499, 15225, 17562, 2464, 14342, 5793, 1183, 2714, 4754, 14773, 8722, 11863, 17375, 10192, 7905, 13785, 8900, 17150, 2149, 18451, 13080, 16933, 8685, 6529, 17038, 16095, 534, 9591, 19078, 8779, 4673, 13956, 579, 12919, 17741, 11280, 7203, 13208, 1416, 9110, 5863, 19582, 9024, 14315, 19977, 2294, 13330, 5458, 3525, 10297, 16043, 11291, 16172, 11063, 7882, 14146, 19352, 20879, 7450, 16780, 18847, 10776, 10521, 6117, 3663, 13285, 6612, 1297, 12321, 3951, 11010, 20232, 12813, 14888, 12525, 9388, 18893, 13586, 10907, 19188, 3624, 1028, 17012, 3248, 7950, 1961, 20003, 4938, 471, 6949, 2711, 4579, 19328, 8162, 15155, 16858, 15435, 18913, 11463, 1394, 19862, 6169, 1328, 21233, 4555, 11724, 1450, 14406, 6605, 8118, 4700, 13035, 16967, 15972, 17491, 5936, 7558, 17080, 13565, 13336, 1925, 5609, 824, 3483, 3046, 8784, 15751, 6748, 17669, 11635, 7732, 17597, 5631, 16374, 15341, 9316, 21119, 168, 19099, 18331, 8170, 17850, 12480, 6102, 19414, 14526, 100, 17637, 9931, 12336, 12043, 16579, 16356, 18156, 14657, 15984, 10571, 6882, 11527, 19450, 10525, 7336, 20551, 19570, 19830, 18595, 7541, 9838, 5520, 19336, 7429, 7132, 9556, 16711, 17394, 19909, 17422, 19677, 4292, 1997, 1566, 3109, 16349, 3173, 15805, 5222, 10300, 3680, 7756, 14836, 7545, 20652, 8108, 20303, 7587, 20000, 20806, 18021, 7148, 10248, 1360, 9735, 14075, 5373, 6246, 18844, 9675, 7047, 5414, 13145, 2690, 9030, 21209, 8389, 14902, 10808, 15491, 6901, 1369, 14296, 5125, 19002, 4753, 2930, 1184, 4578, 2847, 6950, 4230, 5040, 14095, 16166, 11811, 18261, 19463, 13067, 2228, 10101, 10656, 5232, 10459, 4006, 20830, 7441, 3971, 6428, 9029, 2727, 13146, 13483, 5467, 19333, 1323, 1078, 20638, 7189, 12551, 9074, 9244, 3144, 12538, 16943, 4983, 14269, 20095, 4742, 14667, 14975, 439, 14086, 6034, 583, 20921, 11929, 19947, 5183, 3220, 11899, 3750, 11804, 21240, 9108, 1418, 18477, 13709, 546, 5878, 2319, 10456, 11672, 539, 20027, 1343, 10934, 20291, 5536, 13385, 4880, 15602, 15479, 2540, 20103, 16513, 7780, 15686, 11105, 11497, 13441, 7528, 8647, 7113, 16861, 2584, 15189, 6038, 13328, 2296, 2954, 9748, 9224, 20915, 66, 4187, 12328, 16587, 20597, 10364, 11956, 1166, 21085, 19544, 20987, 4660, 654, 19917, 14811, 8034, 3083, 20422, 8166, 4969, 3055, 16784, 7900, 12059, 5323, 3307, 2225, 4853, 3163, 8439, 8245, 15188, 2625, 16862, 18836, 21108, 1072, 10130, 8419, 20184, 14713, 11549, 7532, 191, 6009, 6805, 1713, 8796, 18947, 13092, 5700, 10003, 3118, 5433, 12794, 19115, 9898, 14030, 10047, 5346, 7136, 12671, 19983, 4322, 1875, 2359, 11954, 10366, 1611, 10975, 3115, 3467, 3201, 19802, 15838, 20102, 2637, 15480, 7061, 998, 5516, 12771, 14353, 4289, 6977, 9348, 17501, 19088, 10099, 2230, 10797, 19657, 11454, 616, 14868, 6940, 8461, 4836, 12317, 12153, 19457, 13498, 13292, 13255, 111, 13401, 7885, 20799, 6120, 11608, 4437, 12347, 4101, 16467, 13857, 17704, 19318, 6831, 1890, 9254, 6456, 10846, 6018, 9644, 5349, 19823, 20309, 18780, 7314, 20607, 8534, 5193, 8635, 20469, 13138, 8080, 19311, 20382, 12087, 8299, 4362, 12720, 9194, 15326, 1179, 5102, 939, 18760, 13936, 8953, 975, 14341, 2934, 17563, 19340, 11255, 8918, 9034, 20193, 13488, 8595, 13828, 4020, 15451, 9918, 15030, 14906, 7769, 12678, 15680, 8326, 10355, 19152, 9302, 20630, 9954, 5524, 19322, 15642, 3516, 987, 6417, 12978, 20121, 7229, 7197, 18099, 7973, 17790, 5177, 4890, 14788, 15443, 12379, 589, 4944, 18288, 3384, 16923, 1540, 1699, 15659, 4386, 18667, 142, 11224, 17870, 21098, 10982, 13574, 15002, 18517, 11575, 4468, 18372, 10474, 11798, 11227, 20140, 8044, 12625, 10660, 10771, 15199, 13046, 14785, 3096, 14050, 3152, 17036, 6531, 15250, 4994, 11570, 9924, 8598, 10754, 16039, 8296, 5429, 19754, 17677, 1353, 6943, 8084, 18944, 288, 2289, 5692, 1357, 9506, 1466, 7437, 13521, 10620, 18214, 11953, 2551, 1876, 11860, 18388, 7664, 3947, 5918, 19558, 4820, 16237, 19031, 11824, 15497, 5238, 12102, 9695, 20368, 17309, 4205, 19622, 16895, 6256, 5813, 18409, 9787, 256, 21166, 17839, 1305, 20728, 5979, 17404, 3463, 12868, 12133, 10812, 4567, 12405, 19627, 10455, 2650, 5879, 8542, 1084, 7117, 7561, 727, 12569, 15297, 5062, 3490, 11283, 19912, 13164, 18878, 20962, 12452, 18681, 8158, 13032, 8387, 21211, 2953, 2621, 13329, 2892, 19978, 11538, 9307, 5691, 2369, 289, 5810, 17603, 17220, 4645, 7403, 16898, 14380, 12270, 19765, 5665, 16347, 3111, 14474, 19715, 8670, 4445, 8453, 2136, 7711, 11707, 8993, 5892, 7124, 21079, 2152, 11287, 5670, 3086, 14426, 10761, 14759, 8415, 20032, 6857, 7011, 2087, 19671, 8428, 9065, 16123, 18533, 16497, 749, 5874, 12463, 5500, 15775, 9946, 9865, 9442, 6377, 20516, 15494, 1904, 16060, 1620, 10796, 2527, 10100, 2701, 13068, 4852, 2590, 3308, 4543, 14982, 3858, 7211, 5011, 18900, 9426, 17248, 17227, 5800, 3603, 2980, 20700, 15073, 5842, 6894, 16962, 4896, 3886, 19647, 16163, 725, 7563, 12040, 21219, 12902, 20503, 15566, 7022, 16084, 10072, 17146, 4784, 7601, 1545, 3275, 1838, 2996, 1470, 17968, 12942, 4190, 16599, 15183, 7854, 3251, 8740, 16686, 6207, 21160, 7817, 11657, 18340, 12471, 14182, 15120, 11782, 11758, 4272, 14480, 18172, 3747, 18720, 11151, 16335, 3882, 10319, 14376, 11966, 17419, 11286, 2263, 21080, 18450, 2919, 17151, 3991, 18108, 5065, 16836, 11914, 16425, 10555, 17682, 6391, 19866, 7710, 2270, 8454, 18688, 11352, 13491, 6415, 989, 19960, 19400, 3269, 7080, 6073, 11250, 3936, 1724, 12659, 6338, 15540, 553, 14410, 10077, 13901, 9081, 16731, 3413, 9396, 4061, 14505, 15006, 16476, 15424, 14371, 14590, 4681, 17931, 21076, 20752, 20691, 10893, 18805, 11948, 4638, 5229, 5394, 13241, 7961, 7619, 7643, 19670, 2252, 7012, 15610, 10650, 14033, 20227, 15354, 12275, 14469, 13453, 14442, 19538, 462, 12741, 14757, 10763, 1982, 20981, 10306, 9170, 3693, 11710, 21073, 14533, 17961, 10341, 18391, 17626, 3728, 817, 8506, 6494, 12052, 17129, 1813, 16866, 5007, 15410, 13270, 17283, 136, 12344, 3608, 21196, 9584, 17948, 13572, 10984, 1888, 6833, 14517, 19661, 15743, 13347, 9192, 12722, 4219, 5174, 1583, 17464, 20839, 17135, 6373, 3866, 13945, 12028, 13496, 19459, 917, 15665, 3363, 8310, 16680, 8846, 3074, 7999, 9652, 6410, 16751, 16717, 7680, 20538, 5546, 20410, 20919, 585, 16818, 6272, 20812, 1565, 2758, 4293, 1269, 9713, 14155, 6596, 8361, 11196, 15979, 12993, 13941, 5385, 4788, 15955, 20980, 2071, 10764, 17544, 9980, 17551, 11689, 5735, 13832, 4707, 11842, 10037, 1759, 12842, 3445, 1254, 20351, 3061, 120, 18239, 20804, 20002, 2852, 7951, 16137, 7058, 15719, 5848, 8689, 6213, 17754, 13603, 17794, 5866, 11857, 6625, 15101, 20243, 8996, 18044, 9793, 20635, 11424, 16843, 13168, 18769, 868, 13979, 6296, 6640, 12747, 3544, 18749, 14419, 8718, 15724, 18810, 5608, 2817, 13337, 16594, 16669, 18404, 13088, 14546, 14210, 15781, 18563, 19927, 15728, 18481, 13821, 19724, 3685, 18787, 9995, 9755, 19720, 16059, 2234, 15495, 11826, 8757, 19883, 10423, 7102, 18368, 371, 14663, 4962, 17194, 1192, 9253, 2498, 6832, 2039, 10985, 11081, 17673, 757, 13334, 13567, 713, 10551, 9380, 6623, 11859, 2358, 2552, 4323, 5256, 14389, 5148, 5776, 1764, 809, 10875, 3339, 1631, 14006, 19776, 15197, 10773, 9453, 7880, 11065, 13910, 11432, 13352, 5780, 17290, 3766, 380, 1288, 19121, 17981, 4133, 7924, 11143, 15380, 3819, 7318, 15509, 20601, 2995, 2187, 3276, 15146, 18456, 6724, 1010, 5745, 20354, 15277, 11380, 11770, 5784, 9990, 12663, 9628, 8059, 3548, 14512, 8668, 19717, 17319, 10566, 13674, 5588, 16865, 2053, 17130, 17879, 3642, 12399, 9725, 21048, 1390, 21142, 3442, 6144, 4425, 13965, 9721, 18471, 10725, 20621, 14359, 20265, 21011, 9095, 18733, 7752, 19229, 20333, 19738, 2987, 18546, 8183, 16970, 156, 20568, 753, 9257, 10505, 3588, 10134, 20446, 7774, 16119, 16248, 4248, 3038, 10066, 20563, 15813, 3478, 10149, 808, 1869, 5777, 18292, 20077, 12841, 1971, 10038, 3522, 19771, 16657, 19939, 668, 16637, 4044, 6974, 19680, 17344, 15054, 1316, 10125, 16177, 7868, 5627, 4922, 20295, 10380, 11389, 17613, 12590, 969, 5089, 20009, 4653, 4582, 16394, 18088, 17348, 3337, 10877, 12658, 2122, 3937, 12285, 21038, 5390, 12628, 12128, 17323, 224, 9013, 8795, 2570, 6806, 19173, 20788, 8149, 7631, 4223, 163, 18642, 263, 8727, 10281, 3538, 15658, 2416, 1541, 5200, 14642, 13133, 14082, 12596, 15330, 18897, 16430, 6433, 6928, 5004, 8235, 13968, 15163, 6557, 4033, 21033, 697, 18475, 1420, 9623, 20081, 166, 21121, 9951, 6384, 6655, 3731, 3453, 15385, 18353, 12226, 3257, 20277, 19650, 308, 8487, 11886, 347, 20453, 7789, 16729, 9083, 5181, 19949, 11313, 17166, 12190, 12365, 6090, 1408, 3850, 13429, 570, 15024, 9142, 16882, 6729, 9042, 4375, 10118, 7967, 4253, 12986, 11653, 14005, 1865, 3340, 3329, 17043, 18909, 4355, 15897, 12778, 8843, 18928, 10795, 2232, 16061, 6676, 11558, 11552, 883, 6956, 15699, 10974, 2548, 10367, 6753, 14862, 16181, 14073, 9737, 10260, 17362, 19045, 5087, 971, 19586, 20942, 5366, 11164, 8945, 8097, 10451, 18724, 9796, 9040, 6731, 19213, 5507, 10095, 8143, 17463, 2029, 5175, 17792, 13605, 19161, 18998, 12822, 6854, 5306, 9240, 3826, 18489, 16958, 14274, 19500, 3906, 3108, 2757, 1998, 20813, 14542, 246, 6307, 10863, 20007, 5091, 14680, 4551, 5511, 7813, 8968, 13741, 8678, 5954, 6850, 8324, 15682, 3274, 2189, 7602, 11341, 5199, 1698, 2417, 16924, 15995, 17693, 8832, 6774, 18975, 12580, 19430, 3931, 11493, 19343, 5191, 8536, 7427, 19338, 17565, 6967, 16275, 10946, 20129, 8497, 16528, 11087, 10912, 6667, 5885, 11566, 915, 19461, 18263, 13851, 4992, 15252, 21008, 891, 312, 10285, 8664, 8259, 15224, 2937, 3677, 1123, 15819, 18873, 3573, 14797, 58, 20150, 7207, 13466, 7331, 3790, 187, 8978, 18970, 15585, 4764, 16410, 15789, 17726, 19493, 4593, 20643, 15093, 7242, 19386, 6053, 17967, 2185, 2997, 13876, 7436, 2365, 9507, 17443, 13502, 15809, 17799, 4297, 4912, 17369, 12828, 1067, 16908, 9345, 1157, 14234, 14405, 2831, 11725, 18047, 18706, 5412, 7049, 10838, 11096, 15763, 17456, 14899, 16446, 21041, 7325, 13223, 3394, 772, 4378, 3802, 16538, 566, 7247, 12776, 15899, 18758, 941, 5421, 17408, 9062, 9622, 1678, 18476, 2655, 9109, 2899, 13209, 9399, 12686, 13734, 15115, 5882, 3849, 1647, 6091, 10254, 14090, 15463, 11261, 9434, 20990, 16950, 16339, 3712, 17580, 199, 19861, 2838, 11464, 8066, 21141, 1806, 21049, 19854, 18412, 15081, 11039, 14857, 19111, 13540, 13596, 8583, 3131, 11450, 10362, 20599, 15511, 15089, 16215, 15173, 20364, 14295, 2719, 6902, 12491, 19349, 10827, 5379, 21170, 8556, 9734, 2737, 10249, 9505, 2367, 5693, 8459, 6942, 2374, 17678, 4455, 64, 20917, 20412, 7941, 18057, 5044, 10933, 2645, 20028, 3854, 18487, 3828, 9965, 18942, 8086, 877, 12067, 20594, 18646, 6439, 7499, 21232, 2835, 6170, 11755, 20911, 1077, 2685, 19334, 5522, 9956, 5079, 11778, 10124, 1746, 15055, 14225, 5167, 12075, 4591, 19495, 20582, 8373, 11926, 20727, 2331, 17840, 9319, 18586, 16067, 19596, 9937, 12320, 2870, 6613, 9705, 16877, 9128, 12476, 20968, 20259, 19120, 1850, 381, 13609, 17591, 4936, 20005, 10865, 16982, 6812, 10691, 4094, 8643, 4717, 20731, 702, 6933, 18356, 18956, 9712, 1995, 4294, 8577, 18695, 16928, 4459, 18066, 1231, 13879, 9671, 3058, 5748, 5262, 5554, 20350, 1968, 3446, 11686, 14160, 13661, 18507, 444, 19287, 18398, 16312, 19966, 10385, 19690, 16159, 19516, 16597, 4192, 9404, 10203, 16272, 17905, 7434, 13878, 1262, 18067, 5728, 6408, 9654, 8812, 15537, 10112, 20709, 18603, 19907, 17396, 7031, 12833, 18994, 14393, 15945, 10353, 8328, 3510, 9887, 6767, 3079, 10070, 16086, 1200, 20948, 5900, 15786, 8935, 20947, 1206, 16087, 72, 9150, 8322, 6852, 12824, 9252, 1892, 17195, 10830, 10857, 14106, 13885, 16640, 4577, 2713, 2931, 5794, 15180, 5101, 2472, 15327, 11835, 9639, 16814, 9746, 2956, 19488, 8409, 12542, 11625, 19573, 21084, 2609, 11957, 6925, 3018, 9133, 18006, 5299, 17083, 14233, 1453, 9346, 6979, 18576, 16508, 3656, 16315, 16773, 5905, 5410, 18708, 18613, 4737, 11619, 13192, 14805, 7512, 18282, 11446, 7700, 17339, 16905, 15421, 17985, 14247, 4303, 11339, 7604, 8270, 18816, 14021, 18094, 18129, 15818, 1497, 3678, 10302, 19729, 12753, 9740, 10872, 344, 20199, 4888, 5179, 9085, 7715, 10021, 18851, 13206, 7205, 20152, 11683, 12676, 7771, 11078, 15125, 21190, 19758, 14043, 20143, 9567, 3089, 3675, 2939, 4636, 11950, 15707, 17479, 12413, 15633, 15432, 7116, 2316, 8543, 15096, 16192, 11422, 20637, 2684, 1324, 20912, 5837, 7981, 10129, 2580, 21109, 12781, 15419, 16907, 1456, 12829, 18672, 6537, 12145, 7871, 4070, 9832, 7572, 6554, 12214, 18791, 7762, 11704, 7494, 9361, 20904, 20134, 16362, 9275, 10787, 15921, 15285, 4503, 9972, 6818, 9460, 7690, 7636, 923, 8266, 3963, 20611, 7385, 20898, 14674, 15534, 7455, 17011, 2856, 3625, 10013, 5292, 271, 7215, 19167, 5896, 3775, 7786, 10238, 18383, 8437, 3165, 20430, 12745, 6642, 5744, 1833, 6725, 12112, 6147, 19303, 12254, 15359, 11091, 20590, 12388, 20376, 5515, 2537, 7062, 16721, 10710, 6634, 9575, 20712, 280, 19959, 2130, 6416, 2436, 3517, 6889, 19454, 239, 20360, 5703, 11026, 10190, 17377, 14260, 14340, 2466, 8954, 17991, 19585, 1600, 5088, 1735, 12591, 4246, 16250, 17435, 16372, 5633, 11940, 15560, 7844, 10314, 18606, 15714, 18200, 16326, 19509, 10870, 9742, 17513, 20845, 15488, 8078, 13140, 18505, 13663, 722, 14098, 5420, 1425, 18759, 2470, 5103, 10511, 10295, 3527, 502, 3261, 18304, 298, 15759, 6572, 5456, 13332, 759, 16994, 8265, 1038, 7637, 9770, 5989, 6551, 15664, 2019, 19460, 1512, 11567, 4078, 16117, 7776, 18186, 21131, 11175, 4105, 14510, 3550, 20848, 21036, 12287, 6682, 15694, 19994, 19282, 18189, 15503, 19418, 5973, 16365, 311, 1505, 21009, 20267, 15547, 11248, 6075, 19878, 6955, 1615, 11553, 18906, 3941, 7043, 12066, 1335, 8087, 18112, 8860, 20249, 15735, 9843, 20759, 13978, 1937, 18770, 9163, 14928, 6673, 4068, 7873, 20828, 4008, 13398, 18025, 5139, 17098, 16297, 8445, 16036, 17453, 7075, 4831, 10399, 5018, 3944, 16546, 12865, 10007, 6688, 13113, 20818, 15702, 19245, 331, 19901, 13309, 6905, 15458, 6513, 18052, 16973, 693, 15577, 18165, 18650, 13084, 3482, 2815, 5610, 8800, 12516, 18083, 20235, 8505, 2058, 3729, 6657, 16570, 10546, 17685, 342, 10874, 1868, 1765, 10150, 5095, 13505, 11114, 19473, 13476, 10173, 17924, 10731, 17889, 20901, 19591, 13461, 11013, 16285, 4057, 14336, 17074, 4396, 10611, 7651, 12668, 17752, 6215, 3995, 7836, 12613, 18766, 8112, 11021, 17935, 17355, 13699, 10116, 4377, 1434, 3395, 12600, 14138, 13547, 3912, 7861, 17438, 17071, 17428, 13933, 644, 16993, 926, 13333, 1884, 17674, 6454, 9256, 1781, 20569, 16517, 5873, 2245, 16498, 8346, 19052, 5684, 7579, 17955, 9922, 11572, 14204, 9185, 8938, 17524, 14686, 5993, 14871, 19013, 5756, 14350, 9823, 4408, 12568, 2313, 7562, 2202, 16164, 14097, 944, 13664, 11644, 14649, 6787, 8755, 11828, 14493, 10550, 1881, 13568, 19243, 15704, 18217, 5170, 4124, 8982, 7697, 12181, 6932, 1274, 20732, 11430, 13912, 18474, 1680, 21034, 20850, 15576, 830, 16974, 5944, 6261, 20723, 9774, 11182, 19480, 5437, 3734, 406, 21092, 19467, 20497, 4733, 16917, 4747, 8909, 20586, 15881, 10087, 5289, 7707, 7655, 16636, 1753, 19940, 12877, 21216, 12339, 20574, 5369, 11043, 10157, 20247, 8862, 10333, 9181, 19916, 2604, 4661, 18637, 10886, 19873, 5739, 19409, 18255, 20688, 16992, 761, 13934, 18762, 12716, 134, 17285, 20214, 13865, 16664, 3989, 17153, 12608, 14884, 6510, 6115, 10523, 19452, 6891, 7072, 15766, 17326, 11376, 20769, 11070, 11946, 18807, 11296, 14867, 2523, 11455, 19307, 9826, 20170, 18566, 14061, 16740, 10642, 16655, 19773, 6157, 10924, 20648, 10324, 20646, 10926, 18299, 13703, 18503, 13142, 466, 6522, 9153, 5861, 9112, 4943, 2422, 12380, 5911, 16817, 2002, 20920, 2666, 6035, 14764, 12918, 2905, 13957, 11768, 11382, 11809, 16168, 9473, 5136, 15023, 1644, 13430, 9594, 7246, 1430, 16539, 6794, 15010, 2993, 20603, 4258, 496, 19150, 10357, 15429, 16454, 14409, 2118, 15541, 9002, 18268, 19038, 6177, 5877, 2652, 13710, 10018, 14231, 17085, 11136, 20026, 2647, 11673, 20257, 20970, 9590, 2911, 16096, 3042, 8139, 15143, 3180, 15523, 14987, 20560, 11476, 326, 9322, 19943, 18919, 15271, 16531, 19974, 20548, 9820, 12774, 7249, 10583, 14429, 11791, 15571, 15518, 6329, 4242, 11487, 13449, 12293, 3260, 934, 3528, 11029, 14123, 172, 19149, 559, 4259, 4871, 13777, 477, 11405, 20379, 7272, 4931, 14734, 3199, 3469, 8491, 13622, 11265, 9872, 20627, 10180, 11404, 492, 13778, 9728, 5032, 6078, 6948, 2849, 4939, 21021, 7053, 6521, 595, 13143, 5416, 12740, 2075, 19539, 13101, 4037, 3023, 8155, 15551, 21014, 8209, 7099, 20824, 13363, 18740, 15130, 17588, 11482, 3009, 19286, 1248, 18508, 3229, 16564, 14085, 2669, 14976, 19250, 19685, 6708, 16292, 8608, 8135, 20408, 5548, 10277, 11346, 10824, 14149, 20797, 7887, 4482, 13375, 20388, 17242, 18554, 13809, 13025, 12698, 9906, 16052, 6963, 11219, 3784, 19222, 4115, 13313, 21091, 683, 3735, 20299, 5762, 17698, 20345, 214, 20554, 5674, 11322, 7424, 8791, 15301, 14256, 7989, 3978, 16223, 14622, 6150, 8753, 6789, 7028, 7823, 13628, 13608, 1287, 1851, 3767, 12907, 3561, 11786, 4489, 16691, 11367, 14662, 1896, 18369, 13800, 11985, 16778, 7452, 8815, 4625, 4403, 6946, 6080, 8050, 17509, 7738, 3761, 17238, 15186, 8247, 15393, 13863, 20216, 6576, 3359, 20452, 1659, 11887, 20198, 1116, 10873, 811, 17686, 9465, 9493, 19924, 20173, 15413, 12024, 18632, 21184, 19900, 838, 19246, 20665, 18584, 9321, 524, 11477, 15262, 12736, 6620, 4184, 13322, 6482, 7977, 3968, 13019, 21045, 13781, 10284, 1504, 892, 16366, 8486, 1662, 19651, 15884, 12232, 12062, 12313, 20048, 20044, 15350, 15758, 931, 18305, 18223, 4843, 11821, 4003, 5331, 8280, 5809, 2288, 2370, 18945, 8798, 5612, 14491, 11830, 8772, 19958, 991, 20713, 11660, 4235, 18003, 16828, 11753, 6172, 7214, 1024, 5293, 19266, 19179, 10944, 16277, 6359, 8726, 1704, 18643, 16590, 11814, 19848, 4300, 21165, 2334, 9788, 8483, 5650, 6519, 7055, 6998, 17050, 8517, 6306, 1562, 14543, 8220, 6937, 5996, 19743, 20359, 983, 19455, 12155, 5697, 20794, 13041, 5038, 4232, 17830, 8073, 16309, 20780, 14197, 5478, 9012, 1716, 17324, 15768, 11880, 5337, 17252, 13415, 17215, 19568, 20553, 400, 20346, 8963, 19528, 15860, 4802, 19811, 13925, 7567, 8229, 20934, 7469, 11523, 19442, 19860, 1396, 17581, 7264, 7955, 7996, 17505, 14055, 6008, 2573, 7533, 7121, 8977, 1486, 3791, 6352, 12308, 17629, 8805, 12159, 13770, 7521, 9124, 9538, 19184, 6717, 3317, 19148, 498, 14124, 18985, 19098, 2800, 21120, 1675, 20082, 18641, 1706, 4224, 8367, 12963, 7935, 20842, 20567, 1783, 16971, 18054, 3216, 3378, 18840, 10268, 15362, 9685, 8005, 16559, 4575, 16642, 11223, 2412, 18668, 20178, 8469, 12408, 12343, 2047, 17284, 640, 12717, 3407, 11932, 18448, 21082, 19575, 11299, 14109, 12852, 12611, 7838, 13873, 18238, 1965, 3062, 20340, 10075, 14412, 11370, 7146, 18023, 13400, 2512, 13256, 13182, 19858, 19444, 17808, 9603, 6602, 16457, 14937, 17636, 2791, 14527, 15991, 6862, 5145, 14241, 2971, 12703, 14010, 3070, 15041, 19075, 13433, 17048, 7000, 16948, 20992, 18916, 3411, 16733, 15869, 19886, 12694, 6431, 16432, 9476, 16009, 9149, 1198, 16088, 16937, 3438, 13320, 4186, 2616, 20916, 1350, 4456, 15675, 15228, 6123, 20149, 1492, 14798, 5023, 5116, 17640, 19205, 11666, 14024, 7806, 13723, 7234, 4158, 6139, 16902, 12848, 12648, 16584, 12218, 18524, 12861, 18951, 18297, 10928, 6875, 8371, 20584, 8911, 9208, 19050, 8348, 10231, 17162, 6800, 6198, 8315, 12556, 4048, 3188, 4474, 15346, 13749, 19920, 18415, 16695, 13076, 12395, 3864, 6375, 9444, 18592, 12142, 3542, 12749, 15936, 7083, 10624, 21247]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-product-permutation-l6-s6/tests/check.py b/tasks/construct-rlve-prefix-product-permutation-l6-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3d93850acd79cc0f8fff05cdbb0c63aabc484815 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l6-s6/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("perm"), n, 1, n, "perm") + if len(set(p)) != n: + raise Invalid("not a permutation") + seen, acc = set(), 1 + for v in p: + acc = acc * v % n + if acc in seen: + raise Invalid(f"prefix product residue {acc} repeats") + seen.add(acc) + return None, {} diff --git a/tasks/construct-rlve-prefix-product-permutation-l6-s6/tests/instance.json b/tasks/construct-rlve-prefix-product-permutation-l6-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a8674d27c514255e9ab362cdbcb7162c38e8181c --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l6-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 21247, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l6-s6/tests/run.py b/tasks/construct-rlve-prefix-product-permutation-l6-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l6-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prefix-product-permutation-l6-s6/tests/test.sh b/tasks/construct-rlve-prefix-product-permutation-l6-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l6-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prefix-sum-permutation-l3-s1/environment/Dockerfile b/tasks/construct-rlve-prefix-sum-permutation-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l3-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prefix-sum-permutation-l3-s1/environment/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4302ad5f603997023d37acda4e9ebbd4f1265640 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 106, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l3-s1/solution/solve.sh b/tasks/construct-rlve-prefix-sum-permutation-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..24a4ef1ad4376635ca35c3d835ab47788e30f359 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l3-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"perm": [106, 1, 104, 3, 102, 5, 100, 7, 98, 9, 96, 11, 94, 13, 92, 15, 90, 17, 88, 19, 86, 21, 84, 23, 82, 25, 80, 27, 78, 29, 76, 31, 74, 33, 72, 35, 70, 37, 68, 39, 66, 41, 64, 43, 62, 45, 60, 47, 58, 49, 56, 51, 54, 53, 52, 55, 50, 57, 48, 59, 46, 61, 44, 63, 42, 65, 40, 67, 38, 69, 36, 71, 34, 73, 32, 75, 30, 77, 28, 79, 26, 81, 24, 83, 22, 85, 20, 87, 18, 89, 16, 91, 14, 93, 12, 95, 10, 97, 8, 99, 6, 101, 4, 103, 2, 105]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-sum-permutation-l3-s1/tests/check.py b/tasks/construct-rlve-prefix-sum-permutation-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..60c3e0996cdfa8673fd7f34ad70cccb789b17654 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l3-s1/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("perm"), n, 1, n, "perm") + if len(set(p)) != n: + raise Invalid("not a permutation") + seen, acc = set(), 0 + for v in p: + acc = (acc + v) % n + if acc in seen: + raise Invalid(f"prefix sum residue {acc} repeats") + seen.add(acc) + return None, {} diff --git a/tasks/construct-rlve-prefix-sum-permutation-l3-s1/tests/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4302ad5f603997023d37acda4e9ebbd4f1265640 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 106, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l3-s1/tests/run.py b/tasks/construct-rlve-prefix-sum-permutation-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l3-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prefix-sum-permutation-l3-s1/tests/test.sh b/tasks/construct-rlve-prefix-sum-permutation-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l3-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prefix-sum-permutation-l3-s6/environment/Dockerfile b/tasks/construct-rlve-prefix-sum-permutation-l3-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l3-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prefix-sum-permutation-l3-s6/environment/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l3-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..948ebfb20602114562212b983e46dd0a23e7190c --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l3-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 182, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l3-s6/solution/solve.sh b/tasks/construct-rlve-prefix-sum-permutation-l3-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..94c593bf8b52e75dd5be2fe44d51aab4ec62db77 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l3-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"perm": [182, 1, 180, 3, 178, 5, 176, 7, 174, 9, 172, 11, 170, 13, 168, 15, 166, 17, 164, 19, 162, 21, 160, 23, 158, 25, 156, 27, 154, 29, 152, 31, 150, 33, 148, 35, 146, 37, 144, 39, 142, 41, 140, 43, 138, 45, 136, 47, 134, 49, 132, 51, 130, 53, 128, 55, 126, 57, 124, 59, 122, 61, 120, 63, 118, 65, 116, 67, 114, 69, 112, 71, 110, 73, 108, 75, 106, 77, 104, 79, 102, 81, 100, 83, 98, 85, 96, 87, 94, 89, 92, 91, 90, 93, 88, 95, 86, 97, 84, 99, 82, 101, 80, 103, 78, 105, 76, 107, 74, 109, 72, 111, 70, 113, 68, 115, 66, 117, 64, 119, 62, 121, 60, 123, 58, 125, 56, 127, 54, 129, 52, 131, 50, 133, 48, 135, 46, 137, 44, 139, 42, 141, 40, 143, 38, 145, 36, 147, 34, 149, 32, 151, 30, 153, 28, 155, 26, 157, 24, 159, 22, 161, 20, 163, 18, 165, 16, 167, 14, 169, 12, 171, 10, 173, 8, 175, 6, 177, 4, 179, 2, 181]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-sum-permutation-l3-s6/tests/check.py b/tasks/construct-rlve-prefix-sum-permutation-l3-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..60c3e0996cdfa8673fd7f34ad70cccb789b17654 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l3-s6/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("perm"), n, 1, n, "perm") + if len(set(p)) != n: + raise Invalid("not a permutation") + seen, acc = set(), 0 + for v in p: + acc = (acc + v) % n + if acc in seen: + raise Invalid(f"prefix sum residue {acc} repeats") + seen.add(acc) + return None, {} diff --git a/tasks/construct-rlve-prefix-sum-permutation-l3-s6/tests/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l3-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..948ebfb20602114562212b983e46dd0a23e7190c --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l3-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 182, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l3-s6/tests/run.py b/tasks/construct-rlve-prefix-sum-permutation-l3-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l3-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prefix-sum-permutation-l3-s6/tests/test.sh b/tasks/construct-rlve-prefix-sum-permutation-l3-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l3-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prefix-sum-permutation-l3-s8/environment/Dockerfile b/tasks/construct-rlve-prefix-sum-permutation-l3-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l3-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prefix-sum-permutation-l3-s8/environment/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l3-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c367599e89786b07e3aab00c56c21dcea7f3e002 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l3-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 262, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l3-s8/solution/solve.sh b/tasks/construct-rlve-prefix-sum-permutation-l3-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7f7c6751fa016e66bdd563c3437d507e4bbaf26c --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l3-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"perm": [262, 1, 260, 3, 258, 5, 256, 7, 254, 9, 252, 11, 250, 13, 248, 15, 246, 17, 244, 19, 242, 21, 240, 23, 238, 25, 236, 27, 234, 29, 232, 31, 230, 33, 228, 35, 226, 37, 224, 39, 222, 41, 220, 43, 218, 45, 216, 47, 214, 49, 212, 51, 210, 53, 208, 55, 206, 57, 204, 59, 202, 61, 200, 63, 198, 65, 196, 67, 194, 69, 192, 71, 190, 73, 188, 75, 186, 77, 184, 79, 182, 81, 180, 83, 178, 85, 176, 87, 174, 89, 172, 91, 170, 93, 168, 95, 166, 97, 164, 99, 162, 101, 160, 103, 158, 105, 156, 107, 154, 109, 152, 111, 150, 113, 148, 115, 146, 117, 144, 119, 142, 121, 140, 123, 138, 125, 136, 127, 134, 129, 132, 131, 130, 133, 128, 135, 126, 137, 124, 139, 122, 141, 120, 143, 118, 145, 116, 147, 114, 149, 112, 151, 110, 153, 108, 155, 106, 157, 104, 159, 102, 161, 100, 163, 98, 165, 96, 167, 94, 169, 92, 171, 90, 173, 88, 175, 86, 177, 84, 179, 82, 181, 80, 183, 78, 185, 76, 187, 74, 189, 72, 191, 70, 193, 68, 195, 66, 197, 64, 199, 62, 201, 60, 203, 58, 205, 56, 207, 54, 209, 52, 211, 50, 213, 48, 215, 46, 217, 44, 219, 42, 221, 40, 223, 38, 225, 36, 227, 34, 229, 32, 231, 30, 233, 28, 235, 26, 237, 24, 239, 22, 241, 20, 243, 18, 245, 16, 247, 14, 249, 12, 251, 10, 253, 8, 255, 6, 257, 4, 259, 2, 261]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-sum-permutation-l3-s8/tests/check.py b/tasks/construct-rlve-prefix-sum-permutation-l3-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..60c3e0996cdfa8673fd7f34ad70cccb789b17654 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l3-s8/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("perm"), n, 1, n, "perm") + if len(set(p)) != n: + raise Invalid("not a permutation") + seen, acc = set(), 0 + for v in p: + acc = (acc + v) % n + if acc in seen: + raise Invalid(f"prefix sum residue {acc} repeats") + seen.add(acc) + return None, {} diff --git a/tasks/construct-rlve-prefix-sum-permutation-l3-s8/tests/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l3-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c367599e89786b07e3aab00c56c21dcea7f3e002 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l3-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 262, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l3-s8/tests/run.py b/tasks/construct-rlve-prefix-sum-permutation-l3-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l3-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prefix-sum-permutation-l3-s8/tests/test.sh b/tasks/construct-rlve-prefix-sum-permutation-l3-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l3-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prime-graph-coloring-l2-s0/environment/Dockerfile b/tasks/construct-rlve-prime-graph-coloring-l2-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l2-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prime-graph-coloring-l2-s0/environment/instance.json b/tasks/construct-rlve-prime-graph-coloring-l2-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..135cd7e5c881ce49ed5a9d1e0d29fc7d502c65cc --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l2-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 36, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l2-s0/solution/solve.sh b/tasks/construct-rlve-prime-graph-coloring-l2-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..925f0dfbc6b145f449998e2c9ec8097e984763cc --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l2-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prime-graph-coloring-l2-s0/tests/check.py b/tasks/construct-rlve-prime-graph-coloring-l2-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b3736f1375f1862241999142c975ced361b8fcb5 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l2-s0/tests/check.py @@ -0,0 +1,20 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + sieve = [True] * (n + 1) + sieve[0] = False + if n >= 1: + sieve[1] = False + for i in range(2, int(n ** 0.5) + 1): + if sieve[i]: + for j in range(i * i, n + 1, i): + sieve[j] = False + for p in range(2, n): + if sieve[p]: + for u in range(n - p): + if c[u] == c[u + p]: + raise Invalid(f"vertices {u + 1} and {u + p + 1} (difference {p}) share a colour") + return None, {} diff --git a/tasks/construct-rlve-prime-graph-coloring-l2-s0/tests/instance.json b/tasks/construct-rlve-prime-graph-coloring-l2-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..135cd7e5c881ce49ed5a9d1e0d29fc7d502c65cc --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l2-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 36, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l2-s0/tests/run.py b/tasks/construct-rlve-prime-graph-coloring-l2-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l2-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prime-graph-coloring-l2-s0/tests/test.sh b/tasks/construct-rlve-prime-graph-coloring-l2-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l2-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prime-graph-coloring-l2-s7/environment/Dockerfile b/tasks/construct-rlve-prime-graph-coloring-l2-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l2-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prime-graph-coloring-l2-s7/environment/instance.json b/tasks/construct-rlve-prime-graph-coloring-l2-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..751234899ad62c7c740e970f66713a23c590ea6a --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l2-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 15, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l2-s7/solution/solve.sh b/tasks/construct-rlve-prime-graph-coloring-l2-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..74b29e99e2c3871e7b4d9ca5573ecd8a4b2f4409 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l2-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prime-graph-coloring-l2-s7/tests/check.py b/tasks/construct-rlve-prime-graph-coloring-l2-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b3736f1375f1862241999142c975ced361b8fcb5 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l2-s7/tests/check.py @@ -0,0 +1,20 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + sieve = [True] * (n + 1) + sieve[0] = False + if n >= 1: + sieve[1] = False + for i in range(2, int(n ** 0.5) + 1): + if sieve[i]: + for j in range(i * i, n + 1, i): + sieve[j] = False + for p in range(2, n): + if sieve[p]: + for u in range(n - p): + if c[u] == c[u + p]: + raise Invalid(f"vertices {u + 1} and {u + p + 1} (difference {p}) share a colour") + return None, {} diff --git a/tasks/construct-rlve-prime-graph-coloring-l2-s7/tests/instance.json b/tasks/construct-rlve-prime-graph-coloring-l2-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..751234899ad62c7c740e970f66713a23c590ea6a --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l2-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 15, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l2-s7/tests/run.py b/tasks/construct-rlve-prime-graph-coloring-l2-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l2-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prime-graph-coloring-l2-s7/tests/test.sh b/tasks/construct-rlve-prime-graph-coloring-l2-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l2-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prime-graph-coloring-l2-s9/environment/Dockerfile b/tasks/construct-rlve-prime-graph-coloring-l2-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l2-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prime-graph-coloring-l2-s9/environment/instance.json b/tasks/construct-rlve-prime-graph-coloring-l2-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0e57ee7704e17a00fa9b483d2a5c883fe6714f9a --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l2-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 31, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l2-s9/solution/solve.sh b/tasks/construct-rlve-prime-graph-coloring-l2-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b829b1f18a73535d3019c903d6262ce7ae942840 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l2-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prime-graph-coloring-l2-s9/tests/check.py b/tasks/construct-rlve-prime-graph-coloring-l2-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b3736f1375f1862241999142c975ced361b8fcb5 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l2-s9/tests/check.py @@ -0,0 +1,20 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + sieve = [True] * (n + 1) + sieve[0] = False + if n >= 1: + sieve[1] = False + for i in range(2, int(n ** 0.5) + 1): + if sieve[i]: + for j in range(i * i, n + 1, i): + sieve[j] = False + for p in range(2, n): + if sieve[p]: + for u in range(n - p): + if c[u] == c[u + p]: + raise Invalid(f"vertices {u + 1} and {u + p + 1} (difference {p}) share a colour") + return None, {} diff --git a/tasks/construct-rlve-prime-graph-coloring-l2-s9/tests/instance.json b/tasks/construct-rlve-prime-graph-coloring-l2-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0e57ee7704e17a00fa9b483d2a5c883fe6714f9a --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l2-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 31, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l2-s9/tests/run.py b/tasks/construct-rlve-prime-graph-coloring-l2-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l2-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prime-graph-coloring-l2-s9/tests/test.sh b/tasks/construct-rlve-prime-graph-coloring-l2-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l2-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prime-graph-coloring-l6-s1/environment/Dockerfile b/tasks/construct-rlve-prime-graph-coloring-l6-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l6-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prime-graph-coloring-l6-s1/environment/instance.json b/tasks/construct-rlve-prime-graph-coloring-l6-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8c1553a6f7b6356d46901c55bdc7cfd85136a181 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l6-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 1258, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l6-s1/solution/solve.sh b/tasks/construct-rlve-prime-graph-coloring-l6-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ce28337f73734dba6a9d6d8e361e49df086959bf --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l6-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prime-graph-coloring-l6-s1/tests/check.py b/tasks/construct-rlve-prime-graph-coloring-l6-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b3736f1375f1862241999142c975ced361b8fcb5 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l6-s1/tests/check.py @@ -0,0 +1,20 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + sieve = [True] * (n + 1) + sieve[0] = False + if n >= 1: + sieve[1] = False + for i in range(2, int(n ** 0.5) + 1): + if sieve[i]: + for j in range(i * i, n + 1, i): + sieve[j] = False + for p in range(2, n): + if sieve[p]: + for u in range(n - p): + if c[u] == c[u + p]: + raise Invalid(f"vertices {u + 1} and {u + p + 1} (difference {p}) share a colour") + return None, {} diff --git a/tasks/construct-rlve-prime-graph-coloring-l6-s1/tests/instance.json b/tasks/construct-rlve-prime-graph-coloring-l6-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8c1553a6f7b6356d46901c55bdc7cfd85136a181 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l6-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 1258, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l6-s1/tests/run.py b/tasks/construct-rlve-prime-graph-coloring-l6-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l6-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prime-graph-coloring-l6-s1/tests/test.sh b/tasks/construct-rlve-prime-graph-coloring-l6-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l6-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prime-graph-coloring-l6-s6/environment/Dockerfile b/tasks/construct-rlve-prime-graph-coloring-l6-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l6-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prime-graph-coloring-l6-s6/environment/instance.json b/tasks/construct-rlve-prime-graph-coloring-l6-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b4eadddae5313033412ed5ecc20875dc3b3cf5a3 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l6-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 1470, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l6-s6/solution/solve.sh b/tasks/construct-rlve-prime-graph-coloring-l6-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..996fa580eff9ea6369f98f51b5aa0046c1d921bc --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l6-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prime-graph-coloring-l6-s6/tests/check.py b/tasks/construct-rlve-prime-graph-coloring-l6-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b3736f1375f1862241999142c975ced361b8fcb5 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l6-s6/tests/check.py @@ -0,0 +1,20 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + sieve = [True] * (n + 1) + sieve[0] = False + if n >= 1: + sieve[1] = False + for i in range(2, int(n ** 0.5) + 1): + if sieve[i]: + for j in range(i * i, n + 1, i): + sieve[j] = False + for p in range(2, n): + if sieve[p]: + for u in range(n - p): + if c[u] == c[u + p]: + raise Invalid(f"vertices {u + 1} and {u + p + 1} (difference {p}) share a colour") + return None, {} diff --git a/tasks/construct-rlve-prime-graph-coloring-l6-s6/tests/instance.json b/tasks/construct-rlve-prime-graph-coloring-l6-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b4eadddae5313033412ed5ecc20875dc3b3cf5a3 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l6-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 1470, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l6-s6/tests/run.py b/tasks/construct-rlve-prime-graph-coloring-l6-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l6-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prime-graph-coloring-l6-s6/tests/test.sh b/tasks/construct-rlve-prime-graph-coloring-l6-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l6-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prime-graph-coloring-l6-s8/environment/Dockerfile b/tasks/construct-rlve-prime-graph-coloring-l6-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l6-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prime-graph-coloring-l6-s8/environment/instance.json b/tasks/construct-rlve-prime-graph-coloring-l6-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9a4259e6b03d914bd8bb987dd6ee5951c221dffd --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l6-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 1658, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l6-s8/solution/solve.sh b/tasks/construct-rlve-prime-graph-coloring-l6-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d309d80952ffef59c40635b0c7c44b22df6aa6d0 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l6-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prime-graph-coloring-l6-s8/tests/check.py b/tasks/construct-rlve-prime-graph-coloring-l6-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b3736f1375f1862241999142c975ced361b8fcb5 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l6-s8/tests/check.py @@ -0,0 +1,20 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + sieve = [True] * (n + 1) + sieve[0] = False + if n >= 1: + sieve[1] = False + for i in range(2, int(n ** 0.5) + 1): + if sieve[i]: + for j in range(i * i, n + 1, i): + sieve[j] = False + for p in range(2, n): + if sieve[p]: + for u in range(n - p): + if c[u] == c[u + p]: + raise Invalid(f"vertices {u + 1} and {u + p + 1} (difference {p}) share a colour") + return None, {} diff --git a/tasks/construct-rlve-prime-graph-coloring-l6-s8/tests/instance.json b/tasks/construct-rlve-prime-graph-coloring-l6-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9a4259e6b03d914bd8bb987dd6ee5951c221dffd --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l6-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 1658, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l6-s8/tests/run.py b/tasks/construct-rlve-prime-graph-coloring-l6-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l6-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prime-graph-coloring-l6-s8/tests/test.sh b/tasks/construct-rlve-prime-graph-coloring-l6-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l6-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-round-robin-scores-l4-s6/environment/Dockerfile b/tasks/construct-rlve-round-robin-scores-l4-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l4-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-round-robin-scores-l4-s6/environment/instance.json b/tasks/construct-rlve-round-robin-scores-l4-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bf583d268da2c508d56e30c4c79802504f5c9729 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l4-s6/environment/instance.json @@ -0,0 +1 @@ +{"W": [14, 17, 14, 7, 15, 18, 13, 16, 13, 17, 11, 13, 14], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l4-s6/solution/solve.sh b/tasks/construct-rlve-round-robin-scores-l4-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a5ff19d35ee39e698714927815c4a5bd0c1abf73 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l4-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"A": ["0121111111111", "1022112111110", "0001111121121", "1010110100101", "1111011021211", "1111101111222", "1012110010121", "1111212021001", "1102011001112", "1112112110210", "1111001210011", "1102100211101", "1211101102110"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-round-robin-scores-l4-s6/tests/check.py b/tasks/construct-rlve-round-robin-scores-l4-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..214446acaa90ce170daad3989b42317353060f9d --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l4-s6/tests/check.py @@ -0,0 +1,24 @@ +from run import Invalid + + +def check(inst, ans): + W = inst["W"] + n = len(W) + A = ans.get("A") + if not isinstance(A, list) or len(A) != n: + raise Invalid(f"A must be a list of {n} strings") + for r in A: + if not isinstance(r, str) or len(r) != n or set(r) - {"0", "1", "2"}: + raise Invalid(f"each row must be a string of {n} digits 0/1/2") + for i in range(n): + if A[i][i] != "0": + raise Invalid("diagonal must be 0") + w = 0 + for j in range(n): + if i != j: + if int(A[i][j]) + int(A[j][i]) != 2: + raise Invalid(f"A[{i}][{j}] + A[{j}][{i}] != 2") + w += 3 * (A[i][j] == "2") + (A[i][j] == "1") + if w != W[i]: + raise Invalid(f"W[{i}] = {w}, need {W[i]}") + return None, {} diff --git a/tasks/construct-rlve-round-robin-scores-l4-s6/tests/instance.json b/tasks/construct-rlve-round-robin-scores-l4-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bf583d268da2c508d56e30c4c79802504f5c9729 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l4-s6/tests/instance.json @@ -0,0 +1 @@ +{"W": [14, 17, 14, 7, 15, 18, 13, 16, 13, 17, 11, 13, 14], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l4-s6/tests/run.py b/tasks/construct-rlve-round-robin-scores-l4-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l4-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-round-robin-scores-l4-s6/tests/test.sh b/tasks/construct-rlve-round-robin-scores-l4-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l4-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-round-robin-scores-l4-s8/environment/Dockerfile b/tasks/construct-rlve-round-robin-scores-l4-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l4-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-round-robin-scores-l4-s8/environment/instance.json b/tasks/construct-rlve-round-robin-scores-l4-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9e3d59a3bbbd637b12dfc91979766ba1c57949f7 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l4-s8/environment/instance.json @@ -0,0 +1 @@ +{"W": [13, 11, 14, 12, 14, 12, 14, 12, 11, 12, 12, 12, 11], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l4-s8/solution/solve.sh b/tasks/construct-rlve-round-robin-scores-l4-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2f14b3907acff2bc3425c41b27a831675dae693a --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l4-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"A": ["0101111111112", "1011110111111", "2101111111111", "1110111111111", "1111011121111", "1111101111111", "1211110111111", "1111111011111", "1111011101111", "1111111110111", "1111111111011", "1111111111101", "0111111111110"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-round-robin-scores-l4-s8/tests/check.py b/tasks/construct-rlve-round-robin-scores-l4-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..214446acaa90ce170daad3989b42317353060f9d --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l4-s8/tests/check.py @@ -0,0 +1,24 @@ +from run import Invalid + + +def check(inst, ans): + W = inst["W"] + n = len(W) + A = ans.get("A") + if not isinstance(A, list) or len(A) != n: + raise Invalid(f"A must be a list of {n} strings") + for r in A: + if not isinstance(r, str) or len(r) != n or set(r) - {"0", "1", "2"}: + raise Invalid(f"each row must be a string of {n} digits 0/1/2") + for i in range(n): + if A[i][i] != "0": + raise Invalid("diagonal must be 0") + w = 0 + for j in range(n): + if i != j: + if int(A[i][j]) + int(A[j][i]) != 2: + raise Invalid(f"A[{i}][{j}] + A[{j}][{i}] != 2") + w += 3 * (A[i][j] == "2") + (A[i][j] == "1") + if w != W[i]: + raise Invalid(f"W[{i}] = {w}, need {W[i]}") + return None, {} diff --git a/tasks/construct-rlve-round-robin-scores-l4-s8/tests/instance.json b/tasks/construct-rlve-round-robin-scores-l4-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9e3d59a3bbbd637b12dfc91979766ba1c57949f7 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l4-s8/tests/instance.json @@ -0,0 +1 @@ +{"W": [13, 11, 14, 12, 14, 12, 14, 12, 11, 12, 12, 12, 11], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l4-s8/tests/run.py b/tasks/construct-rlve-round-robin-scores-l4-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l4-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-round-robin-scores-l4-s8/tests/test.sh b/tasks/construct-rlve-round-robin-scores-l4-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l4-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-shortest-path-count-l3-s3/environment/Dockerfile b/tasks/construct-rlve-shortest-path-count-l3-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l3-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-shortest-path-count-l3-s3/environment/instance.json b/tasks/construct-rlve-shortest-path-count-l3-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9cf4d505885367766cc79804999043ce90312177 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l3-s3/environment/instance.json @@ -0,0 +1 @@ +{"K": 20443, "n_max": 93, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l3-s3/solution/solve.sh b/tasks/construct-rlve-shortest-path-count-l3-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..446d65dca8c97763671f1b796dd5271972e54594 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l3-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"n": 45, "adj": ["NNYYNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "YNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNN", "YNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNN", "NNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNN", "NNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNN", "NNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNN", "NNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNYNNNNNNNN", "NNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNYNNNNNNNN", "NNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNYNNNNNNN", "NNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNYNNNNNNN", "NNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNYNNNNNN", "NNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNYNNNNNN", "NNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNYNNNNN", "NNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNYNNNNN", "NNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNYNNNN", "NNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNYNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNYNNN", "NNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNYNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNY", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNY", "YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNN", "NNYYNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNN", "NNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNN", "NNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNN", "NNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNN", "NNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNYNYNNNNNN", "NNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNYNYNNNNN", "NNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNYNYNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNYNYNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNYNYNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNY", "NYNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNYN"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-shortest-path-count-l3-s3/tests/check.py b/tasks/construct-rlve-shortest-path-count-l3-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c59d4c4f4bb4e824a2019380643a5b3ade0ca974 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l3-s3/tests/check.py @@ -0,0 +1,34 @@ +from run import Invalid, as_int + + +def check(inst, ans): + n = as_int(ans.get("n"), "n", lo=2, hi=inst["n_max"]) + adj = ans.get("adj") + if not isinstance(adj, list) or len(adj) != n: + raise Invalid(f"adj must be a list of {n} strings") + for r in adj: + if not isinstance(r, str) or len(r) != n or set(r) - {"Y", "N"}: + raise Invalid("each row must be a string of length n over {'Y','N'}") + for i in range(n): + if adj[i][i] != "N": + raise Invalid("self-loop") + for j in range(i + 1, n): + if adj[i][j] != adj[j][i]: + raise Invalid("matrix not symmetric") + nb = [[j for j in range(n) if adj[i][j] == "Y"] for i in range(n)] + dist = [-1] * n + cnt = [0] * n + dist[0], cnt[0] = 0, 1 + q = [0] + for u in q: # BFS with exact (Python int) path counts + for v in nb[u]: + if dist[v] < 0: + dist[v] = dist[u] + 1 + q.append(v) + if dist[v] == dist[u] + 1: + cnt[v] += cnt[u] + if dist[1] < 0: + raise Invalid("vertex 2 is unreachable from vertex 1") + if cnt[1] != inst["K"]: + raise Invalid(f"{cnt[1]} shortest paths, need {inst['K']}") + return None, {} diff --git a/tasks/construct-rlve-shortest-path-count-l3-s3/tests/instance.json b/tasks/construct-rlve-shortest-path-count-l3-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9cf4d505885367766cc79804999043ce90312177 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l3-s3/tests/instance.json @@ -0,0 +1 @@ +{"K": 20443, "n_max": 93, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l3-s3/tests/run.py b/tasks/construct-rlve-shortest-path-count-l3-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l3-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-shortest-path-count-l3-s3/tests/test.sh b/tasks/construct-rlve-shortest-path-count-l3-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l3-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-shortest-path-count-l3-s4/environment/Dockerfile b/tasks/construct-rlve-shortest-path-count-l3-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l3-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-shortest-path-count-l3-s4/environment/instance.json b/tasks/construct-rlve-shortest-path-count-l3-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ce9a9f40d0f6aa978120d8299eb0be114b025803 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l3-s4/environment/instance.json @@ -0,0 +1 @@ +{"K": 95415, "n_max": 105, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l3-s4/solution/solve.sh b/tasks/construct-rlve-shortest-path-count-l3-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6c9615325264ddddb0a9551fd406b336214b722e --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l3-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"n": 51, "adj": ["NNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "YNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNN", "YNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNN", "NNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNN", "NNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNN", "NNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNN", "NNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNN", "NNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNN", "NNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNN", "NNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNYNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNYNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNYNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNYNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNYNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNYNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNY", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNY", "YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNN", "NNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNN", "NNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNN", "NNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNN", "NNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNN", "NNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNYNYNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNYNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNYNYNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNYNYN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNY", "NYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNYN"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-shortest-path-count-l3-s4/tests/check.py b/tasks/construct-rlve-shortest-path-count-l3-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c59d4c4f4bb4e824a2019380643a5b3ade0ca974 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l3-s4/tests/check.py @@ -0,0 +1,34 @@ +from run import Invalid, as_int + + +def check(inst, ans): + n = as_int(ans.get("n"), "n", lo=2, hi=inst["n_max"]) + adj = ans.get("adj") + if not isinstance(adj, list) or len(adj) != n: + raise Invalid(f"adj must be a list of {n} strings") + for r in adj: + if not isinstance(r, str) or len(r) != n or set(r) - {"Y", "N"}: + raise Invalid("each row must be a string of length n over {'Y','N'}") + for i in range(n): + if adj[i][i] != "N": + raise Invalid("self-loop") + for j in range(i + 1, n): + if adj[i][j] != adj[j][i]: + raise Invalid("matrix not symmetric") + nb = [[j for j in range(n) if adj[i][j] == "Y"] for i in range(n)] + dist = [-1] * n + cnt = [0] * n + dist[0], cnt[0] = 0, 1 + q = [0] + for u in q: # BFS with exact (Python int) path counts + for v in nb[u]: + if dist[v] < 0: + dist[v] = dist[u] + 1 + q.append(v) + if dist[v] == dist[u] + 1: + cnt[v] += cnt[u] + if dist[1] < 0: + raise Invalid("vertex 2 is unreachable from vertex 1") + if cnt[1] != inst["K"]: + raise Invalid(f"{cnt[1]} shortest paths, need {inst['K']}") + return None, {} diff --git a/tasks/construct-rlve-shortest-path-count-l3-s4/tests/instance.json b/tasks/construct-rlve-shortest-path-count-l3-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ce9a9f40d0f6aa978120d8299eb0be114b025803 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l3-s4/tests/instance.json @@ -0,0 +1 @@ +{"K": 95415, "n_max": 105, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l3-s4/tests/run.py b/tasks/construct-rlve-shortest-path-count-l3-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l3-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-shortest-path-count-l3-s4/tests/test.sh b/tasks/construct-rlve-shortest-path-count-l3-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l3-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l4-s0/environment/Dockerfile b/tasks/construct-rlve-smallest-enclosing-circle-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l4-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l4-s0/environment/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..650d8f14b13282136ef6aa35d49e191d7cf4afb8 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"points": [[0, 27], [1, 8], [2, 23], [2, 36], [3, 44], [4, 9], [4, 39], [6, 3], [6, 10], [13, 52], [15, 41], [17, 58], [20, 22], [20, 23], [22, 39], [28, 31], [29, 13], [30, 9], [32, 46], [35, 51], [42, 49], [43, 20], [44, 57], [45, 8], [45, 13], [46, 6], [46, 16], [50, 43], [52, 5], [57, 21]], "r_opt": 33.338219758187314, "r2_num": 53305625, "r2_den": 47961, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l4-s0/solution/solve.sh b/tasks/construct-rlve-smallest-enclosing-circle-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..86d1fac904a798eed1e5b224c4d40e96abfdb9e9 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l4-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 27.75799086757991, "y": 27.885844748858446, "r": 33.33821975918731} +RLMATH_EOF diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l4-s0/tests/check.py b/tasks/construct-rlve-smallest-enclosing-circle-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0eabf3219588f98db42bf5fd305dc24ce21ca495 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l4-s0/tests/check.py @@ -0,0 +1,17 @@ +import math + +from run import Invalid, num + +TOL = 1e-6 + + +def check(inst, ans): + x, y, r = num(ans.get("x"), "x"), num(ans.get("y"), "y"), num(ans.get("r"), "r") + if r <= 0: + raise Invalid("r must be positive") + if r > inst["r_opt"] + TOL: + raise Invalid(f"r = {r} exceeds the minimum radius {inst['r_opt']} by more than {TOL}") + for px, py in inst["points"]: + if math.hypot(px - x, py - y) > r + TOL: + raise Invalid(f"point ({px}, {py}) is outside the circle") + return None, {"r": r} diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l4-s0/tests/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..650d8f14b13282136ef6aa35d49e191d7cf4afb8 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"points": [[0, 27], [1, 8], [2, 23], [2, 36], [3, 44], [4, 9], [4, 39], [6, 3], [6, 10], [13, 52], [15, 41], [17, 58], [20, 22], [20, 23], [22, 39], [28, 31], [29, 13], [30, 9], [32, 46], [35, 51], [42, 49], [43, 20], [44, 57], [45, 8], [45, 13], [46, 6], [46, 16], [50, 43], [52, 5], [57, 21]], "r_opt": 33.338219758187314, "r2_num": 53305625, "r2_den": 47961, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l4-s0/tests/run.py b/tasks/construct-rlve-smallest-enclosing-circle-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l4-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l4-s0/tests/test.sh b/tasks/construct-rlve-smallest-enclosing-circle-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l4-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l4-s7/environment/Dockerfile b/tasks/construct-rlve-smallest-enclosing-circle-l4-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l4-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l4-s7/environment/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l4-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..44f15f5d669f5d485b28fd6195550686486fa75e --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l4-s7/environment/instance.json @@ -0,0 +1 @@ +{"points": [[0, 10], [0, 33], [1, 0], [3, 54], [6, 32], [8, 14], [9, 60], [12, 40], [13, 13], [15, 38], [16, 16], [16, 26], [18, 51], [19, 14], [23, 6], [25, 5], [28, 30], [34, 49], [39, 13], [39, 45], [40, 24], [45, 34], [48, 37], [49, 11], [51, 52], [54, 19], [55, 17], [57, 39], [59, 7], [60, 24]], "r_opt": 37.6260378153411, "r2_num": 4149392293, "r2_den": 2930944, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l4-s7/solution/solve.sh b/tasks/construct-rlve-smallest-enclosing-circle-l4-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8e882f686928c0773482e4977e97b0ad9b2a2c0d --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l4-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 27.158294392523363, "y": 27.04556074766355, "r": 37.626037816341096} +RLMATH_EOF diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l4-s7/tests/check.py b/tasks/construct-rlve-smallest-enclosing-circle-l4-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0eabf3219588f98db42bf5fd305dc24ce21ca495 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l4-s7/tests/check.py @@ -0,0 +1,17 @@ +import math + +from run import Invalid, num + +TOL = 1e-6 + + +def check(inst, ans): + x, y, r = num(ans.get("x"), "x"), num(ans.get("y"), "y"), num(ans.get("r"), "r") + if r <= 0: + raise Invalid("r must be positive") + if r > inst["r_opt"] + TOL: + raise Invalid(f"r = {r} exceeds the minimum radius {inst['r_opt']} by more than {TOL}") + for px, py in inst["points"]: + if math.hypot(px - x, py - y) > r + TOL: + raise Invalid(f"point ({px}, {py}) is outside the circle") + return None, {"r": r} diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l4-s7/tests/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l4-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..44f15f5d669f5d485b28fd6195550686486fa75e --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l4-s7/tests/instance.json @@ -0,0 +1 @@ +{"points": [[0, 10], [0, 33], [1, 0], [3, 54], [6, 32], [8, 14], [9, 60], [12, 40], [13, 13], [15, 38], [16, 16], [16, 26], [18, 51], [19, 14], [23, 6], [25, 5], [28, 30], [34, 49], [39, 13], [39, 45], [40, 24], [45, 34], [48, 37], [49, 11], [51, 52], [54, 19], [55, 17], [57, 39], [59, 7], [60, 24]], "r_opt": 37.6260378153411, "r2_num": 4149392293, "r2_den": 2930944, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l4-s7/tests/run.py b/tasks/construct-rlve-smallest-enclosing-circle-l4-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l4-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l4-s7/tests/test.sh b/tasks/construct-rlve-smallest-enclosing-circle-l4-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l4-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l4-s9/environment/Dockerfile b/tasks/construct-rlve-smallest-enclosing-circle-l4-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l4-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l4-s9/environment/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l4-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b9c31f45e4af494b40fe1b6a64102b5e1446f97a --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l4-s9/environment/instance.json @@ -0,0 +1 @@ +{"points": [[1, 26], [2, 42], [4, 38], [7, 52], [9, 51], [12, 14], [13, 2], [16, 59], [20, 7], [22, 4], [23, 27], [23, 30], [24, 46], [27, 17], [27, 19], [28, 11], [31, 34], [38, 42], [42, 34], [42, 38], [43, 53], [46, 21], [46, 22], [51, 6], [52, 54], [53, 20], [53, 48], [55, 24], [56, 10], [60, 45]], "r_opt": 32.91963303936371, "r2_num": 195743717, "r2_den": 180625, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l4-s9/solution/solve.sh b/tasks/construct-rlve-smallest-enclosing-circle-l4-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0b728b42cc426c94d5f4073b58d2852f8d46de59 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l4-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 30.88470588235294, "y": 29.63764705882353, "r": 32.919633040363706} +RLMATH_EOF diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l4-s9/tests/check.py b/tasks/construct-rlve-smallest-enclosing-circle-l4-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0eabf3219588f98db42bf5fd305dc24ce21ca495 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l4-s9/tests/check.py @@ -0,0 +1,17 @@ +import math + +from run import Invalid, num + +TOL = 1e-6 + + +def check(inst, ans): + x, y, r = num(ans.get("x"), "x"), num(ans.get("y"), "y"), num(ans.get("r"), "r") + if r <= 0: + raise Invalid("r must be positive") + if r > inst["r_opt"] + TOL: + raise Invalid(f"r = {r} exceeds the minimum radius {inst['r_opt']} by more than {TOL}") + for px, py in inst["points"]: + if math.hypot(px - x, py - y) > r + TOL: + raise Invalid(f"point ({px}, {py}) is outside the circle") + return None, {"r": r} diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l4-s9/tests/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l4-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b9c31f45e4af494b40fe1b6a64102b5e1446f97a --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l4-s9/tests/instance.json @@ -0,0 +1 @@ +{"points": [[1, 26], [2, 42], [4, 38], [7, 52], [9, 51], [12, 14], [13, 2], [16, 59], [20, 7], [22, 4], [23, 27], [23, 30], [24, 46], [27, 17], [27, 19], [28, 11], [31, 34], [38, 42], [42, 34], [42, 38], [43, 53], [46, 21], [46, 22], [51, 6], [52, 54], [53, 20], [53, 48], [55, 24], [56, 10], [60, 45]], "r_opt": 32.91963303936371, "r2_num": 195743717, "r2_den": 180625, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l4-s9/tests/run.py b/tasks/construct-rlve-smallest-enclosing-circle-l4-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l4-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l4-s9/tests/test.sh b/tasks/construct-rlve-smallest-enclosing-circle-l4-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l4-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-subgraph-isomorphism-l4-s2/environment/Dockerfile b/tasks/construct-rlve-subgraph-isomorphism-l4-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l4-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-subgraph-isomorphism-l4-s2/environment/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l4-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a52dfcd1e5637b01e7d74f8a00656f5c91812b98 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l4-s2/environment/instance.json @@ -0,0 +1 @@ +{"n1": 17, "n2": 18, "edges1": [[6, 12], [3, 13], [3, 12], [0, 5], [9, 13], [1, 10], [3, 8], [2, 11], [2, 9], [4, 8], [3, 4], [12, 13], [6, 14], [7, 15], [6, 16], [5, 9], [6, 8], [10, 11], [9, 16], [6, 9], [8, 11], [7, 10], [8, 9], [1, 8], [10, 14], [8, 13], [5, 13], [1, 16], [5, 6], [6, 10], [11, 14], [8, 10], [10, 15], [10, 12], [2, 13], [7, 9], [4, 13], [7, 11], [10, 16], [3, 6], [9, 12], [8, 12], [5, 14], [13, 16], [1, 11], [7, 13], [13, 15], [4, 5], [9, 11], [11, 13], [11, 16], [2, 5], [0, 15], [0, 4], [0, 7], [7, 12], [14, 15], [3, 15], [15, 16], [0, 10], [7, 14], [12, 15], [1, 15], [4, 7], [4, 16], [3, 16], [8, 15], [5, 15], [0, 1], [2, 4], [1, 12], [1, 3], [4, 15]], "edges2": [[12, 17], [4, 6], [9, 17], [5, 17], [11, 16], [5, 12], [7, 13], [2, 16], [0, 14], [0, 5], [3, 17], [4, 15], [8, 15], [0, 4], [3, 4], [1, 16], [3, 6], [10, 13], [8, 10], [0, 2], [10, 15], [6, 13], [1, 10], [3, 9], [0, 17], [2, 7], [4, 8], [12, 16], [5, 15], [15, 17], [11, 12], [3, 12], [0, 7], [3, 10], [4, 7], [1, 3], [1, 2], [6, 11], [1, 8], [8, 11], [0, 8], [10, 12], [7, 10], [2, 14], [9, 15], [11, 17], [5, 16], [8, 9], [2, 17], [10, 17], [6, 15], [7, 8], [11, 14], [2, 6], [3, 5], [0, 16], [5, 9], [6, 14], [1, 5], [2, 13], [0, 6], [1, 4], [12, 13], [7, 12], [9, 14], [3, 7], [0, 15], [0, 11], [5, 14], [5, 8], [8, 17], [1, 15], [5, 11], [7, 17], [0, 3], [6, 7], [7, 11], [4, 9], [0, 9], [2, 10], [10, 11], [12, 15], [7, 15], [9, 12]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l4-s2/solution/solve.sh b/tasks/construct-rlve-subgraph-isomorphism-l4-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..59e5882cc4f317d4dcf79d0a8346113a483d6dbf --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l4-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"p": [14, 9, 13, 4, 6, 2, 1, 11, 15, 10, 5, 12, 8, 7, 16, 0, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-subgraph-isomorphism-l4-s2/tests/check.py b/tasks/construct-rlve-subgraph-isomorphism-l4-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b8467dd00c27c8902c06206c376ff7a11ac78ae0 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l4-s2/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n1, n2 = inst["n1"], inst["n2"] + p = int_list(ans.get("p"), n1, 0, n2 - 1, "p") + if len(set(p)) != n1: + raise Invalid("p is not injective") + e1 = {(min(u, v), max(u, v)) for u, v in inst["edges1"]} + e2 = {(min(u, v), max(u, v)) for u, v in inst["edges2"]} + for u in range(n1): + for v in range(u + 1, n1): + a, b = min(p[u], p[v]), max(p[u], p[v]) + if ((u, v) in e1) != ((a, b) in e2): + raise Invalid(f"pair ({u}, {v}) is not preserved") + return None, {} diff --git a/tasks/construct-rlve-subgraph-isomorphism-l4-s2/tests/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l4-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a52dfcd1e5637b01e7d74f8a00656f5c91812b98 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l4-s2/tests/instance.json @@ -0,0 +1 @@ +{"n1": 17, "n2": 18, "edges1": [[6, 12], [3, 13], [3, 12], [0, 5], [9, 13], [1, 10], [3, 8], [2, 11], [2, 9], [4, 8], [3, 4], [12, 13], [6, 14], [7, 15], [6, 16], [5, 9], [6, 8], [10, 11], [9, 16], [6, 9], [8, 11], [7, 10], [8, 9], [1, 8], [10, 14], [8, 13], [5, 13], [1, 16], [5, 6], [6, 10], [11, 14], [8, 10], [10, 15], [10, 12], [2, 13], [7, 9], [4, 13], [7, 11], [10, 16], [3, 6], [9, 12], [8, 12], [5, 14], [13, 16], [1, 11], [7, 13], [13, 15], [4, 5], [9, 11], [11, 13], [11, 16], [2, 5], [0, 15], [0, 4], [0, 7], [7, 12], [14, 15], [3, 15], [15, 16], [0, 10], [7, 14], [12, 15], [1, 15], [4, 7], [4, 16], [3, 16], [8, 15], [5, 15], [0, 1], [2, 4], [1, 12], [1, 3], [4, 15]], "edges2": [[12, 17], [4, 6], [9, 17], [5, 17], [11, 16], [5, 12], [7, 13], [2, 16], [0, 14], [0, 5], [3, 17], [4, 15], [8, 15], [0, 4], [3, 4], [1, 16], [3, 6], [10, 13], [8, 10], [0, 2], [10, 15], [6, 13], [1, 10], [3, 9], [0, 17], [2, 7], [4, 8], [12, 16], [5, 15], [15, 17], [11, 12], [3, 12], [0, 7], [3, 10], [4, 7], [1, 3], [1, 2], [6, 11], [1, 8], [8, 11], [0, 8], [10, 12], [7, 10], [2, 14], [9, 15], [11, 17], [5, 16], [8, 9], [2, 17], [10, 17], [6, 15], [7, 8], [11, 14], [2, 6], [3, 5], [0, 16], [5, 9], [6, 14], [1, 5], [2, 13], [0, 6], [1, 4], [12, 13], [7, 12], [9, 14], [3, 7], [0, 15], [0, 11], [5, 14], [5, 8], [8, 17], [1, 15], [5, 11], [7, 17], [0, 3], [6, 7], [7, 11], [4, 9], [0, 9], [2, 10], [10, 11], [12, 15], [7, 15], [9, 12]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l4-s2/tests/run.py b/tasks/construct-rlve-subgraph-isomorphism-l4-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l4-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-subgraph-isomorphism-l4-s2/tests/test.sh b/tasks/construct-rlve-subgraph-isomorphism-l4-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l4-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-subgraph-isomorphism-l4-s5/environment/Dockerfile b/tasks/construct-rlve-subgraph-isomorphism-l4-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l4-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-subgraph-isomorphism-l4-s5/environment/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l4-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0bcc5ec00daad88f3460362c4f7196277d9b5c73 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l4-s5/environment/instance.json @@ -0,0 +1 @@ +{"n1": 16, "n2": 18, "edges1": [[0, 9], [3, 11], [5, 9], [8, 15], [5, 13], [0, 7], [8, 14], [8, 12], [0, 14], [6, 14], [3, 7], [5, 12], [4, 8], [8, 10], [9, 11], [7, 15], [2, 7], [8, 13], [0, 1], [9, 14], [6, 13], [0, 12], [5, 7], [12, 14], [1, 2], [9, 13], [3, 9], [4, 15], [11, 14], [0, 4], [0, 5], [2, 3], [1, 11], [3, 6], [6, 15], [10, 12], [3, 15], [11, 13], [6, 8], [5, 6], [3, 10], [1, 9], [6, 9], [7, 14], [2, 14], [10, 13], [0, 10], [4, 6], [14, 15], [0, 8], [1, 15], [9, 10], [0, 15], [1, 6], [3, 14], [3, 8], [8, 9], [2, 9], [10, 15], [12, 15], [5, 8], [5, 14], [7, 11], [1, 12], [6, 10], [7, 8], [1, 5], [7, 9], [0, 6], [6, 12], [4, 12], [13, 15], [10, 11], [3, 12], [1, 14], [5, 10], [1, 4], [3, 13], [1, 3], [2, 13], [6, 11], [2, 8], [0, 13], [5, 11], [2, 11], [8, 11], [4, 9], [5, 15], [6, 7]], "edges2": [[2, 11], [7, 11], [11, 17], [0, 17], [14, 16], [6, 8], [3, 13], [13, 17], [15, 16], [4, 17], [2, 15], [4, 15], [7, 14], [0, 11], [1, 8], [4, 12], [14, 15], [10, 14], [10, 17], [6, 9], [1, 13], [7, 15], [13, 15], [5, 8], [5, 15], [11, 12], [13, 14], [5, 11], [6, 12], [2, 7], [0, 3], [8, 10], [11, 13], [0, 1], [4, 7], [9, 13], [1, 15], [1, 2], [1, 7], [7, 12], [14, 17], [0, 12], [6, 15], [9, 12], [5, 17], [10, 16], [0, 15], [1, 17], [3, 15], [0, 14], [3, 4], [2, 6], [8, 12], [5, 13], [8, 15], [13, 16], [2, 3], [3, 16], [2, 14], [4, 14], [5, 12], [0, 7], [7, 9], [4, 16], [0, 5], [3, 7], [15, 17], [4, 10], [8, 9], [11, 15], [5, 14], [4, 13], [3, 10], [9, 10], [3, 9], [3, 17], [1, 10], [9, 17], [2, 10], [2, 9], [1, 6], [12, 17], [2, 5], [2, 4], [6, 7], [11, 16], [0, 8], [0, 6], [1, 11], [3, 14], [6, 13], [4, 5], [1, 9], [10, 13], [10, 12], [8, 17], [7, 13], [6, 11], [12, 15], [2, 12], [0, 4], [0, 9], [2, 17], [10, 11], [0, 10], [4, 11], [2, 13], [8, 11], [4, 9], [1, 4], [9, 15], [6, 14], [1, 3], [4, 6]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l4-s5/solution/solve.sh b/tasks/construct-rlve-subgraph-isomorphism-l4-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..778c2d4d430e48b2dda0bb6d8dc6083110f570c2 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l4-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"p": [13, 10, 8, 0, 16, 2, 4, 5, 15, 11, 7, 12, 3, 6, 17, 14]} +RLMATH_EOF diff --git a/tasks/construct-rlve-subgraph-isomorphism-l4-s5/tests/check.py b/tasks/construct-rlve-subgraph-isomorphism-l4-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b8467dd00c27c8902c06206c376ff7a11ac78ae0 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l4-s5/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n1, n2 = inst["n1"], inst["n2"] + p = int_list(ans.get("p"), n1, 0, n2 - 1, "p") + if len(set(p)) != n1: + raise Invalid("p is not injective") + e1 = {(min(u, v), max(u, v)) for u, v in inst["edges1"]} + e2 = {(min(u, v), max(u, v)) for u, v in inst["edges2"]} + for u in range(n1): + for v in range(u + 1, n1): + a, b = min(p[u], p[v]), max(p[u], p[v]) + if ((u, v) in e1) != ((a, b) in e2): + raise Invalid(f"pair ({u}, {v}) is not preserved") + return None, {} diff --git a/tasks/construct-rlve-subgraph-isomorphism-l4-s5/tests/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l4-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0bcc5ec00daad88f3460362c4f7196277d9b5c73 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l4-s5/tests/instance.json @@ -0,0 +1 @@ +{"n1": 16, "n2": 18, "edges1": [[0, 9], [3, 11], [5, 9], [8, 15], [5, 13], [0, 7], [8, 14], [8, 12], [0, 14], [6, 14], [3, 7], [5, 12], [4, 8], [8, 10], [9, 11], [7, 15], [2, 7], [8, 13], [0, 1], [9, 14], [6, 13], [0, 12], [5, 7], [12, 14], [1, 2], [9, 13], [3, 9], [4, 15], [11, 14], [0, 4], [0, 5], [2, 3], [1, 11], [3, 6], [6, 15], [10, 12], [3, 15], [11, 13], [6, 8], [5, 6], [3, 10], [1, 9], [6, 9], [7, 14], [2, 14], [10, 13], [0, 10], [4, 6], [14, 15], [0, 8], [1, 15], [9, 10], [0, 15], [1, 6], [3, 14], [3, 8], [8, 9], [2, 9], [10, 15], [12, 15], [5, 8], [5, 14], [7, 11], [1, 12], [6, 10], [7, 8], [1, 5], [7, 9], [0, 6], [6, 12], [4, 12], [13, 15], [10, 11], [3, 12], [1, 14], [5, 10], [1, 4], [3, 13], [1, 3], [2, 13], [6, 11], [2, 8], [0, 13], [5, 11], [2, 11], [8, 11], [4, 9], [5, 15], [6, 7]], "edges2": [[2, 11], [7, 11], [11, 17], [0, 17], [14, 16], [6, 8], [3, 13], [13, 17], [15, 16], [4, 17], [2, 15], [4, 15], [7, 14], [0, 11], [1, 8], [4, 12], [14, 15], [10, 14], [10, 17], [6, 9], [1, 13], [7, 15], [13, 15], [5, 8], [5, 15], [11, 12], [13, 14], [5, 11], [6, 12], [2, 7], [0, 3], [8, 10], [11, 13], [0, 1], [4, 7], [9, 13], [1, 15], [1, 2], [1, 7], [7, 12], [14, 17], [0, 12], [6, 15], [9, 12], [5, 17], [10, 16], [0, 15], [1, 17], [3, 15], [0, 14], [3, 4], [2, 6], [8, 12], [5, 13], [8, 15], [13, 16], [2, 3], [3, 16], [2, 14], [4, 14], [5, 12], [0, 7], [7, 9], [4, 16], [0, 5], [3, 7], [15, 17], [4, 10], [8, 9], [11, 15], [5, 14], [4, 13], [3, 10], [9, 10], [3, 9], [3, 17], [1, 10], [9, 17], [2, 10], [2, 9], [1, 6], [12, 17], [2, 5], [2, 4], [6, 7], [11, 16], [0, 8], [0, 6], [1, 11], [3, 14], [6, 13], [4, 5], [1, 9], [10, 13], [10, 12], [8, 17], [7, 13], [6, 11], [12, 15], [2, 12], [0, 4], [0, 9], [2, 17], [10, 11], [0, 10], [4, 11], [2, 13], [8, 11], [4, 9], [1, 4], [9, 15], [6, 14], [1, 3], [4, 6]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l4-s5/tests/run.py b/tasks/construct-rlve-subgraph-isomorphism-l4-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l4-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-subgraph-isomorphism-l4-s5/tests/test.sh b/tasks/construct-rlve-subgraph-isomorphism-l4-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l4-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/optimize-ae-p1-ff-kakeya-d4-p5/environment/Dockerfile b/tasks/optimize-ae-p1-ff-kakeya-d4-p5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-ae-p1-ff-kakeya-d4-p5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/optimize-ae-p1-ff-kakeya-d4-p5/environment/instance.json b/tasks/optimize-ae-p1-ff-kakeya-d4-p5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f7d2dcdbe38778c3520e25a15e3686bcffaa4282 --- /dev/null +++ b/tasks/optimize-ae-p1-ff-kakeya-d4-p5/environment/instance.json @@ -0,0 +1 @@ +{"p": 5, "d": 4, "direction": "minimize", "family": "ae_p1_ff_kakeya", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p1-ff-kakeya-d4-p5/solution/solve.sh b/tasks/optimize-ae-p1-ff-kakeya-d4-p5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..30b8b9f96452fe18667f4ec8752096865f8d0f78 --- /dev/null +++ b/tasks/optimize-ae-p1-ff-kakeya-d4-p5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"points": [[0, 0, 0, 0], [0, 0, 0, 1], [0, 0, 0, 2], [0, 0, 0, 3], [0, 0, 0, 4], [0, 0, 1, 0], [0, 0, 1, 2], [0, 0, 1, 3], [0, 0, 2, 2], [0, 0, 2, 3], [0, 0, 3, 1], [0, 0, 3, 4], [0, 0, 4, 0], [0, 0, 4, 1], [0, 0, 4, 4], [0, 1, 0, 0], [0, 1, 0, 2], [0, 1, 0, 3], [0, 1, 1, 0], [0, 1, 1, 2], [0, 1, 1, 3], [0, 1, 2, 2], [0, 1, 2, 3], [0, 1, 4, 0], [0, 2, 0, 0], [0, 2, 0, 2], [0, 2, 0, 3], [0, 2, 1, 2], [0, 2, 1, 3], [0, 2, 2, 2], [0, 2, 2, 3], [0, 3, 0, 0], [0, 3, 0, 1], [0, 3, 0, 4], [0, 3, 3, 1], [0, 3, 3, 4], [0, 3, 4, 1], [0, 3, 4, 4], [0, 4, 0, 0], [0, 4, 0, 1], [0, 4, 0, 4], [0, 4, 1, 0], [0, 4, 3, 1], [0, 4, 3, 4], [0, 4, 4, 0], [0, 4, 4, 1], [0, 4, 4, 4], [1, 0, 0, 0], [1, 0, 0, 2], [1, 0, 0, 3], [1, 0, 1, 0], [1, 0, 1, 2], [1, 0, 1, 3], [1, 0, 2, 2], [1, 0, 2, 3], [1, 0, 4, 0], [1, 1, 0, 0], [1, 1, 0, 2], [1, 1, 0, 3], [1, 1, 1, 0], [1, 1, 1, 2], [1, 1, 1, 3], [1, 1, 2, 0], [1, 1, 2, 2], [1, 1, 2, 3], [1, 1, 3, 0], [1, 1, 4, 0], [1, 2, 0, 0], [1, 2, 0, 2], [1, 2, 0, 3], [1, 2, 1, 2], [1, 2, 1, 3], [1, 2, 2, 0], [1, 2, 2, 2], [1, 2, 2, 3], [1, 2, 3, 0], [1, 3, 2, 0], [1, 3, 3, 0], [1, 4, 0, 0], [1, 4, 1, 0], [1, 4, 4, 0], [2, 0, 0, 0], [2, 0, 0, 2], [2, 0, 0, 3], [2, 0, 1, 2], [2, 0, 1, 3], [2, 0, 2, 2], [2, 0, 2, 3], [2, 1, 0, 0], [2, 1, 0, 2], [2, 1, 0, 3], [2, 1, 1, 2], [2, 1, 1, 3], [2, 1, 2, 0], [2, 1, 2, 2], [2, 1, 2, 3], [2, 1, 3, 0], [2, 2, 0, 0], [2, 2, 0, 2], [2, 2, 0, 3], [2, 2, 1, 2], [2, 2, 1, 3], [2, 2, 2, 0], [2, 2, 2, 2], [2, 2, 2, 3], [2, 2, 3, 0], [2, 3, 2, 0], [2, 3, 3, 0], [3, 0, 0, 0], [3, 0, 0, 1], [3, 0, 0, 4], [3, 0, 3, 1], [3, 0, 3, 4], [3, 0, 4, 1], [3, 0, 4, 4], [3, 1, 2, 0], [3, 1, 3, 0], [3, 2, 2, 0], [3, 2, 3, 0], [3, 3, 0, 0], [3, 3, 0, 1], [3, 3, 0, 4], [3, 3, 2, 0], [3, 3, 3, 0], [3, 3, 3, 1], [3, 3, 3, 4], [3, 3, 4, 1], [3, 3, 4, 4], [3, 4, 0, 1], [3, 4, 0, 4], [3, 4, 3, 1], [3, 4, 3, 4], [3, 4, 4, 1], [3, 4, 4, 4], [4, 0, 0, 0], [4, 0, 0, 1], [4, 0, 0, 4], [4, 0, 1, 0], [4, 0, 3, 1], [4, 0, 3, 4], [4, 0, 4, 0], [4, 0, 4, 1], [4, 0, 4, 4], [4, 1, 0, 0], [4, 1, 1, 0], [4, 1, 4, 0], [4, 3, 0, 0], [4, 3, 0, 1], [4, 3, 0, 4], [4, 3, 3, 1], [4, 3, 3, 4], [4, 3, 4, 1], [4, 3, 4, 4], [4, 4, 0, 0], [4, 4, 0, 1], [4, 4, 0, 4], [4, 4, 1, 0], [4, 4, 3, 1], [4, 4, 3, 4], [4, 4, 4, 0], [4, 4, 4, 1], [4, 4, 4, 4]]} +RLMATH_EOF diff --git a/tasks/optimize-ae-p1-ff-kakeya-d4-p5/tests/check.py b/tasks/optimize-ae-p1-ff-kakeya-d4-p5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..dac5049b59a505ff843bc5e086d0c1c303695b2a --- /dev/null +++ b/tasks/optimize-ae-p1-ff-kakeya-d4-p5/tests/check.py @@ -0,0 +1,32 @@ +"""Finite-field Kakeya set in F_p^d: every direction contains a full line. Score = |K| (minimize). + +Upstream (AlphaEvolve notebook `finite_field_kakeya.ipynb`) silently deduplicated points and only checked +d in {3, 4}; here duplicates, out-of-range or non-integer coordinates are rejected and every projective +direction (first non-zero coordinate = 1) is checked for any d. +""" +import itertools + +import numpy as np + +from run import Invalid, int_list + + +def check(inst, ans): + p, d = inst["p"], inst["d"] + pts = ans.get("points") + if not isinstance(pts, list) or not pts: + raise Invalid("points must be a non-empty list") + if len(pts) > p ** d: + raise Invalid("more points than the whole space") + K = np.array([int_list(x, d, 0, p - 1, "point") for x in pts], dtype=np.int64) + w = p ** np.arange(d - 1, -1, -1, dtype=np.int64) + codes = K @ w + if len(np.unique(codes)) != len(codes): + raise Invalid("duplicate points") + for i in range(d): # directions v = (0,..,0,1,*,..,*) with the 1 in position i + for tail in itertools.product(range(p), repeat=d - 1 - i): + v = np.array([0] * i + [1] + list(tail), dtype=np.int64) + base = (K - K[:, i:i + 1] * v) % p # canonical point of the line through x with direction v + if np.bincount(base @ w, minlength=p ** d).max() < p: + raise Invalid(f"no full line in direction {v.tolist()}") + return len(pts), {"size": len(pts)} diff --git a/tasks/optimize-ae-p1-ff-kakeya-d4-p5/tests/instance.json b/tasks/optimize-ae-p1-ff-kakeya-d4-p5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..902984e4445f8d2fc86aeb4ea8e59959ca131e9b --- /dev/null +++ b/tasks/optimize-ae-p1-ff-kakeya-d4-p5/tests/instance.json @@ -0,0 +1 @@ +{"p": 5, "d": 4, "direction": "minimize", "best_known": 162, "baseline": 625, "family": "ae_p1_ff_kakeya", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p1-ff-kakeya-d4-p5/tests/run.py b/tasks/optimize-ae-p1-ff-kakeya-d4-p5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-ae-p1-ff-kakeya-d4-p5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/optimize-ae-p1-ff-kakeya-d4-p5/tests/test.sh b/tasks/optimize-ae-p1-ff-kakeya-d4-p5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-ae-p1-ff-kakeya-d4-p5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/optimize-finch-flat-poly-n32/environment/Dockerfile b/tasks/optimize-finch-flat-poly-n32/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-finch-flat-poly-n32/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/optimize-finch-flat-poly-n32/environment/instance.json b/tasks/optimize-finch-flat-poly-n32/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8b1c27db706caad1930246c4e8b39eb1f71269df --- /dev/null +++ b/tasks/optimize-finch-flat-poly-n32/environment/instance.json @@ -0,0 +1 @@ +{"n": 32, "grid": 16384, "direction": "minimize", "family": "finch_flat_poly_32", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-finch-flat-poly-n32/solution/solve.sh b/tasks/optimize-finch-flat-poly-n32/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a1a49563f2f1be154559287bea6ba8d3effe0793 --- /dev/null +++ b/tasks/optimize-finch-flat-poly-n32/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coefficients": [-1, -1, 1, 1, -1, -1, -1, -1, -1, 1, -1, -1, 1, -1, -1, -1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, -1, -1, -1, 1, -1, 1]} +RLMATH_EOF diff --git a/tasks/optimize-finch-flat-poly-n32/tests/check.py b/tasks/optimize-finch-flat-poly-n32/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2e620938175201eca84154d4e1ca8a458a1f6bb6 --- /dev/null +++ b/tasks/optimize-finch-flat-poly-n32/tests/check.py @@ -0,0 +1,17 @@ +"""Erdos-Littlewood flat polynomial, n = 32 +-1 coefficients: minimize max |p| on the unit circle, +evaluated on the 16384-point FFT grid as in the upstream evaluator (Finch/EFT skydiscover +erdos_flat_polynomials_n32, Apache-2.0; grid error is below 0.002% for degree 31). Changes: the raw max +modulus is the score (upstream: sqrt(n)/max); coefficients must be the JSON integers 1/-1.""" +import numpy as np + +from run import Invalid, int_list + + +def check(inst, ans): + n, M = inst["n"], inst["grid"] + c = int_list(ans.get("coefficients"), n, -1, 1, "coefficients") + if any(x == 0 for x in c): + raise Invalid("coefficients must be +1 or -1") + p = np.zeros(M, dtype=np.complex128) + p[:n] = c + return float(np.max(np.abs(np.fft.fft(p)))), {} diff --git a/tasks/optimize-finch-flat-poly-n32/tests/instance.json b/tasks/optimize-finch-flat-poly-n32/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4878420fee69bf1e91a34a166dafe5ad1a282855 --- /dev/null +++ b/tasks/optimize-finch-flat-poly-n32/tests/instance.json @@ -0,0 +1 @@ +{"n": 32, "grid": 16384, "direction": "minimize", "best_known": 7.378357587123142, "baseline": 32.0, "family": "finch_flat_poly_32", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-finch-flat-poly-n32/tests/run.py b/tasks/optimize-finch-flat-poly-n32/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-finch-flat-poly-n32/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/optimize-finch-flat-poly-n32/tests/test.sh b/tasks/optimize-finch-flat-poly-n32/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-finch-flat-poly-n32/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/optimize-finch-sidon-pair-n100/environment/Dockerfile b/tasks/optimize-finch-sidon-pair-n100/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-finch-sidon-pair-n100/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/optimize-finch-sidon-pair-n100/environment/instance.json b/tasks/optimize-finch-sidon-pair-n100/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..364f1b6ce452b6d9299165e2e64053e0863d87b5 --- /dev/null +++ b/tasks/optimize-finch-sidon-pair-n100/environment/instance.json @@ -0,0 +1 @@ +{"N": 100, "direction": "maximize", "family": "finch_sidon_pair_100", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-finch-sidon-pair-n100/solution/solve.sh b/tasks/optimize-finch-sidon-pair-n100/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..34b52a637fc9576cc06922f368f4c47114d15e67 --- /dev/null +++ b/tasks/optimize-finch-sidon-pair-n100/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"A": [1, 2, 5, 21, 30, 35, 57, 75, 81, 88, 96, 98], "B": [1, 12, 38, 50, 100]} +RLMATH_EOF diff --git a/tasks/optimize-finch-sidon-pair-n100/tests/check.py b/tasks/optimize-finch-sidon-pair-n100/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..62e6b728e79ca222aa21046cb95dd2fec81db08c --- /dev/null +++ b/tasks/optimize-finch-sidon-pair-n100/tests/check.py @@ -0,0 +1,35 @@ +"""Erdos #43: Sidon sets A, B in {1..100} with (A-A) and (B-B) meeting only in 0; maximize +C(|A|,2) + C(|B|,2) (Finch/EFT skydiscover erdos_43_sidon_pair, Apache-2.0). Exact integer check, as +upstream. Change: entries must be JSON integers (upstream cast with int()).""" +from run import Invalid, int_list + + +def _sidon(S): + seen = set() + for i in range(len(S)): + for j in range(i, len(S)): + s = S[i] + S[j] + if s in seen: + return False + seen.add(s) + return True + + +def check(inst, ans): + N = inst["N"] + A = int_list(ans.get("A"), None, 1, N, "A") + B = int_list(ans.get("B"), None, 1, N, "B") + if len(A) > N or len(B) > N: + raise Invalid("sets too large") + if len(set(A)) != len(A) or len(set(B)) != len(B): + raise Invalid("elements must be distinct within each set") + if not _sidon(A): + raise Invalid("A is not a Sidon set") + if not _sidon(B): + raise Invalid("B is not a Sidon set") + dA = {a - b for a in A for b in A if a != b} + dB = {a - b for a in B for b in B if a != b} + if dA & dB: + raise Invalid(f"(A-A) and (B-B) share the nonzero difference {min(abs(d) for d in dA & dB)}") + na, nb = len(A), len(B) + return float(na * (na - 1) // 2 + nb * (nb - 1) // 2), {"size_A": na, "size_B": nb} diff --git a/tasks/optimize-finch-sidon-pair-n100/tests/instance.json b/tasks/optimize-finch-sidon-pair-n100/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..042d2ad461d767b0eea986b42dfb7789a32e216b --- /dev/null +++ b/tasks/optimize-finch-sidon-pair-n100/tests/instance.json @@ -0,0 +1 @@ +{"N": 100, "direction": "maximize", "best_known": 76.0, "baseline": 25.0, "family": "finch_sidon_pair_100", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-finch-sidon-pair-n100/tests/run.py b/tasks/optimize-finch-sidon-pair-n100/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-finch-sidon-pair-n100/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/optimize-finch-sidon-pair-n100/tests/test.sh b/tasks/optimize-finch-sidon-pair-n100/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-finch-sidon-pair-n100/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt