diff --git a/tasks/construct-ae-p32-spherical-design-l6-s0/environment/Dockerfile b/tasks/construct-ae-p32-spherical-design-l6-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p32-spherical-design-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-ae-p32-spherical-design-l6-s0/environment/instance.json b/tasks/construct-ae-p32-spherical-design-l6-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..71bf522ba3d4386d040dd1d0a2f16f86e9c942ad --- /dev/null +++ b/tasks/construct-ae-p32-spherical-design-l6-s0/environment/instance.json @@ -0,0 +1 @@ +{"t": 21, "N": 234, "family": "ae_p32_spherical_designs", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p32-spherical-design-l6-s0/solution/solve.sh b/tasks/construct-ae-p32-spherical-design-l6-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..46fd586406bf201510479ecbc9919335411853c5 --- /dev/null +++ b/tasks/construct-ae-p32-spherical-design-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' +{"points": [[-0.9596810424419001, -0.28105208802161075, 0.0046926108213612315], [-0.7595309788778035, 0.28634046819989534, -0.5840563572087804], [-0.813730818738408, -0.3764390859035123, 0.4428721816048601], [-0.9347893044111631, 0.08032069257362744, 0.34600222933239383], [-0.2683002097771996, 0.8777526186055353, -0.3969450062220663], [0.6342524888407759, 0.7323670273520217, -0.2477141853968897], [-0.6358105294073344, 0.10945414424587627, -0.7640449993306467], [-0.6563156541418083, -0.7540754527425505, 0.02489927106418534], [-0.6786431973610589, 0.7310891291870891, -0.07037112944967187], [-0.4811873975065912, 0.6311221524080541, 0.6083942120210042], [-0.45003670932430556, 0.03878241791959169, -0.8921675203238799], [0.6228527841744597, -0.6653027350879948, 0.41161472268440236], [0.6076207751533917, 0.7684224591058331, 0.20080816204461294], [-0.47346951581333485, -0.8807991463945936, -0.004413763251659698], [-0.4682630830342496, -0.8296214355564143, 0.30406900324198416], [0.08447334066555273, -0.9784197703126144, -0.1885709621819129], [0.2965512007803297, 0.8339510970983991, -0.4653847364967197], [0.16956192196161413, 0.6582166746269409, 0.7334845355314148], [-0.9267349967770295, 0.16529078275522413, -0.33740362014187747], [0.9155363444953903, 0.35972750142374055, 0.17997034930079664], [-0.2627253443826455, 0.9008719953020612, 0.3455503458246037], [0.8529106035057721, -0.5217803533335451, 0.016993095731516174], [0.8154965487747823, -0.21995267089048656, -0.5353374650671859], [-0.006640233092314377, 0.5373492646953814, 0.8433336676759755], [-0.7483063574487001, 0.6182553747512798, -0.24041191108805907], [0.3095549491636869, -0.17792809627177064, 0.934086358965471], [0.6412214881552839, 0.5920754635639538, -0.4881410130008052], [-0.6311678912294041, 0.519087959533268, -0.5763460621437569], [-0.5221448195065524, -0.5317466636922998, -0.6667910265702275], [-0.5249865882396665, -0.6938030914144447, -0.49297703041037794], [-0.40160643749158387, 0.3536211784457903, -0.8447865597415296], [-0.5134126179257091, 0.4411424491730167, 0.7360712080310587], [0.2250075280870982, 0.8710978667099899, 0.4365319219913229], [0.01495228087981132, 0.994730219097649, -0.10143086566935319], [-0.6638597776793663, -0.404955775195991, 0.6287296841369241], [-0.4392958717249675, -0.8406796976425278, -0.31666509605112597], [-0.26659411752007567, -0.6500394140441671, 0.7116012483777752], [-0.8984870448276888, -0.4081257483950943, 0.16172323201615418], [0.36140760751015194, -0.2170869474020806, -0.9067843175206739], [0.8486202896097379, -0.09796736733565162, 0.519851901025673], [0.127849511096763, -0.674209354109659, -0.7273900256006781], [0.518427313125392, -0.8234019435730732, 0.23074306127308045], [0.9650569845529166, 0.09810278400656894, 0.24298325114252675], [-0.9346830662641769, 0.35157559207303607, 0.052556338318899824], [0.7077898258883245, 0.4704338591434144, 0.5269967234626886], [0.3546125636716819, 0.3278751889086917, 0.8756413593385634], [0.16926310288516716, -0.9584900993703757, 0.2294487555221268], [0.897204853657943, 0.12553490960663766, 0.4233963120324529], [0.053402856415211544, 0.7989620978572675, 0.599005593558366], [-0.21439356187986022, 0.9765274335157839, 0.02072612398744471], [-0.7011707501688357, -0.61941692916902, -0.35310373400247924], [-0.33731618237682154, -0.7383023287929298, -0.5840611820739874], [0.8554557563450582, 0.03283817503637466, -0.516833728772015], [-0.5634559271627959, 0.25354884099504926, 0.7862762894652117], [0.8968492815056062, -0.31262966307002854, -0.3129282026785035], [0.23461921803172875, -0.5162143097990478, 0.8236969156727934], [-0.8204680841151809, 0.48423123492129905, 0.30389510373640133], [0.10616736913570804, -0.38341718225424076, 0.91745286204961], [0.46062712280394524, -0.5594614288453051, 0.6890758763530536], [-0.1284525648298974, -0.3901420195240853, -0.9117505926459765], [-0.9981858386470472, -0.03776949080309614, -0.04688813377567692], [0.8018003081854409, -0.42333591045686064, 0.4217854581554381], [-0.804564241947829, -0.5709043128795017, -0.1635379042133632], [-0.08185104459845471, 0.1683038448200658, -0.982331014636576], [-0.7694039392163629, -0.18319863207708384, 0.6119279692279385], [0.9771855594361627, 0.10062464178253448, -0.18703760021870053], [0.5544396573972501, 0.28994491883968493, -0.7800824381719336], [-0.758345834263166, 0.6333345963987281, 0.1542688713258864], [-0.008491374376512522, -0.9134942753168819, 0.406762959872802], [-0.33408495344564276, -0.5264650528017564, -0.7818067485380684], [-0.8490007870709428, -0.37197966409990957, -0.3752716256913624], [-0.7730552646309329, -0.5612335110585454, 0.29563914472088426], [0.09753474452626759, 0.5522652919731552, -0.8279432473859555], [0.39648818965076155, -0.905216710214534, -0.15290462064907687], [-0.1569394746409091, -0.11785032825512229, 0.9805515292066987], [0.7163296125291237, -0.39081821229481717, -0.5780423956359592], [0.13548268481111322, 0.7860934232611066, -0.6030767546689287], [0.5914606174806543, 0.3286174092947817, 0.7363320828795857], [0.29537992934537066, -0.7383837478422289, -0.6062508872260621], [0.06313639344439587, -0.6614479580092971, 0.7473288397139278], [-0.10595853244500857, 0.8106792651714269, -0.5758228186024026], [-0.7403016482988084, -0.04845379072284895, -0.6705264347441149], [-0.3958985620837825, 0.9100009927420025, -0.12313619187129128], [-0.45922932850265336, -0.5350173036318506, 0.7091296839489278], [-0.1731172234412477, -0.9436238213650994, 0.28214271335676944], [-0.11188122244125578, -0.04732959379475322, -0.9925938250947736], [-0.6683760509590289, 0.5650410314753236, 0.4837376223261077], [0.9712144606432573, -0.19114858948972396, 0.14214319601555236], [0.44273528725858635, -0.02275450780199933, -0.8963635968683388], [-0.8140656997372473, -0.5794002472143346, 0.03990476211273668], [-0.3359194056345811, -0.9317011148077221, 0.1381708564935365], [-0.06923545147783519, -0.9458561272097491, -0.31711612837955017], [0.5439160463838949, 0.15421703997322497, 0.8248469185661116], [0.8832364379525733, -0.4070790706222847, 0.23276603045579253], [-0.14837564601727582, -0.987793454320691, -0.04742108465812609], [0.16844527590972794, -0.08099813714642741, -0.9823774685946864], [-0.5657172345739175, 0.8193680331828437, 0.09273638285008484], [-0.30564437074087397, 0.6990892393320208, -0.6464176313225001], [-0.33674237640441124, -0.4062997510358398, 0.8494263265532358], [0.21057631941470467, -0.37836730611748437, -0.9013854865500964], [-0.11220515108413405, 0.8641036629287703, 0.4906473925165289], [0.5858354735579581, -0.31634262021302556, 0.74613949403438], [-0.6249590778828292, -0.0718174049830824, 0.777347034028779], [0.30451610664627105, 0.9365585299609991, 0.17357436662793618], [-0.769983500323991, -0.24317770154146764, -0.5899067847565609], [0.9128149561032868, 0.22491928616326284, -0.3408521242796691], [0.7027033101604571, -0.10855427994511252, -0.703152918073398], [-0.020760184088504045, 0.24789364919648074, 0.968564790524962], [0.4714908883810572, 0.7023783523013336, -0.5332550912950622], [-0.4358909668539538, 0.7691980152869542, -0.46726168074617036], [0.6175210102440779, -0.7194187886331095, -0.3179691942135319], [-0.28258906393499694, -0.1383212542658785, -0.9492158087403815], [-0.308452947386237, 0.5188463293337624, 0.7972799168332438], [-0.4481642153318607, 0.7947501233527182, 0.40929338808099125], [-0.9823715121471719, 0.14698516387600186, 0.11550573025622488], [0.13128252284828998, 0.34854705966776073, -0.9280516399379652], [-0.37355690869820035, -0.1793186040240473, 0.9101099242480061], [0.9596810424419, 0.28105208802161097, -0.004692610821361775], [0.7595309788778034, -0.28634046819989484, 0.5840563572087807], [0.8137308187384077, 0.3764390859035117, -0.44287218160486136], [0.9347893044111636, -0.08032069257362752, -0.34600222933239266], [0.2683002097771993, -0.8777526186055356, 0.396945006222066], [-0.6342524888407755, -0.7323670273520221, 0.24771418539688939], [0.6358105294073343, -0.1094541442458756, 0.7640449993306471], [0.6563156541418086, 0.7540754527425502, -0.024899271064185664], [0.6786431973610586, -0.7310891291870895, 0.070371129449672], [0.4811873975065908, -0.6311221524080548, -0.608394212021004], [0.4500367093243048, -0.03878241791959168, 0.8921675203238802], [-0.6228527841744596, 0.6653027350879949, -0.41161472268440247], [-0.6076207751533923, -0.768422459105833, -0.2008081620446126], [0.47346951581333496, 0.8807991463945934, 0.004413763251660042], [0.46826308303425, 0.8296214355564147, -0.3040690032419826], [-0.08447334066555305, 0.9784197703126143, 0.1885709621819126], [-0.2965512007803294, -0.8339510970983987, 0.4653847364967206], [-0.16956192196161457, -0.6582166746269407, -0.733484535531415], [0.9267349967770298, -0.16529078275522432, 0.33740362014187697], [-0.9155363444953903, -0.3597275014237403, -0.1799703493007974], [0.262725344382645, -0.9008719953020613, -0.345550345824604], [-0.8529106035057722, 0.5217803533335449, -0.016993095731516052], [-0.8154965487747817, 0.21995267089048692, 0.5353374650671865], [0.006640233092314197, -0.5373492646953808, -0.8433336676759758], [0.7483063574487, -0.61825537475128, 0.24041191108805898], [-0.3095549491636874, 0.1779280962717704, -0.9340863589654709], [-0.6412214881552835, -0.5920754635639552, 0.48814101300080415], [0.6311678912294046, -0.5190879595332676, 0.5763460621437568], [0.522144819506553, 0.5317466636922993, 0.6667910265702276], [0.5249865882396664, 0.693803091414444, 0.492977030410379], [0.4016064374915847, -0.35362117844579, 0.8447865597415294], [0.5134126179257101, -0.44114244917301687, -0.736071208031058], [-0.22500752808709862, -0.8710978667099897, -0.436531921991323], [-0.014952280879811639, -0.994730219097649, 0.10143086566935354], [0.6638597776793657, 0.4049557751959896, -0.6287296841369258], [0.43929587172496737, 0.8406796976425275, 0.31666509605112736], [0.2665941175200767, 0.6500394140441684, -0.7116012483777735], [0.8984870448276885, 0.4081257483950952, -0.1617232320161543], [-0.36140760751015083, 0.2170869474020804, 0.9067843175206743], [-0.8486202896097377, 0.0979673673356518, -0.5198519010256732], [-0.1278495110967629, 0.6742093541096598, 0.7273900256006773], [-0.5184273131253924, 0.8234019435730728, -0.23074306127308053], [-0.9650569845529168, -0.09810278400656879, -0.2429832511425262], [0.934683066264177, -0.35157559207303596, -0.05255633831889993], [-0.7077898258883238, -0.4704338591434147, -0.5269967234626892], [-0.3546125636716822, -0.3278751889086909, -0.8756413593385636], [-0.16926310288516747, 0.9584900993703757, -0.22944875552212646], [-0.8972048536579433, -0.12553490960663727, -0.42339631203245265], [-0.0534028564152116, -0.7989620978572671, -0.5990055935583666], [0.21439356187985967, -0.976527433515784, -0.020726123987444584], [0.7011707501688349, 0.6194169291690204, 0.35310373400247974], [0.3373161823768212, 0.7383023287929297, 0.5840611820739878], [-0.8554557563450577, -0.0328381750363741, 0.516833728772016], [0.5634559271627959, -0.25354884099504865, -0.7862762894652118], [-0.8968492815056059, 0.3126296630700283, 0.31292820267850424], [-0.23461921803172814, 0.5162143097990476, -0.8236969156727937], [0.8204680841151808, -0.48423123492129955, -0.303895103736401], [-0.1061673691357072, 0.3834171822542412, -0.9174528620496099], [-0.46062712280394497, 0.559461428845305, -0.6890758763530538], [0.12845256482989664, 0.3901420195240855, 0.9117505926459765], [0.9981858386470472, 0.03776949080309688, 0.046888133775677486], [-0.8018003081854406, 0.4233359104568611, -0.42178545815543844], [0.8045642419478288, 0.570904312879502, 0.16353790421336376], [0.08185104459845317, -0.16830384482006544, 0.9823310146365762], [0.7694039392163625, 0.18319863207708306, -0.611927969227939], [-0.9771855594361627, -0.10062464178253405, 0.18703760021870042], [-0.5544396573972512, -0.289944918839686, 0.7800824381719323], [0.758345834263166, -0.6333345963987282, -0.15426887132588604], [0.00849137437651162, 0.9134942753168819, -0.40676295987280187], [0.33408495344564276, 0.5264650528017565, 0.7818067485380683], [0.849000787070943, 0.3719796640999098, 0.37527162569136213], [0.7730552646309327, 0.5612335110585451, -0.2956391447208852], [-0.09753474452626576, -0.5522652919731545, 0.8279432473859561], [-0.39648818965076205, 0.9052167102145339, 0.15290462064907656], [0.15693947464090713, 0.11785032825512202, -0.9805515292066991], [-0.7163296125291233, 0.39081821229481706, 0.5780423956359597], [-0.13548268481111353, -0.786093423261106, 0.6030767546689295], [-0.5914606174806544, -0.32861740929478245, -0.7363320828795854], [-0.29537992934537166, 0.7383837478422289, 0.6062508872260617], [-0.0631363934443951, 0.661447958009296, -0.7473288397139288], [0.10595853244500836, -0.8106792651714273, 0.575822818602402], [0.7403016482988082, 0.04845379072284902, 0.670526434744115], [0.39589856208378216, -0.9100009927420026, 0.12313619187129096], [0.45922932850265347, 0.5350173036318514, -0.7091296839489272], [0.173117223441247, 0.9436238213650995, -0.2821427133567697], [0.11188122244125702, 0.047329593794752316, 0.9925938250947735], [0.6683760509590285, -0.565041031475324, -0.48373762232610773], [-0.9712144606432572, 0.1911485894897237, -0.1421431960155527], [-0.4427352872585862, 0.02275450780200047, 0.8963635968683389], [0.8140656997372471, 0.5794002472143348, -0.03990476211273634], [0.33591940563458067, 0.9317011148077223, -0.13817085649353636], [0.06923545147783511, 0.9458561272097492, 0.3171161283795496], [-0.5439160463838951, -0.1542170399732247, -0.8248469185661114], [-0.8832364379525734, 0.4070790706222843, -0.23276603045579286], [0.14837564601727615, 0.9877934543206909, 0.047421084658126215], [-0.1684452759097269, 0.08099813714642701, 0.9823774685946867], [0.5657172345739174, -0.8193680331828438, -0.09273638285008516], [0.3056443707408742, -0.6990892393320212, 0.6464176313224997], [0.33674237640441157, 0.4062997510358407, -0.8494263265532352], [-0.21057631941470442, 0.3783673061174838, 0.9013854865500968], [0.11220515108413351, -0.8641036629287699, -0.49064739251652956], [-0.5858354735579577, 0.316342620213026, -0.74613949403438], [0.6249590778828292, 0.07181740498308149, -0.7773470340287791], [-0.3045161066462703, -0.9365585299609994, -0.17357436662793585], [0.7699835003239904, 0.24317770154146773, 0.5899067847565614], [-0.9128149561032868, -0.22491928616326198, 0.3408521242796696], [-0.7027033101604563, 0.10855427994511174, 0.7031529180733989], [0.020760184088504535, -0.24789364919648157, -0.9685647905249618], [-0.4714908883810563, -0.7023783523013324, 0.5332550912950645], [0.4358909668539541, -0.7691980152869542, 0.46726168074616986], [-0.6175210102440782, 0.7194187886331092, 0.31796919421353204], [0.28258906393499733, 0.1383212542658797, 0.9492158087403811], [0.30845294738623813, -0.5188463293337621, -0.7972799168332437], [0.44816421533186007, -0.7947501233527184, -0.4092933880809911], [0.9823715121471721, -0.146985163876001, -0.11550573025622408], [-0.13128252284828998, -0.3485470596677601, 0.9280516399379655], [0.3735569086981984, 0.17931860402404787, -0.9101099242480067]]} +RLMATH_EOF diff --git a/tasks/construct-ae-p32-spherical-design-l6-s0/tests/check.py b/tasks/construct-ae-p32-spherical-design-l6-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..5973c15b3df2d6228d713d9b186ced8e47dcbb48 --- /dev/null +++ b/tasks/construct-ae-p32-spherical-design-l6-s0/tests/check.py @@ -0,0 +1,53 @@ +"""Spherical t-design with N points on S^2 (numerical, tolerance 1e-10 on every harmonic average). + +Upstream (AlphaEvolve `spherical_t_designs.ipynb`) scored sum_k dim_k/C_k(1) * sum_{i,j} C_k(), whose +pair sums cancel to ~1e-10 in float64 and can even go negative; its printed acceptance test +`calculate_design_score(...) < 1e-8` compares the NEGATED error and is therefore always true (bug). Here we +evaluate the point averages of an orthonormal real spherical-harmonic basis directly (no cancellation). +""" +import numpy as np + +from run import Invalid, float_matrix + +TOL = 1e-10 + + +def harmonics(X, t): + """Rows: real spherical harmonics Y_lm (1 <= l <= t) normalised so that their mean square on S^2 is 1.""" + ct = np.clip(X[:, 2], -1.0, 1.0) + st = np.sqrt(np.maximum(0.0, 1.0 - ct * ct)) + ph = np.arctan2(X[:, 1], X[:, 0]) + P = {(0, 0): np.ones_like(ct)} + for m in range(1, t + 1): + P[(m, m)] = (np.sqrt(3.0) if m == 1 else np.sqrt((2 * m + 1) / (2 * m))) * st * P[(m - 1, m - 1)] + for m in range(0, t): + P[(m + 1, m)] = np.sqrt(2 * m + 3) * ct * P[(m, m)] + for m in range(0, t + 1): + for l in range(m + 2, t + 1): + a = np.sqrt((4 * l * l - 1) / (l * l - m * m)) + b = np.sqrt(((l - 1) ** 2 - m * m) / (4 * (l - 1) ** 2 - 1)) + P[(l, m)] = a * (ct * P[(l - 1, m)] - b * P[(l - 2, m)]) + rows = [] + for l in range(1, t + 1): + rows.append(P[(l, 0)]) + for m in range(1, l + 1): + rows.append(P[(l, m)] * np.cos(m * ph)) + rows.append(P[(l, m)] * np.sin(m * ph)) + return np.array(rows) + + +def check(inst, ans): + t, n = inst["t"], inst["N"] + X = np.array(float_matrix(ans.get("points"), n, 3, "points")) + nr = np.linalg.norm(X, axis=1) + if nr.min() < 0.5 or nr.max() > 2.0: + raise Invalid("points must be (approximately) unit vectors") + X = X / nr[:, None] + G = X @ X.T + np.fill_diagonal(G, -1.0) + if G.max() > 1.0 - 1e-8: + raise Invalid("two points coincide (or nearly: distance < 1.4e-4)") + dev = np.abs(harmonics(X, t).mean(axis=1)).max() + if not dev <= TOL: + raise Invalid(f"not a {t}-design: some harmonic of degree <= {t} has point average {dev:.3e} > {TOL}") + return None, {"max_harmonic_average": float(dev)} diff --git a/tasks/construct-ae-p32-spherical-design-l6-s0/tests/instance.json b/tasks/construct-ae-p32-spherical-design-l6-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..71bf522ba3d4386d040dd1d0a2f16f86e9c942ad --- /dev/null +++ b/tasks/construct-ae-p32-spherical-design-l6-s0/tests/instance.json @@ -0,0 +1 @@ +{"t": 21, "N": 234, "family": "ae_p32_spherical_designs", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p32-spherical-design-l6-s0/tests/run.py b/tasks/construct-ae-p32-spherical-design-l6-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p32-spherical-design-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-ae-p32-spherical-design-l6-s0/tests/test.sh b/tasks/construct-ae-p32-spherical-design-l6-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p32-spherical-design-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-ae-p38-factorial-factors-l1-s9/environment/Dockerfile b/tasks/construct-ae-p38-factorial-factors-l1-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l1-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-ae-p38-factorial-factors-l1-s9/environment/instance.json b/tasks/construct-ae-p38-factorial-factors-l1-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..767db1c255d132e6b945caf3184e54da89f7cf5c --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l1-s9/environment/instance.json @@ -0,0 +1 @@ +{"N": 59, "t": 17, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l1-s9/solution/solve.sh b/tasks/construct-ae-p38-factorial-factors-l1-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..029fe52f2876be3dd621f3ba1b6ed621d73dbfe6 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l1-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' +{"factors": [17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 23, 23, 24, 24, 24, 24, 26, 26, 26, 26, 29, 29, 31, 37, 41, 43, 47, 53, 59]} +RLMATH_EOF diff --git a/tasks/construct-ae-p38-factorial-factors-l1-s9/tests/check.py b/tasks/construct-ae-p38-factorial-factors-l1-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..93ec67a19039afa8b4ce6e39811691b802132562 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l1-s9/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-l1-s9/tests/instance.json b/tasks/construct-ae-p38-factorial-factors-l1-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..767db1c255d132e6b945caf3184e54da89f7cf5c --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l1-s9/tests/instance.json @@ -0,0 +1 @@ +{"N": 59, "t": 17, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l1-s9/tests/run.py b/tasks/construct-ae-p38-factorial-factors-l1-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l1-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-ae-p38-factorial-factors-l1-s9/tests/test.sh b/tasks/construct-ae-p38-factorial-factors-l1-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l1-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-ae-p38-factorial-factors-l5-s1/environment/Dockerfile b/tasks/construct-ae-p38-factorial-factors-l5-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l5-s1/environment/instance.json b/tasks/construct-ae-p38-factorial-factors-l5-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2215fae0b77129c753f72ca6a3de5595ddb6378d --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l5-s1/environment/instance.json @@ -0,0 +1 @@ +{"N": 1725, "t": 546, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l5-s1/solution/solve.sh b/tasks/construct-ae-p38-factorial-factors-l5-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..344084aa45c439a8331d51f344bb5b92442f4a23 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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' +{"factors": [546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 546, 547, 547, 547, 548, 548, 548, 548, 548, 548, 548, 548, 548, 548, 548, 548, 549, 549, 549, 549, 549, 549, 549, 549, 549, 549, 549, 549, 549, 549, 549, 549, 549, 549, 549, 549, 549, 549, 549, 549, 549, 549, 549, 549, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 550, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 551, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 553, 553, 553, 553, 553, 553, 553, 553, 553, 553, 553, 553, 553, 553, 553, 553, 553, 553, 553, 553, 553, 554, 554, 554, 554, 554, 554, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 556, 556, 556, 556, 556, 556, 556, 556, 556, 556, 556, 556, 557, 557, 557, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 558, 559, 559, 559, 559, 559, 559, 559, 559, 559, 559, 559, 559, 559, 559, 559, 559, 559, 559, 559, 559, 559, 559, 559, 559, 559, 559, 559, 559, 559, 559, 559, 559, 559, 559, 559, 559, 559, 559, 559, 559, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 561, 561, 561, 561, 561, 561, 561, 561, 561, 561, 561, 561, 561, 561, 561, 561, 561, 561, 561, 561, 561, 561, 561, 561, 561, 561, 561, 561, 561, 561, 562, 562, 562, 562, 562, 562, 563, 563, 563, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 565, 565, 565, 565, 565, 565, 565, 565, 565, 565, 565, 565, 565, 565, 565, 566, 566, 566, 566, 566, 566, 567, 567, 567, 567, 567, 567, 567, 567, 567, 567, 567, 567, 567, 567, 567, 567, 567, 567, 568, 568, 568, 568, 568, 568, 568, 568, 568, 568, 568, 568, 568, 568, 568, 568, 568, 568, 568, 568, 568, 568, 568, 568, 569, 569, 569, 570, 570, 570, 570, 570, 570, 570, 570, 570, 570, 570, 570, 570, 570, 570, 570, 570, 570, 570, 570, 570, 570, 570, 570, 570, 570, 570, 570, 570, 570, 570, 570, 570, 571, 571, 571, 573, 573, 573, 573, 573, 573, 573, 573, 573, 574, 574, 574, 574, 574, 574, 574, 574, 574, 574, 574, 574, 574, 574, 574, 574, 574, 574, 574, 574, 574, 574, 574, 574, 574, 574, 574, 574, 574, 574, 574, 574, 574, 574, 574, 574, 574, 574, 574, 574, 574, 574, 574, 576, 576, 576, 576, 576, 576, 576, 576, 576, 576, 576, 576, 576, 576, 576, 576, 576, 576, 576, 576, 576, 576, 576, 576, 576, 576, 577, 577, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 579, 579, 579, 579, 579, 579, 579, 579, 581, 581, 581, 581, 581, 581, 581, 581, 581, 581, 581, 581, 581, 581, 581, 581, 581, 581, 581, 581, 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 584, 584, 584, 584, 584, 584, 584, 584, 584, 584, 584, 584, 584, 584, 584, 584, 584, 584, 584, 584, 584, 584, 584, 586, 586, 586, 586, 586, 587, 587, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 591, 591, 591, 591, 591, 591, 591, 591, 592, 593, 593, 596, 596, 596, 596, 596, 596, 596, 596, 596, 596, 596, 597, 597, 597, 597, 597, 597, 597, 597, 599, 599, 601, 601, 603, 603, 603, 603, 603, 603, 603, 603, 603, 603, 603, 603, 603, 603, 603, 603, 603, 603, 603, 603, 603, 603, 603, 603, 603, 604, 604, 604, 604, 604, 604, 604, 604, 604, 604, 604, 606, 606, 606, 606, 606, 606, 606, 606, 606, 606, 606, 606, 606, 606, 606, 606, 606, 607, 607, 613, 613, 614, 614, 614, 614, 614, 617, 617, 618, 618, 618, 618, 618, 618, 618, 618, 618, 618, 618, 618, 618, 618, 618, 618, 619, 619, 622, 622, 622, 622, 622, 623, 623, 623, 623, 623, 623, 623, 623, 623, 623, 623, 623, 623, 623, 623, 623, 623, 623, 623, 626, 626, 626, 626, 626, 628, 628, 628, 628, 628, 628, 628, 628, 628, 628, 631, 631, 633, 633, 633, 633, 633, 633, 633, 633, 634, 634, 634, 634, 634, 635, 635, 635, 635, 635, 635, 635, 635, 635, 635, 635, 635, 635, 637, 637, 640, 641, 641, 642, 642, 642, 642, 642, 642, 642, 642, 642, 642, 642, 642, 642, 642, 642, 642, 643, 643, 647, 647, 652, 652, 652, 652, 652, 652, 652, 652, 652, 652, 653, 653, 654, 654, 654, 654, 654, 654, 654, 654, 654, 654, 654, 654, 654, 654, 654, 655, 655, 655, 655, 655, 655, 655, 655, 655, 655, 655, 655, 655, 659, 659, 661, 661, 662, 662, 662, 662, 662, 668, 668, 668, 668, 668, 668, 668, 668, 668, 668, 669, 669, 669, 669, 669, 669, 669, 673, 673, 674, 674, 674, 674, 674, 677, 677, 681, 681, 681, 681, 681, 681, 681, 683, 683, 687, 687, 687, 687, 687, 687, 687, 691, 691, 692, 692, 692, 692, 692, 692, 692, 692, 692, 694, 694, 694, 694, 698, 698, 698, 698, 699, 699, 699, 699, 699, 699, 699, 701, 701, 706, 706, 706, 706, 709, 709, 716, 716, 716, 716, 716, 716, 716, 716, 716, 717, 717, 717, 717, 717, 717, 717, 718, 718, 718, 718, 719, 719, 723, 723, 723, 723, 723, 723, 723, 724, 724, 724, 724, 724, 724, 724, 724, 724, 727, 727, 733, 733, 734, 734, 734, 734, 739, 739, 743, 743, 746, 746, 746, 746, 751, 751, 753, 753, 753, 753, 753, 753, 757, 757, 758, 758, 758, 758, 761, 761, 766, 766, 766, 766, 769, 769, 771, 771, 771, 771, 771, 771, 773, 773, 778, 778, 778, 778, 787, 787, 789, 789, 789, 789, 789, 789, 794, 794, 794, 794, 797, 797, 802, 802, 802, 802, 807, 807, 807, 807, 807, 807, 809, 809, 811, 811, 813, 813, 813, 813, 813, 813, 818, 818, 818, 818, 821, 821, 823, 823, 827, 827, 829, 829, 838, 838, 838, 838, 839, 839, 842, 842, 842, 842, 853, 853, 857, 857, 859, 859, 862, 862, 862, 862, 863, 866, 866, 866, 877, 878, 878, 878, 881, 883, 886, 886, 886, 887, 898, 898, 898, 907, 911, 914, 914, 914, 919, 922, 922, 922, 926, 926, 926, 929, 934, 934, 934, 937, 941, 947, 953, 958, 958, 958, 967, 971, 974, 974, 974, 977, 982, 982, 982, 983, 991, 997, 998, 998, 998, 1006, 1006, 1006, 1009, 1013, 1018, 1018, 1018, 1019, 1021, 1031, 1033, 1039, 1042, 1042, 1042, 1046, 1046, 1046, 1049, 1051, 1061, 1063, 1069, 1082, 1082, 1082, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723]} +RLMATH_EOF diff --git a/tasks/construct-ae-p38-factorial-factors-l5-s1/tests/check.py b/tasks/construct-ae-p38-factorial-factors-l5-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..93ec67a19039afa8b4ce6e39811691b802132562 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l5-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-l5-s1/tests/instance.json b/tasks/construct-ae-p38-factorial-factors-l5-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2215fae0b77129c753f72ca6a3de5595ddb6378d --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l5-s1/tests/instance.json @@ -0,0 +1 @@ +{"N": 1725, "t": 546, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l5-s1/tests/run.py b/tasks/construct-ae-p38-factorial-factors-l5-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l5-s1/tests/test.sh b/tasks/construct-ae-p38-factorial-factors-l5-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l5-s6/environment/Dockerfile b/tasks/construct-ae-p38-factorial-factors-l5-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l5-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-l5-s6/environment/instance.json b/tasks/construct-ae-p38-factorial-factors-l5-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..75af400129f0d32f41596ca685ba05dd31664084 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l5-s6/environment/instance.json @@ -0,0 +1 @@ +{"N": 2989, "t": 956, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l5-s6/solution/solve.sh b/tasks/construct-ae-p38-factorial-factors-l5-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6825004f8f41d692da0f51a7efdf72f7f736b84a --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l5-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": [2868, 956, 956, 956, 956, 956, 956, 956, 956, 956, 956, 956, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, 958, 958, 958, 958, 958, 958, 959, 959, 959, 959, 959, 959, 959, 959, 959, 959, 959, 959, 959, 959, 959, 959, 959, 959, 959, 959, 959, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 961, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 962, 963, 963, 963, 963, 963, 963, 963, 963, 963, 963, 963, 963, 963, 963, 963, 963, 963, 963, 963, 963, 963, 963, 963, 963, 963, 963, 963, 964, 964, 964, 964, 964, 964, 964, 964, 964, 964, 964, 964, 965, 965, 965, 965, 965, 965, 965, 965, 965, 965, 965, 965, 965, 965, 965, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, 967, 967, 967, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 968, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 969, 970, 970, 970, 970, 970, 970, 970, 970, 970, 970, 970, 970, 970, 970, 970, 970, 970, 970, 970, 970, 970, 970, 970, 970, 970, 970, 970, 970, 970, 970, 971, 971, 971, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, 973, 973, 973, 973, 973, 973, 973, 973, 973, 973, 973, 973, 973, 973, 973, 973, 973, 973, 973, 973, 973, 974, 974, 974, 974, 974, 974, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 975, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 976, 977, 977, 977, 978, 978, 978, 978, 978, 978, 978, 978, 978, 978, 978, 978, 978, 978, 978, 978, 978, 978, 979, 979, 979, 979, 979, 979, 979, 979, 979, 979, 979, 979, 979, 979, 979, 979, 979, 979, 979, 979, 979, 979, 979, 979, 979, 979, 979, 979, 979, 979, 979, 979, 979, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 980, 981, 981, 981, 981, 981, 981, 981, 981, 981, 981, 981, 981, 981, 981, 981, 981, 981, 981, 981, 981, 981, 981, 981, 981, 981, 981, 981, 982, 982, 982, 982, 982, 982, 983, 983, 983, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 985, 985, 985, 985, 985, 985, 985, 985, 985, 985, 985, 985, 985, 985, 985, 986, 986, 986, 986, 986, 986, 986, 986, 986, 986, 986, 986, 986, 986, 986, 986, 986, 986, 986, 986, 986, 986, 986, 986, 986, 986, 986, 986, 986, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 987, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 989, 991, 991, 991, 992, 993, 993, 993, 993, 993, 993, 993, 993, 993, 994, 994, 994, 994, 994, 994, 994, 994, 994, 994, 994, 994, 994, 994, 994, 994, 994, 994, 994, 994, 994, 994, 994, 994, 994, 994, 994, 994, 994, 994, 994, 994, 994, 994, 994, 994, 994, 994, 994, 994, 994, 994, 995, 995, 995, 995, 995, 995, 995, 995, 995, 995, 995, 995, 995, 995, 995, 996, 996, 996, 996, 996, 996, 996, 996, 996, 996, 996, 996, 996, 996, 996, 996, 996, 996, 996, 996, 996, 996, 996, 996, 996, 996, 996, 996, 996, 996, 996, 996, 996, 996, 996, 996, 997, 997, 998, 998, 998, 998, 998, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1003, 1004, 1004, 1004, 1004, 1004, 1004, 1004, 1004, 1004, 1004, 1004, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1006, 1006, 1006, 1006, 1006, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1008, 1008, 1009, 1009, 1010, 1010, 1010, 1010, 1010, 1010, 1010, 1010, 1010, 1010, 1010, 1010, 1010, 1010, 1010, 1010, 1010, 1010, 1010, 1010, 1010, 1010, 1010, 1010, 1010, 1010, 1010, 1010, 1010, 1011, 1011, 1011, 1011, 1011, 1011, 1011, 1011, 1013, 1013, 1015, 1016, 1016, 1016, 1016, 1016, 1016, 1016, 1016, 1016, 1016, 1016, 1016, 1016, 1016, 1016, 1016, 1016, 1016, 1016, 1016, 1016, 1016, 1016, 1017, 1017, 1017, 1017, 1017, 1017, 1017, 1017, 1017, 1017, 1017, 1017, 1017, 1017, 1017, 1017, 1017, 1017, 1017, 1017, 1017, 1017, 1017, 1017, 1017, 1017, 1018, 1018, 1018, 1018, 1018, 1019, 1019, 1021, 1021, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1028, 1028, 1028, 1028, 1028, 1028, 1028, 1028, 1028, 1028, 1028, 1029, 1029, 1030, 1030, 1030, 1030, 1030, 1030, 1030, 1030, 1030, 1030, 1030, 1030, 1030, 1030, 1030, 1030, 1030, 1030, 1030, 1030, 1030, 1030, 1030, 1030, 1030, 1030, 1030, 1030, 1030, 1031, 1031, 1033, 1033, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1039, 1039, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1042, 1042, 1042, 1042, 1042, 1043, 1043, 1043, 1043, 1043, 1043, 1043, 1043, 1043, 1043, 1043, 1043, 1043, 1043, 1043, 1043, 1043, 1043, 1043, 1043, 1046, 1046, 1046, 1046, 1046, 1047, 1047, 1047, 1047, 1047, 1047, 1047, 1047, 1048, 1048, 1048, 1048, 1048, 1048, 1048, 1048, 1048, 1048, 1048, 1048, 1048, 1048, 1048, 1048, 1048, 1048, 1048, 1048, 1048, 1048, 1049, 1049, 1051, 1051, 1052, 1052, 1052, 1052, 1052, 1052, 1052, 1052, 1052, 1052, 1052, 1055, 1055, 1055, 1055, 1055, 1055, 1055, 1055, 1055, 1055, 1055, 1055, 1055, 1055, 1057, 1057, 1057, 1057, 1057, 1057, 1057, 1057, 1057, 1057, 1057, 1057, 1057, 1057, 1057, 1057, 1057, 1057, 1057, 1059, 1059, 1059, 1059, 1059, 1059, 1059, 1059, 1061, 1061, 1063, 1063, 1069, 1069, 1074, 1074, 1074, 1074, 1074, 1074, 1074, 1074, 1074, 1074, 1074, 1074, 1074, 1074, 1074, 1074, 1076, 1076, 1076, 1076, 1076, 1076, 1076, 1076, 1076, 1076, 1076, 1077, 1077, 1077, 1077, 1077, 1077, 1077, 1077, 1082, 1082, 1082, 1082, 1082, 1084, 1084, 1084, 1084, 1084, 1084, 1084, 1084, 1084, 1084, 1084, 1086, 1086, 1086, 1086, 1086, 1086, 1086, 1086, 1086, 1086, 1086, 1086, 1086, 1086, 1086, 1086, 1087, 1087, 1091, 1091, 1093, 1093, 1094, 1094, 1094, 1094, 1094, 1097, 1097, 1099, 1099, 1099, 1099, 1099, 1099, 1099, 1099, 1099, 1099, 1099, 1099, 1099, 1099, 1099, 1099, 1099, 1099, 1099, 1101, 1101, 1101, 1101, 1101, 1101, 1101, 1101, 1103, 1103, 1108, 1108, 1108, 1108, 1108, 1108, 1108, 1108, 1108, 1108, 1109, 1109, 1114, 1114, 1114, 1114, 1114, 1115, 1115, 1115, 1115, 1115, 1115, 1115, 1115, 1115, 1115, 1115, 1115, 1115, 1117, 1117, 1119, 1119, 1119, 1119, 1119, 1119, 1119, 1119, 1121, 1123, 1123, 1124, 1124, 1124, 1124, 1124, 1124, 1124, 1124, 1124, 1124, 1126, 1126, 1126, 1126, 1126, 1129, 1129, 1132, 1132, 1132, 1132, 1132, 1132, 1132, 1132, 1132, 1132, 1135, 1135, 1135, 1135, 1135, 1135, 1135, 1135, 1135, 1135, 1135, 1135, 1135, 1137, 1137, 1137, 1137, 1137, 1137, 1137, 1138, 1138, 1138, 1138, 1138, 1142, 1142, 1142, 1142, 1142, 1145, 1145, 1145, 1145, 1145, 1145, 1145, 1145, 1145, 1145, 1145, 1145, 1145, 1146, 1146, 1146, 1146, 1146, 1146, 1146, 1146, 1146, 1146, 1146, 1146, 1146, 1146, 1146, 1149, 1149, 1149, 1149, 1149, 1149, 1149, 1151, 1151, 1153, 1153, 1154, 1154, 1154, 1154, 1154, 1163, 1163, 1165, 1165, 1165, 1165, 1165, 1165, 1165, 1165, 1165, 1165, 1165, 1165, 1167, 1167, 1167, 1167, 1167, 1167, 1167, 1171, 1171, 1172, 1172, 1172, 1172, 1172, 1172, 1172, 1172, 1172, 1172, 1174, 1174, 1174, 1174, 1174, 1181, 1181, 1186, 1186, 1186, 1186, 1186, 1187, 1187, 1191, 1191, 1191, 1191, 1191, 1191, 1191, 1193, 1193, 1198, 1198, 1198, 1198, 1201, 1201, 1202, 1202, 1202, 1202, 1203, 1203, 1203, 1203, 1203, 1203, 1203, 1213, 1213, 1214, 1214, 1214, 1214, 1217, 1217, 1223, 1223, 1226, 1226, 1226, 1226, 1227, 1227, 1227, 1227, 1227, 1227, 1227, 1228, 1228, 1228, 1228, 1228, 1228, 1228, 1228, 1228, 1229, 1229, 1231, 1231, 1234, 1234, 1234, 1234, 1237, 1237, 1238, 1238, 1238, 1238, 1244, 1244, 1244, 1244, 1244, 1244, 1244, 1244, 1244, 1249, 1249, 1252, 1252, 1252, 1252, 1252, 1252, 1252, 1252, 1252, 1257, 1257, 1257, 1257, 1257, 1257, 1257, 1259, 1259, 1262, 1262, 1262, 1262, 1263, 1263, 1263, 1263, 1263, 1263, 1263, 1268, 1268, 1268, 1268, 1268, 1268, 1268, 1268, 1268, 1277, 1277, 1279, 1279, 1282, 1282, 1282, 1282, 1283, 1283, 1286, 1286, 1286, 1286, 1289, 1289, 1291, 1291, 1293, 1293, 1293, 1293, 1293, 1293, 1294, 1294, 1294, 1294, 1297, 1297, 1299, 1299, 1299, 1299, 1299, 1299, 1301, 1301, 1303, 1303, 1306, 1306, 1306, 1306, 1307, 1307, 1317, 1317, 1317, 1317, 1317, 1317, 1318, 1318, 1318, 1318, 1319, 1319, 1321, 1321, 1322, 1322, 1322, 1322, 1327, 1327, 1329, 1329, 1329, 1329, 1329, 1329, 1346, 1346, 1346, 1346, 1347, 1347, 1347, 1347, 1347, 1347, 1354, 1354, 1354, 1354, 1361, 1361, 1366, 1366, 1366, 1366, 1367, 1367, 1371, 1371, 1371, 1371, 1371, 1371, 1373, 1373, 1381, 1381, 1382, 1382, 1382, 1382, 1383, 1383, 1383, 1383, 1383, 1383, 1389, 1389, 1389, 1389, 1389, 1389, 1399, 1399, 1401, 1401, 1401, 1401, 1401, 1401, 1402, 1402, 1402, 1402, 1409, 1409, 1418, 1418, 1418, 1418, 1423, 1423, 1427, 1427, 1429, 1429, 1433, 1433, 1438, 1438, 1438, 1438, 1439, 1439, 1447, 1447, 1451, 1451, 1453, 1453, 1454, 1454, 1454, 1454, 1459, 1459, 1466, 1466, 1466, 1466, 1471, 1471, 1478, 1478, 1478, 1478, 1481, 1481, 1483, 1483, 1486, 1486, 1486, 1486, 1487, 1487, 1489, 1489, 1493, 1493, 1499, 1502, 1502, 1502, 1511, 1514, 1514, 1514, 1522, 1522, 1522, 1523, 1531, 1538, 1538, 1538, 1543, 1546, 1546, 1546, 1549, 1553, 1559, 1567, 1571, 1574, 1574, 1574, 1579, 1583, 1594, 1594, 1594, 1597, 1601, 1607, 1609, 1613, 1618, 1618, 1618, 1619, 1621, 1622, 1622, 1622, 1627, 1637, 1642, 1642, 1642, 1646, 1646, 1646, 1654, 1654, 1654, 1657, 1658, 1658, 1658, 1663, 1667, 1669, 1678, 1678, 1678, 1693, 1697, 1699, 1706, 1706, 1706, 1709, 1714, 1714, 1714, 1718, 1718, 1718, 1721, 1723, 1726, 1726, 1726, 1733, 1741, 1747, 1753, 1754, 1754, 1754, 1759, 1762, 1762, 1762, 1766, 1766, 1766, 1774, 1774, 1774, 1777, 1783, 1787, 1789, 1801, 1811, 1814, 1814, 1814, 1822, 1822, 1822, 1823, 1831, 1838, 1838, 1838, 1847, 1858, 1858, 1858, 1861, 1867, 1871, 1873, 1874, 1874, 1874, 1877, 1879, 1882, 1882, 1882, 1889, 1894, 1894, 1894, 1901, 1906, 1906, 1906, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521, 2531, 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687, 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791, 2797, 2801, 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897, 2903, 2909, 2917, 2927, 2939, 2953, 2957, 2963, 2969, 2971]} +RLMATH_EOF diff --git a/tasks/construct-ae-p38-factorial-factors-l5-s6/tests/check.py b/tasks/construct-ae-p38-factorial-factors-l5-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..93ec67a19039afa8b4ce6e39811691b802132562 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l5-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-l5-s6/tests/instance.json b/tasks/construct-ae-p38-factorial-factors-l5-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..75af400129f0d32f41596ca685ba05dd31664084 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l5-s6/tests/instance.json @@ -0,0 +1 @@ +{"N": 2989, "t": 956, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l5-s6/tests/run.py b/tasks/construct-ae-p38-factorial-factors-l5-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l5-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-l5-s6/tests/test.sh b/tasks/construct-ae-p38-factorial-factors-l5-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l5-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-p52-erdos-squarefree-l1-s2/environment/Dockerfile b/tasks/construct-ae-p52-erdos-squarefree-l1-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l1-s2/environment/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l1-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..122646de2a68ce22d5cd5ffe7e32fff914b96f45 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l1-s2/environment/instance.json @@ -0,0 +1 @@ +{"N": 91, "t": 4, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l1-s2/solution/solve.sh b/tasks/construct-ae-p52-erdos-squarefree-l1-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b4fe921cb53c008dbabfbc68a8723cafd2892b5b --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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' +{"A": [7, 32, 57, 82]} +RLMATH_EOF diff --git a/tasks/construct-ae-p52-erdos-squarefree-l1-s2/tests/check.py b/tasks/construct-ae-p52-erdos-squarefree-l1-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..87e15b242f211059193ba122baecdee9add99130 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l1-s2/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-l1-s2/tests/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l1-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..122646de2a68ce22d5cd5ffe7e32fff914b96f45 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l1-s2/tests/instance.json @@ -0,0 +1 @@ +{"N": 91, "t": 4, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l1-s2/tests/run.py b/tasks/construct-ae-p52-erdos-squarefree-l1-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l1-s2/tests/test.sh b/tasks/construct-ae-p52-erdos-squarefree-l1-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l1-s5/environment/Dockerfile b/tasks/construct-ae-p52-erdos-squarefree-l1-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l1-s5/environment/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l1-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4e835fa1204a6b454e3042bacd7c2f0e16e0a3b1 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l1-s5/environment/instance.json @@ -0,0 +1 @@ +{"N": 80, "t": 3, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l1-s5/solution/solve.sh b/tasks/construct-ae-p52-erdos-squarefree-l1-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..50f3f4974dadd8b33f98b78aaa992c9a3457fa09 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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' +{"A": [7, 32, 57]} +RLMATH_EOF diff --git a/tasks/construct-ae-p52-erdos-squarefree-l1-s5/tests/check.py b/tasks/construct-ae-p52-erdos-squarefree-l1-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..87e15b242f211059193ba122baecdee9add99130 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l1-s5/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-l1-s5/tests/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l1-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4e835fa1204a6b454e3042bacd7c2f0e16e0a3b1 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l1-s5/tests/instance.json @@ -0,0 +1 @@ +{"N": 80, "t": 3, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l1-s5/tests/run.py b/tasks/construct-ae-p52-erdos-squarefree-l1-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l1-s5/tests/test.sh b/tasks/construct-ae-p52-erdos-squarefree-l1-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-mc-all-interval-l1-s0/environment/Dockerfile b/tasks/construct-mc-all-interval-l1-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-all-interval-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-all-interval-l1-s0/environment/instance.json b/tasks/construct-mc-all-interval-l1-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fd255eec72eef77cd31a8056423232bfe8f39c3c --- /dev/null +++ b/tasks/construct-mc-all-interval-l1-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 7, "fixed": [], "family": "mc_all_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-all-interval-l1-s0/solution/solve.sh b/tasks/construct-mc-all-interval-l1-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0df115a602e72f108d53f83a3cdaf19ea57cf844 --- /dev/null +++ b/tasks/construct-mc-all-interval-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' +{"x": [0, 6, 1, 5, 2, 4, 3]} +RLMATH_EOF diff --git a/tasks/construct-mc-all-interval-l1-s0/tests/check.py b/tasks/construct-mc-all-interval-l1-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2e39eec264b6422a47e35921b8cdbe1fa1748307 --- /dev/null +++ b/tasks/construct-mc-all-interval-l1-s0/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-l1-s0/tests/instance.json b/tasks/construct-mc-all-interval-l1-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fd255eec72eef77cd31a8056423232bfe8f39c3c --- /dev/null +++ b/tasks/construct-mc-all-interval-l1-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 7, "fixed": [], "family": "mc_all_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-all-interval-l1-s0/tests/run.py b/tasks/construct-mc-all-interval-l1-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-all-interval-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-all-interval-l1-s0/tests/test.sh b/tasks/construct-mc-all-interval-l1-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-all-interval-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-all-interval-l5-s1/environment/Dockerfile b/tasks/construct-mc-all-interval-l5-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-all-interval-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-all-interval-l5-s1/environment/instance.json b/tasks/construct-mc-all-interval-l5-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b472a1214fc90215265b83b0cda2a087d9e80466 --- /dev/null +++ b/tasks/construct-mc-all-interval-l5-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 40, "fixed": [], "family": "mc_all_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-all-interval-l5-s1/solution/solve.sh b/tasks/construct-mc-all-interval-l5-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..71d19230a3e0ca3f8f1860419911bb70aedb7fbb --- /dev/null +++ b/tasks/construct-mc-all-interval-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' +{"x": [0, 39, 1, 38, 2, 37, 3, 36, 4, 35, 5, 34, 6, 33, 7, 32, 8, 31, 9, 30, 10, 29, 11, 28, 12, 27, 13, 26, 14, 25, 15, 24, 16, 23, 17, 22, 18, 21, 19, 20]} +RLMATH_EOF diff --git a/tasks/construct-mc-all-interval-l5-s1/tests/check.py b/tasks/construct-mc-all-interval-l5-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2e39eec264b6422a47e35921b8cdbe1fa1748307 --- /dev/null +++ b/tasks/construct-mc-all-interval-l5-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-l5-s1/tests/instance.json b/tasks/construct-mc-all-interval-l5-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b472a1214fc90215265b83b0cda2a087d9e80466 --- /dev/null +++ b/tasks/construct-mc-all-interval-l5-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 40, "fixed": [], "family": "mc_all_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-all-interval-l5-s1/tests/run.py b/tasks/construct-mc-all-interval-l5-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-all-interval-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-all-interval-l5-s1/tests/test.sh b/tasks/construct-mc-all-interval-l5-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-all-interval-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-bibd-l2-s3/environment/Dockerfile b/tasks/construct-mc-bibd-l2-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-bibd-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-bibd-l2-s3/environment/instance.json b/tasks/construct-mc-bibd-l2-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..83f4ced7ee947d37c4ad93b03ccfb680a2cfc0cd --- /dev/null +++ b/tasks/construct-mc-bibd-l2-s3/environment/instance.json @@ -0,0 +1 @@ +{"v": 13, "k": 4, "lambda": 1, "b": 13, "family": "mc_bibd", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-bibd-l2-s3/solution/solve.sh b/tasks/construct-mc-bibd-l2-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7371251760038c8eeeeb68f96e4bc96652c93b93 --- /dev/null +++ b/tasks/construct-mc-bibd-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' +{"blocks": [[0, 1, 3, 9], [1, 2, 4, 10], [2, 3, 5, 11], [3, 4, 6, 12], [0, 4, 5, 7], [1, 5, 6, 8], [2, 6, 7, 9], [3, 7, 8, 10], [4, 8, 9, 11], [5, 9, 10, 12], [0, 6, 10, 11], [1, 7, 11, 12], [0, 2, 8, 12]]} +RLMATH_EOF diff --git a/tasks/construct-mc-bibd-l2-s3/tests/check.py b/tasks/construct-mc-bibd-l2-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c4b5da62477026f27ff9869fe33602fcc41e2ea9 --- /dev/null +++ b/tasks/construct-mc-bibd-l2-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-l2-s3/tests/instance.json b/tasks/construct-mc-bibd-l2-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..83f4ced7ee947d37c4ad93b03ccfb680a2cfc0cd --- /dev/null +++ b/tasks/construct-mc-bibd-l2-s3/tests/instance.json @@ -0,0 +1 @@ +{"v": 13, "k": 4, "lambda": 1, "b": 13, "family": "mc_bibd", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-bibd-l2-s3/tests/run.py b/tasks/construct-mc-bibd-l2-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-bibd-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-bibd-l2-s3/tests/test.sh b/tasks/construct-mc-bibd-l2-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-bibd-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-bibd-l2-s4/environment/Dockerfile b/tasks/construct-mc-bibd-l2-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-bibd-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-bibd-l2-s4/environment/instance.json b/tasks/construct-mc-bibd-l2-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5d8417c56d512f9eb0e6a6cd618d0b57283d5487 --- /dev/null +++ b/tasks/construct-mc-bibd-l2-s4/environment/instance.json @@ -0,0 +1 @@ +{"v": 11, "k": 6, "lambda": 3, "b": 11, "family": "mc_bibd", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-bibd-l2-s4/solution/solve.sh b/tasks/construct-mc-bibd-l2-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b14db3426259841fa2c62654ef8a4941c223abb0 --- /dev/null +++ b/tasks/construct-mc-bibd-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' +{"blocks": [[0, 2, 6, 7, 8, 10], [0, 1, 3, 7, 8, 9], [1, 2, 4, 8, 9, 10], [0, 2, 3, 5, 9, 10], [0, 1, 3, 4, 6, 10], [0, 1, 2, 4, 5, 7], [1, 2, 3, 5, 6, 8], [2, 3, 4, 6, 7, 9], [3, 4, 5, 7, 8, 10], [0, 4, 5, 6, 8, 9], [1, 5, 6, 7, 9, 10]]} +RLMATH_EOF diff --git a/tasks/construct-mc-bibd-l2-s4/tests/check.py b/tasks/construct-mc-bibd-l2-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c4b5da62477026f27ff9869fe33602fcc41e2ea9 --- /dev/null +++ b/tasks/construct-mc-bibd-l2-s4/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-l2-s4/tests/instance.json b/tasks/construct-mc-bibd-l2-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5d8417c56d512f9eb0e6a6cd618d0b57283d5487 --- /dev/null +++ b/tasks/construct-mc-bibd-l2-s4/tests/instance.json @@ -0,0 +1 @@ +{"v": 11, "k": 6, "lambda": 3, "b": 11, "family": "mc_bibd", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-bibd-l2-s4/tests/run.py b/tasks/construct-mc-bibd-l2-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-bibd-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-bibd-l2-s4/tests/test.sh b/tasks/construct-mc-bibd-l2-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-bibd-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-debruijn-l6-s3/environment/Dockerfile b/tasks/construct-mc-debruijn-l6-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-debruijn-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-mc-debruijn-l6-s3/environment/instance.json b/tasks/construct-mc-debruijn-l6-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..53f580c0a0e86af16106e32d5f323ccff93907db --- /dev/null +++ b/tasks/construct-mc-debruijn-l6-s3/environment/instance.json @@ -0,0 +1 @@ +{"b": 6, "n": 4, "family": "mc_debruijn", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-debruijn-l6-s3/solution/solve.sh b/tasks/construct-mc-debruijn-l6-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..08bb8adcb129e4442bd6d2f2ca7b962053203216 --- /dev/null +++ b/tasks/construct-mc-debruijn-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' +{"seq": [0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0, 5, 0, 0, 1, 1, 0, 0, 1, 2, 0, 0, 1, 3, 0, 0, 1, 4, 0, 0, 1, 5, 0, 0, 2, 1, 0, 0, 2, 2, 0, 0, 2, 3, 0, 0, 2, 4, 0, 0, 2, 5, 0, 0, 3, 1, 0, 0, 3, 2, 0, 0, 3, 3, 0, 0, 3, 4, 0, 0, 3, 5, 0, 0, 4, 1, 0, 0, 4, 2, 0, 0, 4, 3, 0, 0, 4, 4, 0, 0, 4, 5, 0, 0, 5, 1, 0, 0, 5, 2, 0, 0, 5, 3, 0, 0, 5, 4, 0, 0, 5, 5, 0, 1, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 4, 0, 1, 0, 5, 0, 1, 1, 1, 0, 1, 1, 2, 0, 1, 1, 3, 0, 1, 1, 4, 0, 1, 1, 5, 0, 1, 2, 1, 0, 1, 2, 2, 0, 1, 2, 3, 0, 1, 2, 4, 0, 1, 2, 5, 0, 1, 3, 1, 0, 1, 3, 2, 0, 1, 3, 3, 0, 1, 3, 4, 0, 1, 3, 5, 0, 1, 4, 1, 0, 1, 4, 2, 0, 1, 4, 3, 0, 1, 4, 4, 0, 1, 4, 5, 0, 1, 5, 1, 0, 1, 5, 2, 0, 1, 5, 3, 0, 1, 5, 4, 0, 1, 5, 5, 0, 2, 0, 2, 0, 3, 0, 2, 0, 4, 0, 2, 0, 5, 0, 2, 1, 1, 0, 2, 1, 2, 0, 2, 1, 3, 0, 2, 1, 4, 0, 2, 1, 5, 0, 2, 2, 1, 0, 2, 2, 2, 0, 2, 2, 3, 0, 2, 2, 4, 0, 2, 2, 5, 0, 2, 3, 1, 0, 2, 3, 2, 0, 2, 3, 3, 0, 2, 3, 4, 0, 2, 3, 5, 0, 2, 4, 1, 0, 2, 4, 2, 0, 2, 4, 3, 0, 2, 4, 4, 0, 2, 4, 5, 0, 2, 5, 1, 0, 2, 5, 2, 0, 2, 5, 3, 0, 2, 5, 4, 0, 2, 5, 5, 0, 3, 0, 3, 0, 4, 0, 3, 0, 5, 0, 3, 1, 1, 0, 3, 1, 2, 0, 3, 1, 3, 0, 3, 1, 4, 0, 3, 1, 5, 0, 3, 2, 1, 0, 3, 2, 2, 0, 3, 2, 3, 0, 3, 2, 4, 0, 3, 2, 5, 0, 3, 3, 1, 0, 3, 3, 2, 0, 3, 3, 3, 0, 3, 3, 4, 0, 3, 3, 5, 0, 3, 4, 1, 0, 3, 4, 2, 0, 3, 4, 3, 0, 3, 4, 4, 0, 3, 4, 5, 0, 3, 5, 1, 0, 3, 5, 2, 0, 3, 5, 3, 0, 3, 5, 4, 0, 3, 5, 5, 0, 4, 0, 4, 0, 5, 0, 4, 1, 1, 0, 4, 1, 2, 0, 4, 1, 3, 0, 4, 1, 4, 0, 4, 1, 5, 0, 4, 2, 1, 0, 4, 2, 2, 0, 4, 2, 3, 0, 4, 2, 4, 0, 4, 2, 5, 0, 4, 3, 1, 0, 4, 3, 2, 0, 4, 3, 3, 0, 4, 3, 4, 0, 4, 3, 5, 0, 4, 4, 1, 0, 4, 4, 2, 0, 4, 4, 3, 0, 4, 4, 4, 0, 4, 4, 5, 0, 4, 5, 1, 0, 4, 5, 2, 0, 4, 5, 3, 0, 4, 5, 4, 0, 4, 5, 5, 0, 5, 0, 5, 1, 1, 0, 5, 1, 2, 0, 5, 1, 3, 0, 5, 1, 4, 0, 5, 1, 5, 0, 5, 2, 1, 0, 5, 2, 2, 0, 5, 2, 3, 0, 5, 2, 4, 0, 5, 2, 5, 0, 5, 3, 1, 0, 5, 3, 2, 0, 5, 3, 3, 0, 5, 3, 4, 0, 5, 3, 5, 0, 5, 4, 1, 0, 5, 4, 2, 0, 5, 4, 3, 0, 5, 4, 4, 0, 5, 4, 5, 0, 5, 5, 1, 0, 5, 5, 2, 0, 5, 5, 3, 0, 5, 5, 4, 0, 5, 5, 5, 1, 1, 1, 1, 2, 1, 1, 1, 3, 1, 1, 1, 4, 1, 1, 1, 5, 1, 1, 2, 2, 1, 1, 2, 3, 1, 1, 2, 4, 1, 1, 2, 5, 1, 1, 3, 2, 1, 1, 3, 3, 1, 1, 3, 4, 1, 1, 3, 5, 1, 1, 4, 2, 1, 1, 4, 3, 1, 1, 4, 4, 1, 1, 4, 5, 1, 1, 5, 2, 1, 1, 5, 3, 1, 1, 5, 4, 1, 1, 5, 5, 1, 2, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 5, 1, 2, 2, 2, 1, 2, 2, 3, 1, 2, 2, 4, 1, 2, 2, 5, 1, 2, 3, 2, 1, 2, 3, 3, 1, 2, 3, 4, 1, 2, 3, 5, 1, 2, 4, 2, 1, 2, 4, 3, 1, 2, 4, 4, 1, 2, 4, 5, 1, 2, 5, 2, 1, 2, 5, 3, 1, 2, 5, 4, 1, 2, 5, 5, 1, 3, 1, 3, 1, 4, 1, 3, 1, 5, 1, 3, 2, 2, 1, 3, 2, 3, 1, 3, 2, 4, 1, 3, 2, 5, 1, 3, 3, 2, 1, 3, 3, 3, 1, 3, 3, 4, 1, 3, 3, 5, 1, 3, 4, 2, 1, 3, 4, 3, 1, 3, 4, 4, 1, 3, 4, 5, 1, 3, 5, 2, 1, 3, 5, 3, 1, 3, 5, 4, 1, 3, 5, 5, 1, 4, 1, 4, 1, 5, 1, 4, 2, 2, 1, 4, 2, 3, 1, 4, 2, 4, 1, 4, 2, 5, 1, 4, 3, 2, 1, 4, 3, 3, 1, 4, 3, 4, 1, 4, 3, 5, 1, 4, 4, 2, 1, 4, 4, 3, 1, 4, 4, 4, 1, 4, 4, 5, 1, 4, 5, 2, 1, 4, 5, 3, 1, 4, 5, 4, 1, 4, 5, 5, 1, 5, 1, 5, 2, 2, 1, 5, 2, 3, 1, 5, 2, 4, 1, 5, 2, 5, 1, 5, 3, 2, 1, 5, 3, 3, 1, 5, 3, 4, 1, 5, 3, 5, 1, 5, 4, 2, 1, 5, 4, 3, 1, 5, 4, 4, 1, 5, 4, 5, 1, 5, 5, 2, 1, 5, 5, 3, 1, 5, 5, 4, 1, 5, 5, 5, 2, 2, 2, 2, 3, 2, 2, 2, 4, 2, 2, 2, 5, 2, 2, 3, 3, 2, 2, 3, 4, 2, 2, 3, 5, 2, 2, 4, 3, 2, 2, 4, 4, 2, 2, 4, 5, 2, 2, 5, 3, 2, 2, 5, 4, 2, 2, 5, 5, 2, 3, 2, 3, 2, 4, 2, 3, 2, 5, 2, 3, 3, 3, 2, 3, 3, 4, 2, 3, 3, 5, 2, 3, 4, 3, 2, 3, 4, 4, 2, 3, 4, 5, 2, 3, 5, 3, 2, 3, 5, 4, 2, 3, 5, 5, 2, 4, 2, 4, 2, 5, 2, 4, 3, 3, 2, 4, 3, 4, 2, 4, 3, 5, 2, 4, 4, 3, 2, 4, 4, 4, 2, 4, 4, 5, 2, 4, 5, 3, 2, 4, 5, 4, 2, 4, 5, 5, 2, 5, 2, 5, 3, 3, 2, 5, 3, 4, 2, 5, 3, 5, 2, 5, 4, 3, 2, 5, 4, 4, 2, 5, 4, 5, 2, 5, 5, 3, 2, 5, 5, 4, 2, 5, 5, 5, 3, 3, 3, 3, 4, 3, 3, 3, 5, 3, 3, 4, 4, 3, 3, 4, 5, 3, 3, 5, 4, 3, 3, 5, 5, 3, 4, 3, 4, 3, 5, 3, 4, 4, 4, 3, 4, 4, 5, 3, 4, 5, 4, 3, 4, 5, 5, 3, 5, 3, 5, 4, 4, 3, 5, 4, 5, 3, 5, 5, 4, 3, 5, 5, 5, 4, 4, 4, 4, 5, 4, 4, 5, 5, 4, 5, 4, 5, 5, 5, 5]} +RLMATH_EOF diff --git a/tasks/construct-mc-debruijn-l6-s3/tests/check.py b/tasks/construct-mc-debruijn-l6-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c9d6f0177d2b3bde8306d74939ee9704c1501a23 --- /dev/null +++ b/tasks/construct-mc-debruijn-l6-s3/tests/check.py @@ -0,0 +1,15 @@ +"""De Bruijn sequence B(b, n) (MathConstraint debruijn, CC-BY-4.0). Accepts any valid cyclic sequence.""" +from run import Invalid, int_list + + +def check(inst, ans): + b, n = inst["b"], inst["n"] + m = b ** n + x = int_list(ans.get("seq"), m, 0, b - 1, "seq") + seen = set() + for i in range(m): + w = tuple(x[(i + k) % m] for k in range(n)) + if w in seen: + raise Invalid(f"window {w} occurs twice") + seen.add(w) + return None, {} diff --git a/tasks/construct-mc-debruijn-l6-s3/tests/instance.json b/tasks/construct-mc-debruijn-l6-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..53f580c0a0e86af16106e32d5f323ccff93907db --- /dev/null +++ b/tasks/construct-mc-debruijn-l6-s3/tests/instance.json @@ -0,0 +1 @@ +{"b": 6, "n": 4, "family": "mc_debruijn", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-debruijn-l6-s3/tests/run.py b/tasks/construct-mc-debruijn-l6-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-debruijn-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-mc-debruijn-l6-s3/tests/test.sh b/tasks/construct-mc-debruijn-l6-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-debruijn-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-mc-graceful-graph-l2-s1/environment/Dockerfile b/tasks/construct-mc-graceful-graph-l2-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-graceful-graph-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-mc-graceful-graph-l2-s1/environment/instance.json b/tasks/construct-mc-graceful-graph-l2-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7effcbd613f3d247ba7a7c20ab7887fd0fa5e24f --- /dev/null +++ b/tasks/construct-mc-graceful-graph-l2-s1/environment/instance.json @@ -0,0 +1 @@ +{"k": 3, "p": 4, "num_vertices": 12, "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], [0, 3], [1, 4], [2, 5], [3, 6], [4, 7], [5, 8], [6, 9], [7, 10], [8, 11]], "fixed": [["labels", 2, 15], ["labels", 4, 0], ["d", 6, 5], ["d", 9, 11], ["d", 15, 13], ["d", 18, 9]], "family": "mc_graceful_graph", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graceful-graph-l2-s1/solution/solve.sh b/tasks/construct-mc-graceful-graph-l2-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..04cbe923c01f9576a0cd924d2a616f4b62a5067c --- /dev/null +++ b/tasks/construct-mc-graceful-graph-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' +{"labels": [3, 21, 15, 20, 0, 1, 7, 2, 17, 16, 5, 9]} +RLMATH_EOF diff --git a/tasks/construct-mc-graceful-graph-l2-s1/tests/check.py b/tasks/construct-mc-graceful-graph-l2-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f4d33af1d63c0495c3b32d34db6ae10f0fb45923 --- /dev/null +++ b/tasks/construct-mc-graceful-graph-l2-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-l2-s1/tests/instance.json b/tasks/construct-mc-graceful-graph-l2-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7effcbd613f3d247ba7a7c20ab7887fd0fa5e24f --- /dev/null +++ b/tasks/construct-mc-graceful-graph-l2-s1/tests/instance.json @@ -0,0 +1 @@ +{"k": 3, "p": 4, "num_vertices": 12, "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], [0, 3], [1, 4], [2, 5], [3, 6], [4, 7], [5, 8], [6, 9], [7, 10], [8, 11]], "fixed": [["labels", 2, 15], ["labels", 4, 0], ["d", 6, 5], ["d", 9, 11], ["d", 15, 13], ["d", 18, 9]], "family": "mc_graceful_graph", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graceful-graph-l2-s1/tests/run.py b/tasks/construct-mc-graceful-graph-l2-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-graceful-graph-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-mc-graceful-graph-l2-s1/tests/test.sh b/tasks/construct-mc-graceful-graph-l2-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-graceful-graph-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-mc-graph-k-coloring-l6-s1/environment/Dockerfile b/tasks/construct-mc-graph-k-coloring-l6-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-graph-k-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-mc-graph-k-coloring-l6-s1/environment/instance.json b/tasks/construct-mc-graph-k-coloring-l6-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c92d6bf930b805327aaec54840bfcb11b0ffd755 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l6-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 250, "k": 4, "edges": [[0, 44], [0, 227], [0, 237], [1, 20], [1, 37], [1, 48], [1, 65], [1, 105], [1, 131], [1, 141], [1, 169], [1, 216], [2, 32], [2, 51], [2, 64], [2, 65], [2, 92], [2, 106], [2, 122], [2, 133], [2, 179], [3, 18], [3, 36], [3, 37], [3, 44], [3, 61], [3, 152], [3, 180], [3, 243], [3, 245], [4, 19], [4, 82], [4, 104], [4, 114], [4, 146], [4, 162], [4, 190], [4, 210], [4, 234], [5, 30], [5, 63], [5, 91], [5, 235], [5, 248], [6, 17], [6, 102], [6, 133], [6, 204], [7, 28], [7, 66], [7, 69], [7, 73], [7, 98], [7, 135], [7, 179], [7, 208], [7, 216], [8, 21], [8, 25], [8, 58], [8, 67], [8, 107], [8, 172], [8, 178], [8, 217], [8, 243], [8, 247], [9, 30], [9, 67], [9, 74], [9, 92], [9, 143], [9, 157], [9, 181], [9, 189], [9, 193], [9, 242], [10, 34], [10, 39], [10, 51], [10, 87], [10, 103], [10, 118], [10, 160], [10, 182], [10, 192], [10, 195], [10, 211], [10, 219], [10, 241], [10, 248], [11, 103], [11, 142], [11, 152], [11, 158], [11, 179], [11, 190], [11, 196], [11, 217], [11, 224], [11, 233], [11, 238], [11, 248], [12, 40], [12, 43], [12, 59], [12, 65], [12, 89], [12, 151], [12, 160], [12, 183], [12, 228], [13, 16], [13, 22], [13, 28], [13, 50], [13, 170], [13, 193], [13, 231], [14, 50], [14, 61], [14, 79], [14, 103], [14, 161], [14, 181], [14, 200], [14, 246], [15, 119], [15, 162], [15, 173], [15, 187], [16, 42], [16, 62], [16, 102], [17, 45], [17, 72], [17, 82], [17, 158], [17, 171], [17, 221], [18, 22], [18, 23], [18, 40], [18, 48], [18, 51], [18, 64], [18, 85], [18, 118], [18, 157], [18, 223], [19, 27], [19, 54], [19, 88], [19, 149], [19, 193], [20, 24], [20, 36], [20, 38], [20, 88], [20, 91], [20, 116], [20, 136], [20, 165], [21, 76], [21, 80], [21, 180], [21, 197], [21, 201], [21, 202], [21, 221], [21, 244], [22, 36], [22, 69], [22, 99], [22, 136], [22, 137], [22, 147], [22, 163], [22, 184], [22, 192], [23, 29], [23, 65], [23, 187], [23, 212], [24, 39], [24, 151], [24, 155], [24, 158], [24, 191], [24, 202], [24, 225], [24, 242], [25, 26], [25, 43], [25, 44], [25, 54], [25, 79], [26, 47], [26, 192], [26, 209], [27, 31], [27, 65], [27, 66], [27, 76], [27, 197], [27, 214], [28, 31], [28, 96], [28, 149], [28, 157], [28, 180], [28, 184], [28, 231], [29, 46], [29, 61], [29, 66], [29, 103], [29, 114], [29, 127], [29, 129], [29, 133], [29, 203], [30, 45], [30, 52], [30, 66], [30, 98], [30, 112], [30, 115], [30, 121], [30, 130], [30, 161], [30, 164], [30, 200], [30, 204], [30, 226], [30, 231], [30, 234], [30, 235], [30, 238], [31, 48], [31, 49], [31, 53], [31, 76], [31, 78], [31, 79], [31, 131], [31, 133], [31, 162], [31, 200], [31, 247], [32, 56], [32, 91], [32, 135], [32, 157], [32, 173], [32, 201], [32, 202], [32, 225], [33, 40], [33, 76], [33, 185], [33, 187], [33, 204], [33, 239], [34, 63], [34, 81], [34, 96], [34, 125], [34, 158], [34, 172], [34, 226], [35, 60], [35, 68], [35, 72], [35, 76], [35, 80], [35, 95], [35, 164], [35, 172], [35, 192], [35, 194], [35, 207], [36, 51], [36, 65], [36, 75], [36, 119], [36, 243], [37, 44], [37, 56], [37, 97], [37, 110], [37, 205], [37, 248], [38, 129], [38, 176], [38, 201], [38, 218], [39, 60], [39, 64], [39, 92], [39, 104], [39, 106], [39, 112], [39, 123], [39, 142], [39, 146], [39, 163], [39, 184], [40, 107], [40, 119], [40, 222], [40, 231], [40, 239], [40, 246], [41, 49], [41, 52], [41, 58], [41, 94], [41, 114], [41, 187], [41, 199], [41, 201], [41, 233], [42, 62], [42, 87], [42, 145], [42, 188], [42, 215], [42, 217], [42, 220], [42, 236], [43, 45], [43, 94], [43, 124], [43, 130], [43, 167], [43, 178], [43, 181], [43, 183], [43, 203], [43, 208], [43, 215], [43, 232], [44, 67], [44, 142], [44, 166], [44, 195], [44, 200], [44, 204], [44, 233], [44, 236], [44, 241], [45, 50], [45, 76], [45, 143], [45, 192], [45, 199], [45, 205], [45, 217], [46, 74], [46, 77], [46, 78], [46, 93], [46, 172], [47, 48], [47, 58], [47, 68], [47, 87], [47, 119], [47, 147], [47, 155], [47, 168], [47, 172], [47, 186], [47, 209], [47, 245], [47, 249], [48, 92], [48, 100], [48, 114], [48, 117], [48, 132], [48, 192], [48, 210], [48, 234], [49, 108], [49, 127], [49, 141], [49, 215], [49, 224], [49, 246], [50, 58], [50, 62], [50, 92], [50, 199], [50, 211], [50, 215], [50, 222], [50, 234], [51, 56], [51, 67], [51, 70], [51, 75], [51, 81], [51, 112], [51, 115], [51, 136], [51, 174], [51, 205], [52, 60], [52, 118], [52, 152], [52, 209], [52, 220], [52, 241], [53, 55], [53, 121], [53, 129], [53, 138], [53, 167], [53, 236], [53, 245], [54, 62], [54, 93], [54, 98], [54, 109], [54, 121], [54, 124], [54, 135], [54, 144], [54, 145], [54, 230], [54, 233], [55, 110], [55, 111], [55, 131], [55, 148], [55, 173], [55, 199], [55, 236], [56, 76], [56, 154], [56, 194], [56, 214], [56, 245], [56, 246], [57, 91], [57, 189], [57, 208], [57, 219], [57, 246], [58, 68], [58, 109], [58, 111], [58, 117], [58, 161], [58, 191], [58, 221], [59, 78], [59, 110], [59, 123], [59, 150], [59, 214], [59, 233], [59, 249], [60, 72], [60, 106], [60, 113], [60, 164], [60, 201], [61, 109], [61, 179], [61, 240], [62, 68], [62, 100], [62, 129], [62, 143], [62, 148], [62, 174], [62, 242], [63, 79], [63, 111], [63, 159], [63, 167], [63, 227], [63, 231], [63, 241], [64, 86], [64, 96], [64, 116], [64, 154], [64, 188], [64, 200], [65, 86], [65, 92], [65, 107], [65, 150], [65, 163], [65, 177], [65, 198], [65, 210], [65, 226], [66, 86], [66, 89], [66, 138], [66, 144], [66, 190], [66, 204], [66, 221], [67, 73], [67, 156], [67, 177], [67, 178], [67, 185], [67, 234], [67, 246], [68, 109], [68, 134], [68, 249], [69, 154], [69, 155], [69, 159], [69, 227], [70, 72], [70, 78], [70, 134], [70, 189], [70, 208], [70, 238], [71, 73], [71, 90], [71, 107], [71, 108], [71, 183], [71, 190], [71, 248], [72, 82], [72, 91], [72, 121], [72, 155], [72, 218], [72, 226], [73, 131], [73, 193], [74, 121], [74, 182], [74, 222], [74, 234], [75, 98], [75, 125], [75, 143], [75, 168], [75, 178], [75, 197], [75, 245], [75, 249], [76, 116], [76, 190], [77, 98], [77, 161], [77, 182], [77, 188], [77, 201], [77, 212], [77, 213], [77, 242], [78, 98], [78, 101], [78, 105], [78, 182], [78, 199], [79, 99], [79, 103], [79, 186], [79, 205], [79, 224], [80, 118], [80, 126], [80, 198], [80, 239], [81, 133], [81, 162], [81, 179], [81, 198], [81, 208], [81, 232], [82, 91], [82, 175], [82, 197], [82, 208], [82, 228], [83, 112], [83, 163], [83, 179], [83, 241], [84, 118], [84, 127], [84, 145], [84, 171], [84, 231], [85, 153], [85, 170], [85, 187], [86, 88], [86, 105], [86, 108], [86, 125], [86, 160], [86, 211], [86, 216], [86, 232], [87, 94], [87, 124], [87, 157], [87, 171], [88, 208], [88, 243], [89, 96], [89, 101], [89, 122], [89, 233], [89, 236], [90, 116], [90, 130], [90, 214], [91, 112], [91, 114], [91, 145], [91, 150], [91, 152], [91, 153], [91, 226], [92, 113], [92, 133], [92, 137], [92, 156], [92, 161], [92, 207], [92, 219], [92, 221], [93, 96], [93, 119], [93, 147], [93, 157], [93, 166], [93, 185], [93, 220], [94, 95], [94, 100], [94, 116], [94, 134], [94, 199], [95, 98], [95, 102], [95, 142], [95, 147], [95, 183], [96, 121], [96, 126], [96, 144], [96, 178], [96, 204], [96, 214], [97, 138], [97, 161], [97, 216], [97, 241], [98, 111], [98, 119], [98, 131], [98, 148], [98, 206], [98, 229], [99, 124], [99, 132], [99, 190], [99, 214], [99, 233], [100, 142], [100, 163], [101, 159], [101, 204], [101, 218], [102, 108], [102, 134], [102, 189], [102, 217], [103, 125], [103, 130], [103, 194], [103, 221], [103, 228], [104, 144], [104, 159], [104, 172], [104, 193], [104, 237], [105, 111], [105, 115], [105, 225], [106, 109], [106, 125], [106, 149], [106, 158], [106, 163], [106, 173], [106, 187], [106, 200], [106, 203], [106, 244], [107, 144], [107, 152], [107, 216], [107, 238], [108, 140], [108, 165], [108, 188], [108, 201], [108, 215], [109, 145], [109, 151], [109, 160], [109, 175], [109, 185], [109, 205], [109, 208], [109, 211], [109, 226], [109, 244], [110, 123], [110, 133], [110, 147], [110, 154], [110, 186], [110, 216], [110, 237], [110, 242], [111, 135], [111, 143], [111, 161], [111, 180], [111, 208], [111, 224], [111, 225], [112, 145], [112, 191], [113, 126], [113, 187], [113, 189], [113, 213], [113, 222], [113, 230], [114, 116], [114, 133], [115, 136], [115, 143], [115, 160], [115, 214], [115, 247], [116, 118], [116, 138], [116, 147], [117, 195], [117, 233], [117, 247], [117, 248], [118, 138], [118, 146], [118, 148], [118, 160], [118, 196], [118, 198], [118, 200], [119, 142], [119, 186], [120, 157], [120, 161], [120, 162], [120, 167], [120, 212], [120, 240], [120, 246], [121, 126], [121, 149], [121, 230], [122, 192], [122, 207], [122, 233], [122, 245], [123, 172], [123, 183], [123, 210], [123, 242], [124, 135], [124, 145], [124, 223], [125, 165], [125, 172], [125, 181], [125, 199], [125, 201], [125, 204], [125, 217], [125, 235], [126, 130], [126, 167], [127, 201], [128, 217], [128, 243], [129, 157], [129, 158], [130, 192], [131, 192], [131, 196], [131, 212], [131, 233], [131, 242], [131, 243], [132, 193], [132, 199], [132, 212], [132, 215], [132, 249], [133, 220], [134, 181], [134, 218], [134, 248], [135, 177], [135, 183], [136, 160], [136, 209], [136, 215], [136, 233], [137, 202], [137, 238], [137, 243], [138, 145], [138, 150], [138, 175], [138, 178], [138, 189], [138, 192], [138, 225], [138, 242], [139, 144], [139, 176], [139, 195], [139, 204], [140, 163], [140, 166], [140, 177], [140, 190], [140, 192], [140, 239], [141, 182], [141, 197], [141, 224], [142, 147], [142, 155], [142, 157], [142, 177], [142, 223], [142, 226], [143, 153], [143, 156], [143, 165], [143, 175], [143, 186], [143, 201], [143, 205], [144, 176], [144, 210], [144, 247], [145, 162], [145, 213], [145, 227], [145, 239], [146, 197], [146, 228], [146, 233], [147, 150], [147, 175], [147, 180], [147, 195], [147, 202], [147, 216], [148, 176], [148, 179], [148, 188], [148, 192], [148, 212], [148, 213], [148, 234], [148, 241], [149, 178], [149, 194], [149, 241], [150, 166], [151, 169], [151, 213], [151, 218], [152, 159], [152, 162], [152, 181], [152, 183], [152, 196], [152, 207], [152, 214], [152, 231], [153, 157], [153, 198], [153, 218], [153, 221], [153, 239], [154, 246], [155, 156], [155, 175], [155, 190], [155, 200], [155, 236], [156, 157], [156, 160], [156, 170], [156, 226], [157, 175], [157, 202], [158, 173], [159, 168], [159, 222], [160, 174], [160, 175], [160, 205], [161, 223], [162, 175], [162, 199], [162, 207], [162, 212], [162, 244], [162, 246], [163, 172], [163, 177], [163, 194], [163, 205], [163, 225], [163, 248], [163, 249], [164, 200], [164, 213], [164, 215], [165, 168], [165, 182], [166, 175], [166, 177], [166, 243], [167, 190], [167, 193], [167, 195], [167, 204], [167, 242], [168, 200], [168, 206], [169, 187], [169, 205], [170, 174], [170, 231], [171, 180], [171, 195], [172, 185], [172, 223], [173, 195], [173, 214], [173, 227], [173, 248], [173, 249], [174, 193], [174, 204], [174, 210], [174, 232], [175, 209], [176, 217], [177, 181], [177, 235], [178, 187], [178, 211], [179, 189], [179, 205], [179, 242], [180, 186], [180, 220], [180, 240], [181, 182], [181, 205], [181, 227], [182, 188], [182, 190], [182, 206], [182, 247], [183, 218], [184, 199], [185, 226], [185, 234], [186, 189], [186, 220], [186, 230], [187, 227], [187, 246], [188, 195], [188, 237], [189, 197], [189, 216], [189, 233], [189, 242], [190, 193], [190, 209], [190, 215], [190, 224], [190, 225], [190, 226], [192, 196], [193, 197], [193, 219], [193, 240], [194, 198], [195, 231], [196, 197], [196, 229], [197, 201], [197, 218], [198, 217], [199, 201], [199, 205], [199, 226], [199, 227], [200, 214], [200, 217], [201, 202], [201, 247], [202, 223], [203, 219], [203, 243], [204, 243], [205, 209], [205, 230], [206, 223], [208, 238], [209, 223], [209, 229], [209, 230], [210, 214], [210, 217], [211, 243], [212, 223], [212, 248], [212, 249], [216, 229], [216, 238], [217, 220], [218, 226], [219, 227], [219, 235], [220, 234], [222, 227], [223, 236], [223, 242], [224, 233], [228, 232], [230, 246], [232, 236], [236, 248], [237, 240], [237, 244], [238, 246], [242, 243], [244, 246], [244, 249]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l6-s1/solution/solve.sh b/tasks/construct-mc-graph-k-coloring-l6-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..536e5be335488badf1187c10a660945eb68a84c2 --- /dev/null +++ b/tasks/construct-mc-graph-k-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' +{"coloring": [1, 2, 2, 2, 3, 1, 2, 3, 2, 1, 2, 3, 2, 3, 1, 1, 2, 3, 0, 1, 1, 3, 1, 2, 2, 0, 3, 2, 1, 3, 3, 0, 0, 2, 1, 2, 0, 1, 0, 0, 1, 3, 0, 3, 3, 2, 2, 2, 1, 2, 0, 1, 2, 3, 3, 0, 2, 0, 1, 1, 3, 0, 1, 0, 3, 1, 1, 0, 0, 2, 0, 1, 1, 2, 3, 2, 1, 3, 3, 2, 0, 3, 0, 3, 3, 3, 2, 1, 0, 3, 3, 3, 3, 0, 2, 1, 2, 3, 0, 3, 0, 2, 0, 0, 1, 0, 1, 3, 3, 2, 2, 3, 2, 1, 2, 2, 0, 3, 1, 3, 0, 0, 1, 3, 0, 3, 3, 0, 2, 2, 1, 3, 2, 1, 1, 1, 3, 0, 2, 1, 1, 3, 2, 0, 0, 1, 2, 3, 3, 3, 0, 0, 1, 1, 0, 0, 1, 3, 0, 3, 0, 2, 2, 2, 0, 2, 2, 1, 1, 1, 0, 2, 0, 2, 3, 1, 2, 3, 1, 1, 0, 2, 0, 0, 3, 1, 1, 0, 1, 3, 2, 3, 0, 0, 1, 0, 2, 1, 2, 1, 2, 2, 1, 0, 0, 3, 2, 0, 1, 0, 2, 3, 1, 2, 0, 1, 0, 1, 3, 1, 3, 2, 2, 3, 1, 1, 0, 3, 3, 3, 2, 2, 0, 0, 2, 0, 1, 3, 2, 3, 2, 1, 0, 1, 0, 0, 3, 1, 0, 3]} +RLMATH_EOF diff --git a/tasks/construct-mc-graph-k-coloring-l6-s1/tests/check.py b/tasks/construct-mc-graph-k-coloring-l6-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2b5f38cd0c22ac1b4ba37c0d3ff0a34635f08854 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l6-s1/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-l6-s1/tests/instance.json b/tasks/construct-mc-graph-k-coloring-l6-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c92d6bf930b805327aaec54840bfcb11b0ffd755 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l6-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 250, "k": 4, "edges": [[0, 44], [0, 227], [0, 237], [1, 20], [1, 37], [1, 48], [1, 65], [1, 105], [1, 131], [1, 141], [1, 169], [1, 216], [2, 32], [2, 51], [2, 64], [2, 65], [2, 92], [2, 106], [2, 122], [2, 133], [2, 179], [3, 18], [3, 36], [3, 37], [3, 44], [3, 61], [3, 152], [3, 180], [3, 243], [3, 245], [4, 19], [4, 82], [4, 104], [4, 114], [4, 146], [4, 162], [4, 190], [4, 210], [4, 234], [5, 30], [5, 63], [5, 91], [5, 235], [5, 248], [6, 17], [6, 102], [6, 133], [6, 204], [7, 28], [7, 66], [7, 69], [7, 73], [7, 98], [7, 135], [7, 179], [7, 208], [7, 216], [8, 21], [8, 25], [8, 58], [8, 67], [8, 107], [8, 172], [8, 178], [8, 217], [8, 243], [8, 247], [9, 30], [9, 67], [9, 74], [9, 92], [9, 143], [9, 157], [9, 181], [9, 189], [9, 193], [9, 242], [10, 34], [10, 39], [10, 51], [10, 87], [10, 103], [10, 118], [10, 160], [10, 182], [10, 192], [10, 195], [10, 211], [10, 219], [10, 241], [10, 248], [11, 103], [11, 142], [11, 152], [11, 158], [11, 179], [11, 190], [11, 196], [11, 217], [11, 224], [11, 233], [11, 238], [11, 248], [12, 40], [12, 43], [12, 59], [12, 65], [12, 89], [12, 151], [12, 160], [12, 183], [12, 228], [13, 16], [13, 22], [13, 28], [13, 50], [13, 170], [13, 193], [13, 231], [14, 50], [14, 61], [14, 79], [14, 103], [14, 161], [14, 181], [14, 200], [14, 246], [15, 119], [15, 162], [15, 173], [15, 187], [16, 42], [16, 62], [16, 102], [17, 45], [17, 72], [17, 82], [17, 158], [17, 171], [17, 221], [18, 22], [18, 23], [18, 40], [18, 48], [18, 51], [18, 64], [18, 85], [18, 118], [18, 157], [18, 223], [19, 27], [19, 54], [19, 88], [19, 149], [19, 193], [20, 24], [20, 36], [20, 38], [20, 88], [20, 91], [20, 116], [20, 136], [20, 165], [21, 76], [21, 80], [21, 180], [21, 197], [21, 201], [21, 202], [21, 221], [21, 244], [22, 36], [22, 69], [22, 99], [22, 136], [22, 137], [22, 147], [22, 163], [22, 184], [22, 192], [23, 29], [23, 65], [23, 187], [23, 212], [24, 39], [24, 151], [24, 155], [24, 158], [24, 191], [24, 202], [24, 225], [24, 242], [25, 26], [25, 43], [25, 44], [25, 54], [25, 79], [26, 47], [26, 192], [26, 209], [27, 31], [27, 65], [27, 66], [27, 76], [27, 197], [27, 214], [28, 31], [28, 96], [28, 149], [28, 157], [28, 180], [28, 184], [28, 231], [29, 46], [29, 61], [29, 66], [29, 103], [29, 114], [29, 127], [29, 129], [29, 133], [29, 203], [30, 45], [30, 52], [30, 66], [30, 98], [30, 112], [30, 115], [30, 121], [30, 130], [30, 161], [30, 164], [30, 200], [30, 204], [30, 226], [30, 231], [30, 234], [30, 235], [30, 238], [31, 48], [31, 49], [31, 53], [31, 76], [31, 78], [31, 79], [31, 131], [31, 133], [31, 162], [31, 200], [31, 247], [32, 56], [32, 91], [32, 135], [32, 157], [32, 173], [32, 201], [32, 202], [32, 225], [33, 40], [33, 76], [33, 185], [33, 187], [33, 204], [33, 239], [34, 63], [34, 81], [34, 96], [34, 125], [34, 158], [34, 172], [34, 226], [35, 60], [35, 68], [35, 72], [35, 76], [35, 80], [35, 95], [35, 164], [35, 172], [35, 192], [35, 194], [35, 207], [36, 51], [36, 65], [36, 75], [36, 119], [36, 243], [37, 44], [37, 56], [37, 97], [37, 110], [37, 205], [37, 248], [38, 129], [38, 176], [38, 201], [38, 218], [39, 60], [39, 64], [39, 92], [39, 104], [39, 106], [39, 112], [39, 123], [39, 142], [39, 146], [39, 163], [39, 184], [40, 107], [40, 119], [40, 222], [40, 231], [40, 239], [40, 246], [41, 49], [41, 52], [41, 58], [41, 94], [41, 114], [41, 187], [41, 199], [41, 201], [41, 233], [42, 62], [42, 87], [42, 145], [42, 188], [42, 215], [42, 217], [42, 220], [42, 236], [43, 45], [43, 94], [43, 124], [43, 130], [43, 167], [43, 178], [43, 181], [43, 183], [43, 203], [43, 208], [43, 215], [43, 232], [44, 67], [44, 142], [44, 166], [44, 195], [44, 200], [44, 204], [44, 233], [44, 236], [44, 241], [45, 50], [45, 76], [45, 143], [45, 192], [45, 199], [45, 205], [45, 217], [46, 74], [46, 77], [46, 78], [46, 93], [46, 172], [47, 48], [47, 58], [47, 68], [47, 87], [47, 119], [47, 147], [47, 155], [47, 168], [47, 172], [47, 186], [47, 209], [47, 245], [47, 249], [48, 92], [48, 100], [48, 114], [48, 117], [48, 132], [48, 192], [48, 210], [48, 234], [49, 108], [49, 127], [49, 141], [49, 215], [49, 224], [49, 246], [50, 58], [50, 62], [50, 92], [50, 199], [50, 211], [50, 215], [50, 222], [50, 234], [51, 56], [51, 67], [51, 70], [51, 75], [51, 81], [51, 112], [51, 115], [51, 136], [51, 174], [51, 205], [52, 60], [52, 118], [52, 152], [52, 209], [52, 220], [52, 241], [53, 55], [53, 121], [53, 129], [53, 138], [53, 167], [53, 236], [53, 245], [54, 62], [54, 93], [54, 98], [54, 109], [54, 121], [54, 124], [54, 135], [54, 144], [54, 145], [54, 230], [54, 233], [55, 110], [55, 111], [55, 131], [55, 148], [55, 173], [55, 199], [55, 236], [56, 76], [56, 154], [56, 194], [56, 214], [56, 245], [56, 246], [57, 91], [57, 189], [57, 208], [57, 219], [57, 246], [58, 68], [58, 109], [58, 111], [58, 117], [58, 161], [58, 191], [58, 221], [59, 78], [59, 110], [59, 123], [59, 150], [59, 214], [59, 233], [59, 249], [60, 72], [60, 106], [60, 113], [60, 164], [60, 201], [61, 109], [61, 179], [61, 240], [62, 68], [62, 100], [62, 129], [62, 143], [62, 148], [62, 174], [62, 242], [63, 79], [63, 111], [63, 159], [63, 167], [63, 227], [63, 231], [63, 241], [64, 86], [64, 96], [64, 116], [64, 154], [64, 188], [64, 200], [65, 86], [65, 92], [65, 107], [65, 150], [65, 163], [65, 177], [65, 198], [65, 210], [65, 226], [66, 86], [66, 89], [66, 138], [66, 144], [66, 190], [66, 204], [66, 221], [67, 73], [67, 156], [67, 177], [67, 178], [67, 185], [67, 234], [67, 246], [68, 109], [68, 134], [68, 249], [69, 154], [69, 155], [69, 159], [69, 227], [70, 72], [70, 78], [70, 134], [70, 189], [70, 208], [70, 238], [71, 73], [71, 90], [71, 107], [71, 108], [71, 183], [71, 190], [71, 248], [72, 82], [72, 91], [72, 121], [72, 155], [72, 218], [72, 226], [73, 131], [73, 193], [74, 121], [74, 182], [74, 222], [74, 234], [75, 98], [75, 125], [75, 143], [75, 168], [75, 178], [75, 197], [75, 245], [75, 249], [76, 116], [76, 190], [77, 98], [77, 161], [77, 182], [77, 188], [77, 201], [77, 212], [77, 213], [77, 242], [78, 98], [78, 101], [78, 105], [78, 182], [78, 199], [79, 99], [79, 103], [79, 186], [79, 205], [79, 224], [80, 118], [80, 126], [80, 198], [80, 239], [81, 133], [81, 162], [81, 179], [81, 198], [81, 208], [81, 232], [82, 91], [82, 175], [82, 197], [82, 208], [82, 228], [83, 112], [83, 163], [83, 179], [83, 241], [84, 118], [84, 127], [84, 145], [84, 171], [84, 231], [85, 153], [85, 170], [85, 187], [86, 88], [86, 105], [86, 108], [86, 125], [86, 160], [86, 211], [86, 216], [86, 232], [87, 94], [87, 124], [87, 157], [87, 171], [88, 208], [88, 243], [89, 96], [89, 101], [89, 122], [89, 233], [89, 236], [90, 116], [90, 130], [90, 214], [91, 112], [91, 114], [91, 145], [91, 150], [91, 152], [91, 153], [91, 226], [92, 113], [92, 133], [92, 137], [92, 156], [92, 161], [92, 207], [92, 219], [92, 221], [93, 96], [93, 119], [93, 147], [93, 157], [93, 166], [93, 185], [93, 220], [94, 95], [94, 100], [94, 116], [94, 134], [94, 199], [95, 98], [95, 102], [95, 142], [95, 147], [95, 183], [96, 121], [96, 126], [96, 144], [96, 178], [96, 204], [96, 214], [97, 138], [97, 161], [97, 216], [97, 241], [98, 111], [98, 119], [98, 131], [98, 148], [98, 206], [98, 229], [99, 124], [99, 132], [99, 190], [99, 214], [99, 233], [100, 142], [100, 163], [101, 159], [101, 204], [101, 218], [102, 108], [102, 134], [102, 189], [102, 217], [103, 125], [103, 130], [103, 194], [103, 221], [103, 228], [104, 144], [104, 159], [104, 172], [104, 193], [104, 237], [105, 111], [105, 115], [105, 225], [106, 109], [106, 125], [106, 149], [106, 158], [106, 163], [106, 173], [106, 187], [106, 200], [106, 203], [106, 244], [107, 144], [107, 152], [107, 216], [107, 238], [108, 140], [108, 165], [108, 188], [108, 201], [108, 215], [109, 145], [109, 151], [109, 160], [109, 175], [109, 185], [109, 205], [109, 208], [109, 211], [109, 226], [109, 244], [110, 123], [110, 133], [110, 147], [110, 154], [110, 186], [110, 216], [110, 237], [110, 242], [111, 135], [111, 143], [111, 161], [111, 180], [111, 208], [111, 224], [111, 225], [112, 145], [112, 191], [113, 126], [113, 187], [113, 189], [113, 213], [113, 222], [113, 230], [114, 116], [114, 133], [115, 136], [115, 143], [115, 160], [115, 214], [115, 247], [116, 118], [116, 138], [116, 147], [117, 195], [117, 233], [117, 247], [117, 248], [118, 138], [118, 146], [118, 148], [118, 160], [118, 196], [118, 198], [118, 200], [119, 142], [119, 186], [120, 157], [120, 161], [120, 162], [120, 167], [120, 212], [120, 240], [120, 246], [121, 126], [121, 149], [121, 230], [122, 192], [122, 207], [122, 233], [122, 245], [123, 172], [123, 183], [123, 210], [123, 242], [124, 135], [124, 145], [124, 223], [125, 165], [125, 172], [125, 181], [125, 199], [125, 201], [125, 204], [125, 217], [125, 235], [126, 130], [126, 167], [127, 201], [128, 217], [128, 243], [129, 157], [129, 158], [130, 192], [131, 192], [131, 196], [131, 212], [131, 233], [131, 242], [131, 243], [132, 193], [132, 199], [132, 212], [132, 215], [132, 249], [133, 220], [134, 181], [134, 218], [134, 248], [135, 177], [135, 183], [136, 160], [136, 209], [136, 215], [136, 233], [137, 202], [137, 238], [137, 243], [138, 145], [138, 150], [138, 175], [138, 178], [138, 189], [138, 192], [138, 225], [138, 242], [139, 144], [139, 176], [139, 195], [139, 204], [140, 163], [140, 166], [140, 177], [140, 190], [140, 192], [140, 239], [141, 182], [141, 197], [141, 224], [142, 147], [142, 155], [142, 157], [142, 177], [142, 223], [142, 226], [143, 153], [143, 156], [143, 165], [143, 175], [143, 186], [143, 201], [143, 205], [144, 176], [144, 210], [144, 247], [145, 162], [145, 213], [145, 227], [145, 239], [146, 197], [146, 228], [146, 233], [147, 150], [147, 175], [147, 180], [147, 195], [147, 202], [147, 216], [148, 176], [148, 179], [148, 188], [148, 192], [148, 212], [148, 213], [148, 234], [148, 241], [149, 178], [149, 194], [149, 241], [150, 166], [151, 169], [151, 213], [151, 218], [152, 159], [152, 162], [152, 181], [152, 183], [152, 196], [152, 207], [152, 214], [152, 231], [153, 157], [153, 198], [153, 218], [153, 221], [153, 239], [154, 246], [155, 156], [155, 175], [155, 190], [155, 200], [155, 236], [156, 157], [156, 160], [156, 170], [156, 226], [157, 175], [157, 202], [158, 173], [159, 168], [159, 222], [160, 174], [160, 175], [160, 205], [161, 223], [162, 175], [162, 199], [162, 207], [162, 212], [162, 244], [162, 246], [163, 172], [163, 177], [163, 194], [163, 205], [163, 225], [163, 248], [163, 249], [164, 200], [164, 213], [164, 215], [165, 168], [165, 182], [166, 175], [166, 177], [166, 243], [167, 190], [167, 193], [167, 195], [167, 204], [167, 242], [168, 200], [168, 206], [169, 187], [169, 205], [170, 174], [170, 231], [171, 180], [171, 195], [172, 185], [172, 223], [173, 195], [173, 214], [173, 227], [173, 248], [173, 249], [174, 193], [174, 204], [174, 210], [174, 232], [175, 209], [176, 217], [177, 181], [177, 235], [178, 187], [178, 211], [179, 189], [179, 205], [179, 242], [180, 186], [180, 220], [180, 240], [181, 182], [181, 205], [181, 227], [182, 188], [182, 190], [182, 206], [182, 247], [183, 218], [184, 199], [185, 226], [185, 234], [186, 189], [186, 220], [186, 230], [187, 227], [187, 246], [188, 195], [188, 237], [189, 197], [189, 216], [189, 233], [189, 242], [190, 193], [190, 209], [190, 215], [190, 224], [190, 225], [190, 226], [192, 196], [193, 197], [193, 219], [193, 240], [194, 198], [195, 231], [196, 197], [196, 229], [197, 201], [197, 218], [198, 217], [199, 201], [199, 205], [199, 226], [199, 227], [200, 214], [200, 217], [201, 202], [201, 247], [202, 223], [203, 219], [203, 243], [204, 243], [205, 209], [205, 230], [206, 223], [208, 238], [209, 223], [209, 229], [209, 230], [210, 214], [210, 217], [211, 243], [212, 223], [212, 248], [212, 249], [216, 229], [216, 238], [217, 220], [218, 226], [219, 227], [219, 235], [220, 234], [222, 227], [223, 236], [223, 242], [224, 233], [228, 232], [230, 246], [232, 236], [236, 248], [237, 240], [237, 244], [238, 246], [242, 243], [244, 246], [244, 249]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l6-s1/tests/run.py b/tasks/construct-mc-graph-k-coloring-l6-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-graph-k-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-mc-graph-k-coloring-l6-s1/tests/test.sh b/tasks/construct-mc-graph-k-coloring-l6-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-graph-k-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-mc-graph-k-coloring-l6-s6/environment/Dockerfile b/tasks/construct-mc-graph-k-coloring-l6-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-graph-k-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-mc-graph-k-coloring-l6-s6/environment/instance.json b/tasks/construct-mc-graph-k-coloring-l6-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..38bc24e0463ad50bf464f2d23551d7a3561c1b40 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l6-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 250, "k": 4, "edges": [[0, 21], [0, 38], [0, 48], [0, 49], [0, 81], [0, 83], [0, 171], [0, 198], [0, 237], [0, 249], [1, 34], [1, 39], [1, 42], [1, 152], [1, 203], [1, 248], [2, 22], [2, 50], [2, 52], [2, 72], [2, 116], [2, 160], [2, 164], [2, 169], [2, 229], [2, 230], [2, 235], [2, 249], [3, 33], [3, 58], [3, 80], [3, 161], [3, 199], [3, 205], [4, 41], [4, 115], [4, 117], [4, 148], [4, 175], [4, 214], [4, 227], [5, 59], [5, 71], [5, 102], [5, 129], [5, 190], [5, 200], [5, 215], [5, 227], [5, 234], [5, 244], [6, 42], [6, 120], [6, 121], [6, 123], [6, 133], [6, 141], [6, 158], [7, 34], [7, 61], [7, 69], [7, 88], [7, 101], [7, 181], [7, 204], [7, 209], [7, 236], [7, 238], [7, 247], [8, 30], [8, 43], [8, 59], [8, 77], [8, 105], [8, 109], [8, 136], [8, 198], [8, 238], [9, 31], [9, 39], [9, 101], [10, 23], [10, 36], [10, 86], [10, 105], [10, 109], [10, 118], [10, 122], [10, 150], [10, 157], [10, 196], [10, 204], [11, 94], [11, 98], [11, 140], [11, 167], [11, 186], [11, 187], [11, 214], [11, 238], [11, 243], [12, 30], [12, 42], [12, 79], [12, 82], [12, 144], [12, 150], [12, 157], [12, 172], [12, 207], [13, 32], [13, 49], [13, 66], [13, 97], [13, 162], [13, 212], [13, 223], [14, 42], [14, 50], [14, 80], [14, 81], [14, 114], [14, 121], [15, 21], [15, 64], [15, 72], [15, 82], [15, 100], [15, 159], [15, 185], [16, 30], [16, 49], [16, 59], [16, 69], [16, 130], [16, 179], [16, 187], [16, 236], [17, 31], [17, 32], [17, 54], [17, 70], [17, 110], [17, 129], [17, 153], [17, 181], [17, 239], [18, 30], [18, 69], [18, 81], [18, 93], [18, 94], [18, 122], [18, 152], [18, 168], [18, 213], [18, 223], [19, 45], [19, 53], [19, 54], [19, 71], [19, 117], [19, 122], [19, 135], [19, 148], [20, 51], [20, 60], [20, 64], [20, 98], [20, 131], [20, 187], [20, 189], [20, 193], [20, 210], [20, 222], [20, 226], [21, 73], [21, 99], [21, 114], [21, 192], [21, 206], [21, 207], [21, 222], [21, 239], [22, 88], [22, 127], [22, 148], [22, 164], [22, 169], [22, 198], [22, 207], [22, 232], [23, 47], [23, 154], [23, 175], [23, 195], [23, 217], [24, 46], [24, 107], [24, 112], [24, 138], [24, 160], [24, 171], [24, 179], [24, 180], [24, 189], [24, 204], [25, 30], [25, 43], [25, 98], [25, 106], [25, 138], [25, 145], [25, 151], [25, 158], [25, 163], [25, 171], [25, 210], [25, 217], [25, 220], [26, 33], [26, 69], [26, 182], [27, 31], [27, 42], [27, 93], [27, 134], [27, 135], [27, 183], [27, 189], [27, 196], [28, 52], [28, 55], [28, 72], [28, 180], [28, 225], [28, 237], [28, 240], [29, 43], [29, 50], [29, 60], [29, 123], [29, 134], [29, 151], [29, 183], [29, 219], [29, 220], [30, 60], [30, 78], [30, 82], [30, 115], [30, 131], [30, 171], [30, 242], [31, 38], [31, 108], [31, 112], [31, 122], [31, 179], [32, 123], [32, 158], [32, 161], [32, 166], [32, 201], [32, 214], [32, 221], [33, 45], [33, 63], [33, 150], [34, 64], [34, 103], [34, 106], [34, 120], [35, 37], [35, 81], [35, 111], [35, 125], [35, 182], [35, 248], [36, 63], [36, 77], [36, 79], [36, 85], [36, 106], [36, 110], [36, 165], [36, 172], [36, 177], [36, 239], [36, 248], [37, 88], [37, 122], [37, 141], [37, 169], [37, 177], [37, 203], [37, 210], [37, 240], [38, 56], [38, 74], [38, 79], [38, 82], [38, 105], [38, 136], [38, 173], [38, 181], [38, 224], [39, 145], [39, 156], [39, 203], [39, 209], [40, 93], [40, 119], [40, 133], [40, 150], [40, 247], [41, 42], [41, 65], [41, 73], [41, 108], [41, 136], [41, 151], [41, 156], [41, 159], [41, 167], [41, 187], [41, 193], [41, 206], [41, 210], [41, 232], [41, 234], [42, 101], [42, 133], [42, 139], [42, 152], [42, 162], [42, 171], [42, 172], [42, 237], [43, 54], [43, 64], [43, 70], [43, 98], [43, 147], [43, 164], [43, 192], [43, 214], [43, 219], [43, 245], [44, 66], [44, 128], [44, 132], [44, 147], [44, 165], [44, 169], [44, 184], [44, 205], [44, 233], [45, 92], [45, 101], [45, 121], [45, 148], [45, 188], [45, 205], [45, 212], [45, 213], [45, 234], [46, 84], [46, 93], [46, 141], [46, 159], [46, 160], [46, 161], [46, 179], [46, 200], [46, 247], [47, 71], [47, 98], [47, 124], [47, 165], [47, 186], [47, 195], [47, 203], [47, 206], [47, 215], [47, 247], [48, 70], [48, 73], [48, 121], [48, 144], [48, 164], [48, 168], [48, 248], [49, 66], [49, 88], [49, 94], [49, 96], [49, 108], [49, 155], [49, 197], [49, 208], [49, 229], [50, 68], [50, 94], [50, 140], [50, 184], [50, 237], [51, 83], [51, 223], [52, 53], [52, 166], [52, 178], [52, 229], [52, 249], [53, 65], [53, 100], [53, 133], [53, 167], [53, 217], [54, 196], [54, 229], [54, 237], [55, 57], [55, 65], [55, 80], [55, 104], [55, 149], [55, 161], [55, 226], [55, 236], [56, 60], [56, 70], [56, 74], [56, 82], [56, 96], [56, 212], [57, 96], [57, 106], [57, 111], [57, 138], [57, 181], [57, 210], [57, 248], [58, 93], [58, 99], [58, 112], [58, 133], [58, 175], [58, 205], [58, 224], [58, 238], [59, 60], [59, 118], [59, 137], [59, 198], [59, 219], [60, 85], [60, 98], [60, 119], [60, 129], [60, 142], [60, 143], [60, 202], [60, 207], [60, 215], [60, 236], [60, 249], [61, 66], [61, 101], [61, 109], [61, 111], [61, 115], [61, 189], [61, 222], [62, 143], [62, 157], [62, 167], [62, 188], [62, 210], [62, 224], [62, 247], [63, 66], [63, 105], [63, 132], [64, 69], [64, 88], [64, 129], [64, 154], [64, 191], [64, 218], [64, 223], [65, 117], [65, 130], [65, 148], [65, 176], [66, 91], [66, 119], [66, 158], [67, 196], [67, 244], [68, 77], [68, 83], [68, 113], [68, 120], [68, 144], [68, 185], [68, 229], [68, 248], [69, 91], [69, 96], [69, 101], [69, 105], [69, 126], [69, 145], [70, 92], [70, 115], [70, 117], [70, 170], [70, 188], [71, 96], [71, 143], [71, 165], [71, 177], [71, 182], [71, 210], [71, 228], [71, 234], [72, 115], [72, 200], [72, 208], [72, 210], [72, 226], [72, 238], [73, 81], [73, 98], [73, 130], [73, 164], [73, 167], [73, 174], [73, 199], [74, 137], [74, 146], [74, 152], [74, 165], [74, 226], [75, 121], [75, 128], [75, 157], [75, 158], [75, 187], [75, 236], [76, 106], [76, 108], [76, 112], [76, 133], [76, 135], [76, 166], [76, 169], [76, 194], [76, 211], [76, 229], [76, 238], [77, 132], [77, 135], [77, 173], [77, 194], [77, 214], [78, 127], [78, 165], [78, 173], [78, 177], [78, 211], [79, 107], [79, 180], [79, 188], [79, 196], [79, 207], [79, 214], [79, 221], [79, 241], [80, 89], [80, 149], [80, 157], [80, 169], [80, 181], [80, 206], [80, 208], [81, 88], [81, 118], [81, 128], [81, 153], [81, 183], [81, 199], [81, 200], [81, 212], [82, 126], [82, 142], [82, 152], [82, 168], [82, 198], [82, 203], [82, 228], [83, 85], [83, 110], [83, 188], [83, 205], [83, 240], [84, 89], [84, 94], [84, 108], [84, 177], [84, 181], [84, 229], [85, 122], [85, 126], [85, 168], [85, 215], [86, 90], [86, 105], [86, 134], [86, 177], [87, 109], [87, 119], [87, 166], [87, 180], [88, 98], [88, 212], [88, 223], [88, 239], [89, 113], [89, 121], [89, 164], [89, 182], [89, 225], [90, 146], [90, 170], [91, 103], [91, 133], [91, 142], [91, 153], [91, 161], [91, 170], [91, 184], [91, 200], [91, 202], [92, 111], [92, 127], [92, 130], [92, 132], [92, 152], [92, 171], [92, 217], [92, 230], [93, 175], [93, 199], [93, 208], [94, 123], [94, 124], [94, 141], [94, 142], [94, 177], [94, 238], [94, 244], [95, 133], [95, 159], [96, 104], [96, 148], [96, 156], [96, 160], [96, 165], [96, 208], [96, 209], [96, 213], [96, 215], [96, 219], [97, 141], [97, 142], [97, 155], [97, 176], [97, 198], [97, 212], [98, 165], [98, 177], [98, 227], [98, 228], [98, 248], [99, 122], [99, 126], [99, 145], [99, 179], [99, 222], [100, 109], [100, 148], [100, 169], [100, 182], [100, 208], [100, 235], [101, 118], [101, 143], [101, 168], [101, 189], [101, 193], [102, 126], [102, 132], [102, 157], [102, 163], [102, 221], [102, 244], [103, 118], [103, 120], [103, 152], [103, 156], [103, 185], [103, 217], [103, 221], [104, 108], [104, 163], [104, 165], [104, 183], [104, 184], [104, 188], [104, 199], [104, 224], [105, 156], [105, 173], [105, 184], [105, 212], [106, 133], [106, 138], [106, 139], [106, 175], [107, 117], [107, 122], [107, 124], [107, 223], [107, 236], [108, 119], [108, 205], [108, 249], [109, 122], [109, 126], [109, 152], [109, 158], [109, 164], [109, 165], [109, 167], [109, 168], [109, 197], [109, 236], [110, 130], [110, 161], [110, 164], [110, 173], [110, 194], [110, 224], [110, 233], [111, 184], [112, 175], [113, 117], [113, 193], [113, 218], [114, 169], [114, 174], [114, 181], [114, 242], [115, 125], [115, 145], [115, 210], [115, 222], [115, 238], [116, 140], [116, 148], [116, 175], [116, 196], [116, 197], [116, 244], [117, 160], [117, 188], [117, 189], [117, 206], [117, 248], [118, 172], [118, 181], [118, 197], [118, 206], [119, 156], [119, 178], [120, 192], [121, 171], [121, 187], [121, 205], [121, 221], [121, 224], [122, 163], [122, 171], [122, 215], [122, 228], [123, 140], [123, 236], [123, 243], [124, 131], [124, 146], [125, 130], [125, 132], [125, 151], [125, 171], [125, 180], [126, 146], [126, 149], [126, 151], [126, 160], [126, 174], [126, 184], [126, 216], [126, 238], [126, 242], [127, 184], [127, 233], [128, 132], [128, 133], [128, 142], [128, 159], [128, 209], [128, 227], [128, 234], [128, 240], [129, 131], [129, 132], [129, 154], [129, 164], [129, 172], [129, 225], [129, 233], [129, 240], [130, 175], [130, 209], [131, 135], [131, 139], [131, 179], [131, 183], [131, 209], [131, 210], [132, 143], [132, 148], [133, 136], [133, 144], [133, 152], [133, 170], [133, 197], [133, 236], [133, 248], [134, 150], [134, 167], [134, 212], [134, 244], [135, 139], [135, 180], [135, 215], [136, 144], [136, 148], [136, 188], [136, 218], [137, 193], [137, 224], [137, 239], [138, 192], [138, 196], [138, 199], [138, 211], [138, 217], [139, 140], [139, 143], [139, 150], [139, 162], [139, 184], [139, 239], [140, 190], [140, 200], [140, 215], [140, 225], [141, 143], [141, 160], [141, 169], [141, 204], [141, 230], [141, 233], [141, 241], [142, 144], [142, 154], [142, 185], [143, 162], [143, 179], [143, 189], [143, 194], [143, 196], [143, 202], [143, 223], [143, 231], [144, 158], [144, 162], [144, 163], [144, 165], [145, 198], [145, 226], [146, 148], [146, 152], [146, 184], [146, 248], [147, 163], [147, 178], [147, 187], [147, 238], [148, 155], [148, 157], [148, 160], [148, 191], [148, 209], [148, 229], [149, 152], [149, 242], [150, 200], [150, 216], [150, 235], [151, 174], [153, 196], [153, 230], [153, 244], [153, 246], [154, 159], [154, 168], [154, 183], [154, 210], [154, 212], [154, 226], [154, 248], [155, 208], [155, 214], [155, 246], [156, 224], [157, 210], [157, 228], [158, 174], [158, 196], [158, 205], [159, 162], [159, 176], [159, 190], [159, 192], [159, 196], [159, 238], [160, 176], [160, 189], [160, 206], [161, 178], [162, 170], [162, 201], [162, 215], [162, 235], [163, 215], [164, 172], [164, 173], [164, 192], [164, 197], [164, 214], [164, 233], [165, 196], [165, 218], [165, 219], [165, 231], [166, 233], [166, 237], [167, 188], [167, 191], [167, 195], [168, 196], [168, 205], [169, 195], [169, 234], [170, 173], [170, 232], [172, 243], [173, 183], [173, 199], [173, 211], [174, 179], [175, 183], [175, 223], [176, 220], [177, 201], [177, 212], [177, 218], [177, 219], [177, 230], [177, 245], [179, 216], [179, 220], [179, 241], [180, 192], [180, 213], [181, 187], [181, 247], [182, 204], [183, 225], [184, 206], [184, 221], [184, 223], [184, 244], [184, 246], [185, 210], [185, 217], [185, 239], [185, 240], [186, 200], [186, 202], [186, 207], [186, 248], [187, 212], [187, 213], [189, 190], [189, 209], [189, 211], [191, 219], [191, 230], [192, 193], [192, 198], [192, 207], [192, 237], [193, 220], [193, 242], [194, 249], [195, 232], [195, 245], [196, 197], [196, 247], [197, 249], [198, 209], [198, 215], [198, 245], [199, 221], [201, 209], [201, 230], [201, 245], [202, 238], [206, 215], [206, 229], [206, 243], [207, 226], [207, 240], [208, 231], [209, 222], [209, 242], [209, 249], [212, 232], [212, 241], [213, 236], [215, 227], [216, 224], [216, 238], [218, 224], [219, 221], [219, 239], [219, 248], [221, 231], [222, 235], [223, 224], [223, 232], [223, 238], [225, 232], [225, 245], [227, 232], [229, 230], [230, 245], [234, 245], [235, 239], [243, 244]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l6-s6/solution/solve.sh b/tasks/construct-mc-graph-k-coloring-l6-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0ae64ba2f01584e58784758992477e9b6a218b95 --- /dev/null +++ b/tasks/construct-mc-graph-k-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' +{"coloring": [1, 0, 0, 0, 1, 0, 0, 3, 0, 0, 1, 2, 2, 0, 2, 1, 2, 3, 2, 2, 3, 2, 1, 0, 3, 3, 3, 3, 0, 0, 1, 1, 2, 2, 2, 2, 2, 0, 3, 2, 3, 2, 1, 2, 0, 0, 2, 2, 2, 3, 3, 0, 2, 3, 0, 2, 1, 3, 3, 1, 2, 1, 3, 1, 0, 1, 2, 1, 2, 1, 0, 3, 3, 1, 2, 2, 3, 3, 3, 1, 1, 0, 0, 3, 3, 0, 0, 3, 2, 0, 2, 0, 1, 1, 0, 3, 0, 2, 0, 1, 0, 2, 1, 1, 3, 2, 1, 2, 0, 2, 1, 0, 0, 1, 3, 2, 1, 3, 3, 1, 3, 3, 3, 3, 1, 3, 3, 0, 3, 1, 0, 2, 2, 2, 1, 0, 1, 3, 0, 3, 0, 3, 1, 1, 3, 0, 0, 3, 3, 0, 0, 1, 3, 1, 2, 1, 3, 0, 1, 0, 1, 3, 2, 2, 3, 1, 1, 0, 3, 2, 1, 2, 0, 0, 2, 2, 3, 1, 0, 0, 2, 2, 1, 1, 1, 0, 0, 0, 2, 0, 3, 1, 1, 0, 2, 1, 2, 0, 3, 2, 1, 3, 3, 3, 0, 2, 0, 3, 2, 1, 1, 1, 3, 1, 0, 1, 2, 2, 3, 3, 2, 0, 0, 3, 0, 3, 1, 2, 2, 1, 2, 3, 0, 2, 1, 3, 0, 2, 1, 1, 2, 2, 2, 1, 3, 0, 0, 1, 1, 3]} +RLMATH_EOF diff --git a/tasks/construct-mc-graph-k-coloring-l6-s6/tests/check.py b/tasks/construct-mc-graph-k-coloring-l6-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2b5f38cd0c22ac1b4ba37c0d3ff0a34635f08854 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l6-s6/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-l6-s6/tests/instance.json b/tasks/construct-mc-graph-k-coloring-l6-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..38bc24e0463ad50bf464f2d23551d7a3561c1b40 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l6-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 250, "k": 4, "edges": [[0, 21], [0, 38], [0, 48], [0, 49], [0, 81], [0, 83], [0, 171], [0, 198], [0, 237], [0, 249], [1, 34], [1, 39], [1, 42], [1, 152], [1, 203], [1, 248], [2, 22], [2, 50], [2, 52], [2, 72], [2, 116], [2, 160], [2, 164], [2, 169], [2, 229], [2, 230], [2, 235], [2, 249], [3, 33], [3, 58], [3, 80], [3, 161], [3, 199], [3, 205], [4, 41], [4, 115], [4, 117], [4, 148], [4, 175], [4, 214], [4, 227], [5, 59], [5, 71], [5, 102], [5, 129], [5, 190], [5, 200], [5, 215], [5, 227], [5, 234], [5, 244], [6, 42], [6, 120], [6, 121], [6, 123], [6, 133], [6, 141], [6, 158], [7, 34], [7, 61], [7, 69], [7, 88], [7, 101], [7, 181], [7, 204], [7, 209], [7, 236], [7, 238], [7, 247], [8, 30], [8, 43], [8, 59], [8, 77], [8, 105], [8, 109], [8, 136], [8, 198], [8, 238], [9, 31], [9, 39], [9, 101], [10, 23], [10, 36], [10, 86], [10, 105], [10, 109], [10, 118], [10, 122], [10, 150], [10, 157], [10, 196], [10, 204], [11, 94], [11, 98], [11, 140], [11, 167], [11, 186], [11, 187], [11, 214], [11, 238], [11, 243], [12, 30], [12, 42], [12, 79], [12, 82], [12, 144], [12, 150], [12, 157], [12, 172], [12, 207], [13, 32], [13, 49], [13, 66], [13, 97], [13, 162], [13, 212], [13, 223], [14, 42], [14, 50], [14, 80], [14, 81], [14, 114], [14, 121], [15, 21], [15, 64], [15, 72], [15, 82], [15, 100], [15, 159], [15, 185], [16, 30], [16, 49], [16, 59], [16, 69], [16, 130], [16, 179], [16, 187], [16, 236], [17, 31], [17, 32], [17, 54], [17, 70], [17, 110], [17, 129], [17, 153], [17, 181], [17, 239], [18, 30], [18, 69], [18, 81], [18, 93], [18, 94], [18, 122], [18, 152], [18, 168], [18, 213], [18, 223], [19, 45], [19, 53], [19, 54], [19, 71], [19, 117], [19, 122], [19, 135], [19, 148], [20, 51], [20, 60], [20, 64], [20, 98], [20, 131], [20, 187], [20, 189], [20, 193], [20, 210], [20, 222], [20, 226], [21, 73], [21, 99], [21, 114], [21, 192], [21, 206], [21, 207], [21, 222], [21, 239], [22, 88], [22, 127], [22, 148], [22, 164], [22, 169], [22, 198], [22, 207], [22, 232], [23, 47], [23, 154], [23, 175], [23, 195], [23, 217], [24, 46], [24, 107], [24, 112], [24, 138], [24, 160], [24, 171], [24, 179], [24, 180], [24, 189], [24, 204], [25, 30], [25, 43], [25, 98], [25, 106], [25, 138], [25, 145], [25, 151], [25, 158], [25, 163], [25, 171], [25, 210], [25, 217], [25, 220], [26, 33], [26, 69], [26, 182], [27, 31], [27, 42], [27, 93], [27, 134], [27, 135], [27, 183], [27, 189], [27, 196], [28, 52], [28, 55], [28, 72], [28, 180], [28, 225], [28, 237], [28, 240], [29, 43], [29, 50], [29, 60], [29, 123], [29, 134], [29, 151], [29, 183], [29, 219], [29, 220], [30, 60], [30, 78], [30, 82], [30, 115], [30, 131], [30, 171], [30, 242], [31, 38], [31, 108], [31, 112], [31, 122], [31, 179], [32, 123], [32, 158], [32, 161], [32, 166], [32, 201], [32, 214], [32, 221], [33, 45], [33, 63], [33, 150], [34, 64], [34, 103], [34, 106], [34, 120], [35, 37], [35, 81], [35, 111], [35, 125], [35, 182], [35, 248], [36, 63], [36, 77], [36, 79], [36, 85], [36, 106], [36, 110], [36, 165], [36, 172], [36, 177], [36, 239], [36, 248], [37, 88], [37, 122], [37, 141], [37, 169], [37, 177], [37, 203], [37, 210], [37, 240], [38, 56], [38, 74], [38, 79], [38, 82], [38, 105], [38, 136], [38, 173], [38, 181], [38, 224], [39, 145], [39, 156], [39, 203], [39, 209], [40, 93], [40, 119], [40, 133], [40, 150], [40, 247], [41, 42], [41, 65], [41, 73], [41, 108], [41, 136], [41, 151], [41, 156], [41, 159], [41, 167], [41, 187], [41, 193], [41, 206], [41, 210], [41, 232], [41, 234], [42, 101], [42, 133], [42, 139], [42, 152], [42, 162], [42, 171], [42, 172], [42, 237], [43, 54], [43, 64], [43, 70], [43, 98], [43, 147], [43, 164], [43, 192], [43, 214], [43, 219], [43, 245], [44, 66], [44, 128], [44, 132], [44, 147], [44, 165], [44, 169], [44, 184], [44, 205], [44, 233], [45, 92], [45, 101], [45, 121], [45, 148], [45, 188], [45, 205], [45, 212], [45, 213], [45, 234], [46, 84], [46, 93], [46, 141], [46, 159], [46, 160], [46, 161], [46, 179], [46, 200], [46, 247], [47, 71], [47, 98], [47, 124], [47, 165], [47, 186], [47, 195], [47, 203], [47, 206], [47, 215], [47, 247], [48, 70], [48, 73], [48, 121], [48, 144], [48, 164], [48, 168], [48, 248], [49, 66], [49, 88], [49, 94], [49, 96], [49, 108], [49, 155], [49, 197], [49, 208], [49, 229], [50, 68], [50, 94], [50, 140], [50, 184], [50, 237], [51, 83], [51, 223], [52, 53], [52, 166], [52, 178], [52, 229], [52, 249], [53, 65], [53, 100], [53, 133], [53, 167], [53, 217], [54, 196], [54, 229], [54, 237], [55, 57], [55, 65], [55, 80], [55, 104], [55, 149], [55, 161], [55, 226], [55, 236], [56, 60], [56, 70], [56, 74], [56, 82], [56, 96], [56, 212], [57, 96], [57, 106], [57, 111], [57, 138], [57, 181], [57, 210], [57, 248], [58, 93], [58, 99], [58, 112], [58, 133], [58, 175], [58, 205], [58, 224], [58, 238], [59, 60], [59, 118], [59, 137], [59, 198], [59, 219], [60, 85], [60, 98], [60, 119], [60, 129], [60, 142], [60, 143], [60, 202], [60, 207], [60, 215], [60, 236], [60, 249], [61, 66], [61, 101], [61, 109], [61, 111], [61, 115], [61, 189], [61, 222], [62, 143], [62, 157], [62, 167], [62, 188], [62, 210], [62, 224], [62, 247], [63, 66], [63, 105], [63, 132], [64, 69], [64, 88], [64, 129], [64, 154], [64, 191], [64, 218], [64, 223], [65, 117], [65, 130], [65, 148], [65, 176], [66, 91], [66, 119], [66, 158], [67, 196], [67, 244], [68, 77], [68, 83], [68, 113], [68, 120], [68, 144], [68, 185], [68, 229], [68, 248], [69, 91], [69, 96], [69, 101], [69, 105], [69, 126], [69, 145], [70, 92], [70, 115], [70, 117], [70, 170], [70, 188], [71, 96], [71, 143], [71, 165], [71, 177], [71, 182], [71, 210], [71, 228], [71, 234], [72, 115], [72, 200], [72, 208], [72, 210], [72, 226], [72, 238], [73, 81], [73, 98], [73, 130], [73, 164], [73, 167], [73, 174], [73, 199], [74, 137], [74, 146], [74, 152], [74, 165], [74, 226], [75, 121], [75, 128], [75, 157], [75, 158], [75, 187], [75, 236], [76, 106], [76, 108], [76, 112], [76, 133], [76, 135], [76, 166], [76, 169], [76, 194], [76, 211], [76, 229], [76, 238], [77, 132], [77, 135], [77, 173], [77, 194], [77, 214], [78, 127], [78, 165], [78, 173], [78, 177], [78, 211], [79, 107], [79, 180], [79, 188], [79, 196], [79, 207], [79, 214], [79, 221], [79, 241], [80, 89], [80, 149], [80, 157], [80, 169], [80, 181], [80, 206], [80, 208], [81, 88], [81, 118], [81, 128], [81, 153], [81, 183], [81, 199], [81, 200], [81, 212], [82, 126], [82, 142], [82, 152], [82, 168], [82, 198], [82, 203], [82, 228], [83, 85], [83, 110], [83, 188], [83, 205], [83, 240], [84, 89], [84, 94], [84, 108], [84, 177], [84, 181], [84, 229], [85, 122], [85, 126], [85, 168], [85, 215], [86, 90], [86, 105], [86, 134], [86, 177], [87, 109], [87, 119], [87, 166], [87, 180], [88, 98], [88, 212], [88, 223], [88, 239], [89, 113], [89, 121], [89, 164], [89, 182], [89, 225], [90, 146], [90, 170], [91, 103], [91, 133], [91, 142], [91, 153], [91, 161], [91, 170], [91, 184], [91, 200], [91, 202], [92, 111], [92, 127], [92, 130], [92, 132], [92, 152], [92, 171], [92, 217], [92, 230], [93, 175], [93, 199], [93, 208], [94, 123], [94, 124], [94, 141], [94, 142], [94, 177], [94, 238], [94, 244], [95, 133], [95, 159], [96, 104], [96, 148], [96, 156], [96, 160], [96, 165], [96, 208], [96, 209], [96, 213], [96, 215], [96, 219], [97, 141], [97, 142], [97, 155], [97, 176], [97, 198], [97, 212], [98, 165], [98, 177], [98, 227], [98, 228], [98, 248], [99, 122], [99, 126], [99, 145], [99, 179], [99, 222], [100, 109], [100, 148], [100, 169], [100, 182], [100, 208], [100, 235], [101, 118], [101, 143], [101, 168], [101, 189], [101, 193], [102, 126], [102, 132], [102, 157], [102, 163], [102, 221], [102, 244], [103, 118], [103, 120], [103, 152], [103, 156], [103, 185], [103, 217], [103, 221], [104, 108], [104, 163], [104, 165], [104, 183], [104, 184], [104, 188], [104, 199], [104, 224], [105, 156], [105, 173], [105, 184], [105, 212], [106, 133], [106, 138], [106, 139], [106, 175], [107, 117], [107, 122], [107, 124], [107, 223], [107, 236], [108, 119], [108, 205], [108, 249], [109, 122], [109, 126], [109, 152], [109, 158], [109, 164], [109, 165], [109, 167], [109, 168], [109, 197], [109, 236], [110, 130], [110, 161], [110, 164], [110, 173], [110, 194], [110, 224], [110, 233], [111, 184], [112, 175], [113, 117], [113, 193], [113, 218], [114, 169], [114, 174], [114, 181], [114, 242], [115, 125], [115, 145], [115, 210], [115, 222], [115, 238], [116, 140], [116, 148], [116, 175], [116, 196], [116, 197], [116, 244], [117, 160], [117, 188], [117, 189], [117, 206], [117, 248], [118, 172], [118, 181], [118, 197], [118, 206], [119, 156], [119, 178], [120, 192], [121, 171], [121, 187], [121, 205], [121, 221], [121, 224], [122, 163], [122, 171], [122, 215], [122, 228], [123, 140], [123, 236], [123, 243], [124, 131], [124, 146], [125, 130], [125, 132], [125, 151], [125, 171], [125, 180], [126, 146], [126, 149], [126, 151], [126, 160], [126, 174], [126, 184], [126, 216], [126, 238], [126, 242], [127, 184], [127, 233], [128, 132], [128, 133], [128, 142], [128, 159], [128, 209], [128, 227], [128, 234], [128, 240], [129, 131], [129, 132], [129, 154], [129, 164], [129, 172], [129, 225], [129, 233], [129, 240], [130, 175], [130, 209], [131, 135], [131, 139], [131, 179], [131, 183], [131, 209], [131, 210], [132, 143], [132, 148], [133, 136], [133, 144], [133, 152], [133, 170], [133, 197], [133, 236], [133, 248], [134, 150], [134, 167], [134, 212], [134, 244], [135, 139], [135, 180], [135, 215], [136, 144], [136, 148], [136, 188], [136, 218], [137, 193], [137, 224], [137, 239], [138, 192], [138, 196], [138, 199], [138, 211], [138, 217], [139, 140], [139, 143], [139, 150], [139, 162], [139, 184], [139, 239], [140, 190], [140, 200], [140, 215], [140, 225], [141, 143], [141, 160], [141, 169], [141, 204], [141, 230], [141, 233], [141, 241], [142, 144], [142, 154], [142, 185], [143, 162], [143, 179], [143, 189], [143, 194], [143, 196], [143, 202], [143, 223], [143, 231], [144, 158], [144, 162], [144, 163], [144, 165], [145, 198], [145, 226], [146, 148], [146, 152], [146, 184], [146, 248], [147, 163], [147, 178], [147, 187], [147, 238], [148, 155], [148, 157], [148, 160], [148, 191], [148, 209], [148, 229], [149, 152], [149, 242], [150, 200], [150, 216], [150, 235], [151, 174], [153, 196], [153, 230], [153, 244], [153, 246], [154, 159], [154, 168], [154, 183], [154, 210], [154, 212], [154, 226], [154, 248], [155, 208], [155, 214], [155, 246], [156, 224], [157, 210], [157, 228], [158, 174], [158, 196], [158, 205], [159, 162], [159, 176], [159, 190], [159, 192], [159, 196], [159, 238], [160, 176], [160, 189], [160, 206], [161, 178], [162, 170], [162, 201], [162, 215], [162, 235], [163, 215], [164, 172], [164, 173], [164, 192], [164, 197], [164, 214], [164, 233], [165, 196], [165, 218], [165, 219], [165, 231], [166, 233], [166, 237], [167, 188], [167, 191], [167, 195], [168, 196], [168, 205], [169, 195], [169, 234], [170, 173], [170, 232], [172, 243], [173, 183], [173, 199], [173, 211], [174, 179], [175, 183], [175, 223], [176, 220], [177, 201], [177, 212], [177, 218], [177, 219], [177, 230], [177, 245], [179, 216], [179, 220], [179, 241], [180, 192], [180, 213], [181, 187], [181, 247], [182, 204], [183, 225], [184, 206], [184, 221], [184, 223], [184, 244], [184, 246], [185, 210], [185, 217], [185, 239], [185, 240], [186, 200], [186, 202], [186, 207], [186, 248], [187, 212], [187, 213], [189, 190], [189, 209], [189, 211], [191, 219], [191, 230], [192, 193], [192, 198], [192, 207], [192, 237], [193, 220], [193, 242], [194, 249], [195, 232], [195, 245], [196, 197], [196, 247], [197, 249], [198, 209], [198, 215], [198, 245], [199, 221], [201, 209], [201, 230], [201, 245], [202, 238], [206, 215], [206, 229], [206, 243], [207, 226], [207, 240], [208, 231], [209, 222], [209, 242], [209, 249], [212, 232], [212, 241], [213, 236], [215, 227], [216, 224], [216, 238], [218, 224], [219, 221], [219, 239], [219, 248], [221, 231], [222, 235], [223, 224], [223, 232], [223, 238], [225, 232], [225, 245], [227, 232], [229, 230], [230, 245], [234, 245], [235, 239], [243, 244]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l6-s6/tests/run.py b/tasks/construct-mc-graph-k-coloring-l6-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-graph-k-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-mc-graph-k-coloring-l6-s6/tests/test.sh b/tasks/construct-mc-graph-k-coloring-l6-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-graph-k-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-mc-hadamard-l2-s1/environment/Dockerfile b/tasks/construct-mc-hadamard-l2-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-hadamard-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-mc-hadamard-l2-s1/environment/instance.json b/tasks/construct-mc-hadamard-l2-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..859345770b6cc22257f31826c8a2b36ddd952bf2 --- /dev/null +++ b/tasks/construct-mc-hadamard-l2-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 15, "family": "mc_hadamard", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-hadamard-l2-s1/solution/solve.sh b/tasks/construct-mc-hadamard-l2-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..957d64b5ce9b6a6bda2912b3923d8d6ce8aa3147 --- /dev/null +++ b/tasks/construct-mc-hadamard-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' +{"x": [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]} +RLMATH_EOF diff --git a/tasks/construct-mc-hadamard-l2-s1/tests/check.py b/tasks/construct-mc-hadamard-l2-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..fc4b93160fd7473dd14935db9d712e52abdd00c2 --- /dev/null +++ b/tasks/construct-mc-hadamard-l2-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-l2-s1/tests/instance.json b/tasks/construct-mc-hadamard-l2-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..859345770b6cc22257f31826c8a2b36ddd952bf2 --- /dev/null +++ b/tasks/construct-mc-hadamard-l2-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 15, "family": "mc_hadamard", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-hadamard-l2-s1/tests/run.py b/tasks/construct-mc-hadamard-l2-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-hadamard-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-mc-hadamard-l2-s1/tests/test.sh b/tasks/construct-mc-hadamard-l2-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-hadamard-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-mc-hadamard-l6-s9/environment/Dockerfile b/tasks/construct-mc-hadamard-l6-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-hadamard-l6-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-hadamard-l6-s9/environment/instance.json b/tasks/construct-mc-hadamard-l6-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bf16642fe740a04ed8858c68089d8d14e3a89e36 --- /dev/null +++ b/tasks/construct-mc-hadamard-l6-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 67, "family": "mc_hadamard", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-hadamard-l6-s9/solution/solve.sh b/tasks/construct-mc-hadamard-l6-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8adcf95f38d2bff581c5e83904f6e3977404c0ad --- /dev/null +++ b/tasks/construct-mc-hadamard-l6-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": [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, 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, 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-l6-s9/tests/check.py b/tasks/construct-mc-hadamard-l6-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..fc4b93160fd7473dd14935db9d712e52abdd00c2 --- /dev/null +++ b/tasks/construct-mc-hadamard-l6-s9/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-l6-s9/tests/instance.json b/tasks/construct-mc-hadamard-l6-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bf16642fe740a04ed8858c68089d8d14e3a89e36 --- /dev/null +++ b/tasks/construct-mc-hadamard-l6-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 67, "family": "mc_hadamard", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-hadamard-l6-s9/tests/run.py b/tasks/construct-mc-hadamard-l6-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-hadamard-l6-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-hadamard-l6-s9/tests/test.sh b/tasks/construct-mc-hadamard-l6-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-hadamard-l6-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-langford-l6-s1/environment/Dockerfile b/tasks/construct-mc-langford-l6-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-langford-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-mc-langford-l6-s1/environment/instance.json b/tasks/construct-mc-langford-l6-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..97b20b970c3e5977538693cc06c869cfe580f6e7 --- /dev/null +++ b/tasks/construct-mc-langford-l6-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 40, "fixed": [], "family": "mc_langford", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-langford-l6-s1/solution/solve.sh b/tasks/construct-mc-langford-l6-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a59780d780fb7c5675fc9e704c3df4b5c169e127 --- /dev/null +++ b/tasks/construct-mc-langford-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' +{"seq": [20, 5, 28, 15, 19, 17, 22, 5, 24, 32, 35, 14, 1, 33, 1, 34, 11, 26, 21, 15, 27, 20, 30, 17, 19, 37, 14, 13, 11, 22, 39, 28, 4, 24, 40, 25, 36, 4, 18, 38, 21, 13, 32, 23, 26, 31, 35, 33, 27, 29, 34, 12, 7, 30, 10, 16, 9, 18, 3, 8, 7, 25, 3, 37, 12, 10, 9, 23, 8, 6, 39, 2, 16, 36, 2, 40, 6, 31, 38, 29]} +RLMATH_EOF diff --git a/tasks/construct-mc-langford-l6-s1/tests/check.py b/tasks/construct-mc-langford-l6-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4672d7eacf321991933cb280d6c940f1c4a67935 --- /dev/null +++ b/tasks/construct-mc-langford-l6-s1/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-l6-s1/tests/instance.json b/tasks/construct-mc-langford-l6-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..97b20b970c3e5977538693cc06c869cfe580f6e7 --- /dev/null +++ b/tasks/construct-mc-langford-l6-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 40, "fixed": [], "family": "mc_langford", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-langford-l6-s1/tests/run.py b/tasks/construct-mc-langford-l6-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-langford-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-mc-langford-l6-s1/tests/test.sh b/tasks/construct-mc-langford-l6-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-langford-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-mc-low-autocorrelation-l4-s3/environment/Dockerfile b/tasks/construct-mc-low-autocorrelation-l4-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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-low-autocorrelation-l4-s3/environment/instance.json b/tasks/construct-mc-low-autocorrelation-l4-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9b76dcbb3c63e9166147a71023998c224328640a --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l4-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 36, "bound": 130, "fixed": [], "family": "mc_low_autocorrelation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-low-autocorrelation-l4-s3/solution/solve.sh b/tasks/construct-mc-low-autocorrelation-l4-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7db8050275d2a818c5c5be63f3022cc7f68cd1d1 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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' +{"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]} +RLMATH_EOF diff --git a/tasks/construct-mc-low-autocorrelation-l4-s3/tests/check.py b/tasks/construct-mc-low-autocorrelation-l4-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8456f7b1c0ff0c9fb4bc9ae5a49074c8afa7d1aa --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l4-s3/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-l4-s3/tests/instance.json b/tasks/construct-mc-low-autocorrelation-l4-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9b76dcbb3c63e9166147a71023998c224328640a --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l4-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 36, "bound": 130, "fixed": [], "family": "mc_low_autocorrelation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-low-autocorrelation-l4-s3/tests/run.py b/tasks/construct-mc-low-autocorrelation-l4-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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-low-autocorrelation-l4-s3/tests/test.sh b/tasks/construct-mc-low-autocorrelation-l4-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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-low-autocorrelation-l4-s4/environment/Dockerfile b/tasks/construct-mc-low-autocorrelation-l4-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l4-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-low-autocorrelation-l4-s4/environment/instance.json b/tasks/construct-mc-low-autocorrelation-l4-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0de1a70f0f4bec7c686a1f9578b4efb20959f5bc --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l4-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 32, "bound": 102, "fixed": [], "family": "mc_low_autocorrelation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-low-autocorrelation-l4-s4/solution/solve.sh b/tasks/construct-mc-low-autocorrelation-l4-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c2f7117ed4c0b8280d601ba5e1b17907a35bb37e --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l4-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' +{"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]} +RLMATH_EOF diff --git a/tasks/construct-mc-low-autocorrelation-l4-s4/tests/check.py b/tasks/construct-mc-low-autocorrelation-l4-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8456f7b1c0ff0c9fb4bc9ae5a49074c8afa7d1aa --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l4-s4/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-l4-s4/tests/instance.json b/tasks/construct-mc-low-autocorrelation-l4-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0de1a70f0f4bec7c686a1f9578b4efb20959f5bc --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l4-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 32, "bound": 102, "fixed": [], "family": "mc_low_autocorrelation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-low-autocorrelation-l4-s4/tests/run.py b/tasks/construct-mc-low-autocorrelation-l4-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l4-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-low-autocorrelation-l4-s4/tests/test.sh b/tasks/construct-mc-low-autocorrelation-l4-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l4-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-magic-sequence-l3-s2/environment/Dockerfile b/tasks/construct-mc-magic-sequence-l3-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-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-l3-s2/environment/instance.json b/tasks/construct-mc-magic-sequence-l3-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b3b9505cc63f96b7b85b0fa7c2d0fd8977eb04be --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 11, "fixed": [], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l3-s2/solution/solve.sh b/tasks/construct-mc-magic-sequence-l3-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..53735d68408cb691942bc64856add404694aa60d --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-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": [7, 2, 1, 0, 0, 0, 0, 1, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-magic-sequence-l3-s2/tests/check.py b/tasks/construct-mc-magic-sequence-l3-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..27f636ddd6cfe523924ae01c6b9f37ee392f0332 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-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-l3-s2/tests/instance.json b/tasks/construct-mc-magic-sequence-l3-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b3b9505cc63f96b7b85b0fa7c2d0fd8977eb04be --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 11, "fixed": [], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l3-s2/tests/run.py b/tasks/construct-mc-magic-sequence-l3-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-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-l3-s2/tests/test.sh b/tasks/construct-mc-magic-sequence-l3-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-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-l3-s5/environment/Dockerfile b/tasks/construct-mc-magic-sequence-l3-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-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-l3-s5/environment/instance.json b/tasks/construct-mc-magic-sequence-l3-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f1ece7f30ac740b3428d0546a7a1c0582276f910 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 16, "fixed": [], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l3-s5/solution/solve.sh b/tasks/construct-mc-magic-sequence-l3-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..fd54d8b22a2478b1da8c1d841eecd63018717140 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-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": [12, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-magic-sequence-l3-s5/tests/check.py b/tasks/construct-mc-magic-sequence-l3-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..27f636ddd6cfe523924ae01c6b9f37ee392f0332 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-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-l3-s5/tests/instance.json b/tasks/construct-mc-magic-sequence-l3-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f1ece7f30ac740b3428d0546a7a1c0582276f910 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 16, "fixed": [], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l3-s5/tests/run.py b/tasks/construct-mc-magic-sequence-l3-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-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-l3-s5/tests/test.sh b/tasks/construct-mc-magic-sequence-l3-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-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-l4-s3/environment/Dockerfile b/tasks/construct-mc-max-clique-l4-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-clique-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-max-clique-l4-s3/environment/instance.json b/tasks/construct-mc-max-clique-l4-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b2562bb7750172673ca3d7376ef5194d2b388a8b --- /dev/null +++ b/tasks/construct-mc-max-clique-l4-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 57, "k": 7, "edges": [[0, 1], [0, 2], [0, 8], [0, 9], [0, 10], [0, 17], [0, 18], [0, 19], [0, 21], [0, 22], [0, 24], [0, 25], [0, 29], [0, 33], [0, 34], [0, 36], [0, 39], [0, 41], [0, 49], [0, 52], [0, 53], [0, 55], [1, 3], [1, 5], [1, 7], [1, 8], [1, 9], [1, 13], [1, 16], [1, 21], [1, 23], [1, 25], [1, 26], [1, 28], [1, 31], [1, 32], [1, 37], [1, 38], [1, 39], [1, 40], [1, 41], [1, 43], [1, 44], [1, 45], [1, 47], [1, 50], [1, 56], [2, 3], [2, 4], [2, 5], [2, 10], [2, 16], [2, 17], [2, 18], [2, 20], [2, 23], [2, 25], [2, 30], [2, 32], [2, 37], [2, 38], [2, 44], [2, 45], [2, 46], [2, 47], [2, 53], [2, 54], [2, 56], [3, 4], [3, 8], [3, 11], [3, 12], [3, 13], [3, 16], [3, 17], [3, 18], [3, 19], [3, 20], [3, 22], [3, 24], [3, 28], [3, 33], [3, 35], [3, 40], [3, 42], [3, 43], [3, 44], [3, 45], [3, 50], [3, 54], [3, 56], [4, 6], [4, 7], [4, 10], [4, 11], [4, 12], [4, 13], [4, 14], [4, 16], [4, 17], [4, 20], [4, 23], [4, 24], [4, 25], [4, 28], [4, 32], [4, 34], [4, 36], [4, 41], [4, 42], [4, 43], [4, 45], [4, 46], [4, 47], [4, 49], [4, 51], [4, 54], [5, 7], [5, 9], [5, 12], [5, 13], [5, 14], [5, 15], [5, 17], [5, 20], [5, 23], [5, 26], [5, 27], [5, 28], [5, 31], [5, 32], [5, 33], [5, 34], [5, 36], [5, 40], [5, 41], [5, 43], [5, 44], [5, 47], [5, 48], [5, 51], [5, 56], [6, 7], [6, 8], [6, 11], [6, 12], [6, 15], [6, 16], [6, 17], [6, 18], [6, 20], [6, 24], [6, 27], [6, 29], [6, 31], [6, 32], [6, 34], [6, 36], [6, 37], [6, 39], [6, 42], [6, 43], [6, 45], [6, 49], [6, 53], [7, 8], [7, 11], [7, 12], [7, 13], [7, 14], [7, 15], [7, 16], [7, 17], [7, 18], [7, 22], [7, 25], [7, 27], [7, 31], [7, 33], [7, 34], [7, 36], [7, 37], [7, 38], [7, 39], [7, 41], [7, 42], [7, 44], [7, 45], [7, 47], [7, 52], [7, 53], [7, 54], [8, 11], [8, 13], [8, 16], [8, 17], [8, 25], [8, 26], [8, 29], [8, 30], [8, 31], [8, 32], [8, 33], [8, 34], [8, 36], [8, 37], [8, 40], [8, 41], [8, 43], [8, 47], [8, 48], [8, 49], [8, 51], [8, 52], [8, 53], [8, 55], [9, 12], [9, 13], [9, 16], [9, 19], [9, 22], [9, 24], [9, 27], [9, 28], [9, 29], [9, 35], [9, 36], [9, 37], [9, 42], [9, 43], [9, 44], [9, 46], [9, 48], [9, 52], [9, 54], [9, 56], [10, 12], [10, 13], [10, 14], [10, 15], [10, 18], [10, 19], [10, 21], [10, 22], [10, 27], [10, 30], [10, 33], [10, 35], [10, 37], [10, 45], [10, 50], [10, 51], [11, 12], [11, 14], [11, 15], [11, 17], [11, 20], [11, 21], [11, 24], [11, 25], [11, 26], [11, 28], [11, 30], [11, 31], [11, 33], [11, 34], [11, 38], [11, 44], [11, 46], [11, 47], [11, 48], [11, 49], [11, 50], [11, 51], [12, 13], [12, 14], [12, 15], [12, 17], [12, 19], [12, 24], [12, 25], [12, 27], [12, 32], [12, 34], [12, 35], [12, 37], [12, 38], [12, 41], [12, 44], [12, 45], [12, 47], [12, 48], [12, 50], [12, 51], [12, 56], [13, 17], [13, 18], [13, 21], [13, 24], [13, 25], [13, 26], [13, 27], [13, 29], [13, 30], [13, 32], [13, 34], [13, 37], [13, 38], [13, 39], [13, 43], [13, 45], [13, 47], [13, 48], [13, 49], [14, 15], [14, 16], [14, 18], [14, 19], [14, 21], [14, 22], [14, 23], [14, 25], [14, 28], [14, 30], [14, 31], [14, 32], [14, 35], [14, 37], [14, 40], [14, 45], [14, 47], [14, 48], [14, 50], [14, 51], [14, 53], [14, 55], [14, 56], [15, 17], [15, 18], [15, 19], [15, 20], [15, 21], [15, 23], [15, 26], [15, 30], [15, 32], [15, 38], [15, 39], [15, 41], [15, 44], [15, 45], [15, 46], [15, 48], [15, 49], [15, 50], [15, 51], [15, 54], [15, 56], [16, 18], [16, 22], [16, 24], [16, 25], [16, 27], [16, 29], [16, 31], [16, 33], [16, 38], [16, 40], [16, 41], [16, 44], [16, 45], [16, 46], [16, 49], [16, 52], [16, 53], [17, 18], [17, 19], [17, 20], [17, 24], [17, 25], [17, 27], [17, 28], [17, 29], [17, 32], [17, 33], [17, 35], [17, 37], [17, 45], [17, 49], [17, 50], [17, 51], [17, 52], [18, 19], [18, 22], [18, 26], [18, 28], [18, 32], [18, 35], [18, 37], [18, 38], [18, 40], [18, 41], [18, 42], [18, 46], [18, 48], [18, 49], [18, 50], [18, 52], [18, 53], [19, 21], [19, 22], [19, 23], [19, 26], [19, 31], [19, 34], [19, 39], [19, 40], [19, 43], [19, 47], [19, 51], [19, 52], [19, 53], [19, 54], [19, 56], [20, 21], [20, 23], [20, 25], [20, 26], [20, 28], [20, 29], [20, 31], [20, 33], [20, 36], [20, 37], [20, 38], [20, 40], [20, 42], [20, 46], [20, 48], [20, 54], [20, 56], [21, 25], [21, 26], [21, 28], [21, 29], [21, 30], [21, 31], [21, 32], [21, 35], [21, 38], [21, 40], [21, 41], [21, 42], [21, 43], [21, 44], [21, 46], [21, 50], [21, 53], [21, 54], [21, 55], [22, 24], [22, 28], [22, 33], [22, 34], [22, 35], [22, 37], [22, 38], [22, 42], [22, 43], [22, 44], [22, 47], [22, 48], [22, 51], [23, 24], [23, 27], [23, 33], [23, 35], [23, 36], [23, 37], [23, 39], [23, 40], [23, 45], [23, 48], [23, 49], [23, 51], [23, 53], [23, 54], [23, 55], [24, 29], [24, 33], [24, 34], [24, 35], [24, 36], [24, 37], [24, 42], [24, 43], [24, 48], [24, 50], [24, 53], [24, 54], [24, 56], [25, 29], [25, 30], [25, 32], [25, 35], [25, 36], [25, 38], [25, 41], [25, 44], [25, 46], [25, 47], [25, 48], [25, 49], [25, 50], [25, 52], [26, 27], [26, 33], [26, 36], [26, 37], [26, 43], [26, 44], [26, 45], [26, 46], [26, 50], [26, 53], [27, 29], [27, 30], [27, 32], [27, 33], [27, 34], [27, 36], [27, 37], [27, 38], [27, 42], [27, 44], [27, 45], [27, 46], [27, 48], [27, 49], [27, 50], [27, 55], [28, 31], [28, 32], [28, 33], [28, 34], [28, 36], [28, 37], [28, 39], [28, 41], [28, 42], [28, 43], [28, 44], [28, 45], [28, 48], [28, 52], [28, 53], [29, 30], [29, 31], [29, 37], [29, 38], [29, 41], [29, 45], [29, 47], [29, 48], [29, 50], [29, 54], [30, 32], [30, 33], [30, 34], [30, 37], [30, 39], [30, 44], [30, 48], [30, 49], [30, 50], [30, 55], [30, 56], [31, 42], [31, 43], [31, 46], [31, 48], [31, 51], [32, 40], [32, 41], [32, 46], [32, 47], [32, 48], [32, 52], [32, 54], [32, 55], [32, 56], [33, 36], [33, 38], [33, 43], [33, 44], [33, 45], [33, 47], [33, 48], [33, 54], [33, 55], [33, 56], [34, 36], [34, 37], [34, 38], [34, 40], [34, 41], [34, 42], [34, 43], [34, 44], [34, 48], [35, 36], [35, 37], [35, 40], [35, 42], [35, 43], [35, 44], [35, 45], [35, 46], [35, 48], [35, 49], [35, 53], [35, 54], [36, 38], [36, 42], [36, 44], [36, 47], [36, 49], [36, 50], [36, 51], [36, 52], [36, 53], [36, 54], [36, 56], [37, 38], [37, 45], [37, 46], [37, 50], [37, 51], [37, 52], [37, 53], [38, 41], [38, 42], [38, 45], [38, 46], [38, 48], [38, 49], [38, 50], [38, 51], [38, 56], [39, 40], [39, 41], [39, 42], [39, 45], [39, 46], [39, 52], [39, 53], [39, 55], [39, 56], [40, 41], [40, 44], [40, 49], [40, 52], [40, 56], [41, 43], [41, 44], [41, 45], [41, 47], [41, 48], [41, 52], [41, 54], [42, 45], [42, 48], [42, 50], [42, 51], [42, 52], [42, 54], [43, 44], [43, 45], [43, 46], [43, 49], [43, 50], [43, 53], [43, 54], [43, 56], [44, 45], [44, 54], [44, 55], [44, 56], [45, 52], [45, 53], [45, 54], [45, 56], [46, 48], [46, 49], [46, 50], [46, 51], [46, 53], [46, 54], [46, 55], [47, 48], [47, 50], [47, 51], [47, 52], [47, 56], [48, 51], [48, 52], [48, 55], [48, 56], [49, 50], [49, 52], [49, 54], [50, 52], [50, 53], [50, 55], [50, 56], [51, 53], [51, 56], [52, 53], [52, 54], [52, 56], [53, 54], [53, 55], [53, 56], [54, 55], [54, 56], [55, 56]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l4-s3/solution/solve.sh b/tasks/construct-mc-max-clique-l4-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..84285924bf9f89e534386d90c963f439f01a3f7d --- /dev/null +++ b/tasks/construct-mc-max-clique-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' +{"clique": [3, 33, 43, 44, 45, 54, 56]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-clique-l4-s3/tests/check.py b/tasks/construct-mc-max-clique-l4-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3f70dbd5b155a3514c2102aa4ad460201495210 --- /dev/null +++ b/tasks/construct-mc-max-clique-l4-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-l4-s3/tests/instance.json b/tasks/construct-mc-max-clique-l4-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b2562bb7750172673ca3d7376ef5194d2b388a8b --- /dev/null +++ b/tasks/construct-mc-max-clique-l4-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 57, "k": 7, "edges": [[0, 1], [0, 2], [0, 8], [0, 9], [0, 10], [0, 17], [0, 18], [0, 19], [0, 21], [0, 22], [0, 24], [0, 25], [0, 29], [0, 33], [0, 34], [0, 36], [0, 39], [0, 41], [0, 49], [0, 52], [0, 53], [0, 55], [1, 3], [1, 5], [1, 7], [1, 8], [1, 9], [1, 13], [1, 16], [1, 21], [1, 23], [1, 25], [1, 26], [1, 28], [1, 31], [1, 32], [1, 37], [1, 38], [1, 39], [1, 40], [1, 41], [1, 43], [1, 44], [1, 45], [1, 47], [1, 50], [1, 56], [2, 3], [2, 4], [2, 5], [2, 10], [2, 16], [2, 17], [2, 18], [2, 20], [2, 23], [2, 25], [2, 30], [2, 32], [2, 37], [2, 38], [2, 44], [2, 45], [2, 46], [2, 47], [2, 53], [2, 54], [2, 56], [3, 4], [3, 8], [3, 11], [3, 12], [3, 13], [3, 16], [3, 17], [3, 18], [3, 19], [3, 20], [3, 22], [3, 24], [3, 28], [3, 33], [3, 35], [3, 40], [3, 42], [3, 43], [3, 44], [3, 45], [3, 50], [3, 54], [3, 56], [4, 6], [4, 7], [4, 10], [4, 11], [4, 12], [4, 13], [4, 14], [4, 16], [4, 17], [4, 20], [4, 23], [4, 24], [4, 25], [4, 28], [4, 32], [4, 34], [4, 36], [4, 41], [4, 42], [4, 43], [4, 45], [4, 46], [4, 47], [4, 49], [4, 51], [4, 54], [5, 7], [5, 9], [5, 12], [5, 13], [5, 14], [5, 15], [5, 17], [5, 20], [5, 23], [5, 26], [5, 27], [5, 28], [5, 31], [5, 32], [5, 33], [5, 34], [5, 36], [5, 40], [5, 41], [5, 43], [5, 44], [5, 47], [5, 48], [5, 51], [5, 56], [6, 7], [6, 8], [6, 11], [6, 12], [6, 15], [6, 16], [6, 17], [6, 18], [6, 20], [6, 24], [6, 27], [6, 29], [6, 31], [6, 32], [6, 34], [6, 36], [6, 37], [6, 39], [6, 42], [6, 43], [6, 45], [6, 49], [6, 53], [7, 8], [7, 11], [7, 12], [7, 13], [7, 14], [7, 15], [7, 16], [7, 17], [7, 18], [7, 22], [7, 25], [7, 27], [7, 31], [7, 33], [7, 34], [7, 36], [7, 37], [7, 38], [7, 39], [7, 41], [7, 42], [7, 44], [7, 45], [7, 47], [7, 52], [7, 53], [7, 54], [8, 11], [8, 13], [8, 16], [8, 17], [8, 25], [8, 26], [8, 29], [8, 30], [8, 31], [8, 32], [8, 33], [8, 34], [8, 36], [8, 37], [8, 40], [8, 41], [8, 43], [8, 47], [8, 48], [8, 49], [8, 51], [8, 52], [8, 53], [8, 55], [9, 12], [9, 13], [9, 16], [9, 19], [9, 22], [9, 24], [9, 27], [9, 28], [9, 29], [9, 35], [9, 36], [9, 37], [9, 42], [9, 43], [9, 44], [9, 46], [9, 48], [9, 52], [9, 54], [9, 56], [10, 12], [10, 13], [10, 14], [10, 15], [10, 18], [10, 19], [10, 21], [10, 22], [10, 27], [10, 30], [10, 33], [10, 35], [10, 37], [10, 45], [10, 50], [10, 51], [11, 12], [11, 14], [11, 15], [11, 17], [11, 20], [11, 21], [11, 24], [11, 25], [11, 26], [11, 28], [11, 30], [11, 31], [11, 33], [11, 34], [11, 38], [11, 44], [11, 46], [11, 47], [11, 48], [11, 49], [11, 50], [11, 51], [12, 13], [12, 14], [12, 15], [12, 17], [12, 19], [12, 24], [12, 25], [12, 27], [12, 32], [12, 34], [12, 35], [12, 37], [12, 38], [12, 41], [12, 44], [12, 45], [12, 47], [12, 48], [12, 50], [12, 51], [12, 56], [13, 17], [13, 18], [13, 21], [13, 24], [13, 25], [13, 26], [13, 27], [13, 29], [13, 30], [13, 32], [13, 34], [13, 37], [13, 38], [13, 39], [13, 43], [13, 45], [13, 47], [13, 48], [13, 49], [14, 15], [14, 16], [14, 18], [14, 19], [14, 21], [14, 22], [14, 23], [14, 25], [14, 28], [14, 30], [14, 31], [14, 32], [14, 35], [14, 37], [14, 40], [14, 45], [14, 47], [14, 48], [14, 50], [14, 51], [14, 53], [14, 55], [14, 56], [15, 17], [15, 18], [15, 19], [15, 20], [15, 21], [15, 23], [15, 26], [15, 30], [15, 32], [15, 38], [15, 39], [15, 41], [15, 44], [15, 45], [15, 46], [15, 48], [15, 49], [15, 50], [15, 51], [15, 54], [15, 56], [16, 18], [16, 22], [16, 24], [16, 25], [16, 27], [16, 29], [16, 31], [16, 33], [16, 38], [16, 40], [16, 41], [16, 44], [16, 45], [16, 46], [16, 49], [16, 52], [16, 53], [17, 18], [17, 19], [17, 20], [17, 24], [17, 25], [17, 27], [17, 28], [17, 29], [17, 32], [17, 33], [17, 35], [17, 37], [17, 45], [17, 49], [17, 50], [17, 51], [17, 52], [18, 19], [18, 22], [18, 26], [18, 28], [18, 32], [18, 35], [18, 37], [18, 38], [18, 40], [18, 41], [18, 42], [18, 46], [18, 48], [18, 49], [18, 50], [18, 52], [18, 53], [19, 21], [19, 22], [19, 23], [19, 26], [19, 31], [19, 34], [19, 39], [19, 40], [19, 43], [19, 47], [19, 51], [19, 52], [19, 53], [19, 54], [19, 56], [20, 21], [20, 23], [20, 25], [20, 26], [20, 28], [20, 29], [20, 31], [20, 33], [20, 36], [20, 37], [20, 38], [20, 40], [20, 42], [20, 46], [20, 48], [20, 54], [20, 56], [21, 25], [21, 26], [21, 28], [21, 29], [21, 30], [21, 31], [21, 32], [21, 35], [21, 38], [21, 40], [21, 41], [21, 42], [21, 43], [21, 44], [21, 46], [21, 50], [21, 53], [21, 54], [21, 55], [22, 24], [22, 28], [22, 33], [22, 34], [22, 35], [22, 37], [22, 38], [22, 42], [22, 43], [22, 44], [22, 47], [22, 48], [22, 51], [23, 24], [23, 27], [23, 33], [23, 35], [23, 36], [23, 37], [23, 39], [23, 40], [23, 45], [23, 48], [23, 49], [23, 51], [23, 53], [23, 54], [23, 55], [24, 29], [24, 33], [24, 34], [24, 35], [24, 36], [24, 37], [24, 42], [24, 43], [24, 48], [24, 50], [24, 53], [24, 54], [24, 56], [25, 29], [25, 30], [25, 32], [25, 35], [25, 36], [25, 38], [25, 41], [25, 44], [25, 46], [25, 47], [25, 48], [25, 49], [25, 50], [25, 52], [26, 27], [26, 33], [26, 36], [26, 37], [26, 43], [26, 44], [26, 45], [26, 46], [26, 50], [26, 53], [27, 29], [27, 30], [27, 32], [27, 33], [27, 34], [27, 36], [27, 37], [27, 38], [27, 42], [27, 44], [27, 45], [27, 46], [27, 48], [27, 49], [27, 50], [27, 55], [28, 31], [28, 32], [28, 33], [28, 34], [28, 36], [28, 37], [28, 39], [28, 41], [28, 42], [28, 43], [28, 44], [28, 45], [28, 48], [28, 52], [28, 53], [29, 30], [29, 31], [29, 37], [29, 38], [29, 41], [29, 45], [29, 47], [29, 48], [29, 50], [29, 54], [30, 32], [30, 33], [30, 34], [30, 37], [30, 39], [30, 44], [30, 48], [30, 49], [30, 50], [30, 55], [30, 56], [31, 42], [31, 43], [31, 46], [31, 48], [31, 51], [32, 40], [32, 41], [32, 46], [32, 47], [32, 48], [32, 52], [32, 54], [32, 55], [32, 56], [33, 36], [33, 38], [33, 43], [33, 44], [33, 45], [33, 47], [33, 48], [33, 54], [33, 55], [33, 56], [34, 36], [34, 37], [34, 38], [34, 40], [34, 41], [34, 42], [34, 43], [34, 44], [34, 48], [35, 36], [35, 37], [35, 40], [35, 42], [35, 43], [35, 44], [35, 45], [35, 46], [35, 48], [35, 49], [35, 53], [35, 54], [36, 38], [36, 42], [36, 44], [36, 47], [36, 49], [36, 50], [36, 51], [36, 52], [36, 53], [36, 54], [36, 56], [37, 38], [37, 45], [37, 46], [37, 50], [37, 51], [37, 52], [37, 53], [38, 41], [38, 42], [38, 45], [38, 46], [38, 48], [38, 49], [38, 50], [38, 51], [38, 56], [39, 40], [39, 41], [39, 42], [39, 45], [39, 46], [39, 52], [39, 53], [39, 55], [39, 56], [40, 41], [40, 44], [40, 49], [40, 52], [40, 56], [41, 43], [41, 44], [41, 45], [41, 47], [41, 48], [41, 52], [41, 54], [42, 45], [42, 48], [42, 50], [42, 51], [42, 52], [42, 54], [43, 44], [43, 45], [43, 46], [43, 49], [43, 50], [43, 53], [43, 54], [43, 56], [44, 45], [44, 54], [44, 55], [44, 56], [45, 52], [45, 53], [45, 54], [45, 56], [46, 48], [46, 49], [46, 50], [46, 51], [46, 53], [46, 54], [46, 55], [47, 48], [47, 50], [47, 51], [47, 52], [47, 56], [48, 51], [48, 52], [48, 55], [48, 56], [49, 50], [49, 52], [49, 54], [50, 52], [50, 53], [50, 55], [50, 56], [51, 53], [51, 56], [52, 53], [52, 54], [52, 56], [53, 54], [53, 55], [53, 56], [54, 55], [54, 56], [55, 56]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l4-s3/tests/run.py b/tasks/construct-mc-max-clique-l4-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-clique-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-max-clique-l4-s3/tests/test.sh b/tasks/construct-mc-max-clique-l4-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-clique-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-max-clique-l4-s4/environment/Dockerfile b/tasks/construct-mc-max-clique-l4-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-clique-l4-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-l4-s4/environment/instance.json b/tasks/construct-mc-max-clique-l4-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9a63cf58dfbd3d7abb1c2d778cceedd7991bb8b0 --- /dev/null +++ b/tasks/construct-mc-max-clique-l4-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 65, "k": 7, "edges": [[0, 1], [0, 2], [0, 5], [0, 7], [0, 12], [0, 13], [0, 16], [0, 19], [0, 23], [0, 24], [0, 26], [0, 28], [0, 29], [0, 30], [0, 32], [0, 33], [0, 34], [0, 36], [0, 37], [0, 39], [0, 40], [0, 42], [0, 43], [0, 44], [0, 45], [0, 47], [0, 48], [0, 49], [0, 50], [0, 53], [0, 54], [0, 55], [0, 56], [0, 57], [0, 58], [0, 60], [0, 62], [0, 63], [1, 5], [1, 8], [1, 9], [1, 11], [1, 13], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 20], [1, 23], [1, 25], [1, 26], [1, 28], [1, 32], [1, 38], [1, 41], [1, 48], [1, 51], [1, 52], [1, 53], [1, 54], [1, 58], [1, 59], [1, 60], [1, 62], [1, 63], [2, 3], [2, 4], [2, 6], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 17], [2, 19], [2, 22], [2, 25], [2, 26], [2, 29], [2, 30], [2, 31], [2, 33], [2, 34], [2, 38], [2, 41], [2, 46], [2, 48], [2, 50], [2, 51], [2, 52], [2, 54], [2, 55], [2, 56], [2, 57], [2, 59], [2, 61], [2, 64], [3, 5], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 14], [3, 15], [3, 17], [3, 18], [3, 19], [3, 20], [3, 21], [3, 22], [3, 23], [3, 24], [3, 25], [3, 26], [3, 30], [3, 32], [3, 34], [3, 35], [3, 36], [3, 42], [3, 43], [3, 45], [3, 47], [3, 48], [3, 50], [3, 51], [3, 52], [3, 53], [3, 54], [3, 57], [3, 59], [3, 60], [3, 62], [4, 9], [4, 10], [4, 11], [4, 12], [4, 13], [4, 14], [4, 16], [4, 17], [4, 18], [4, 20], [4, 21], [4, 22], [4, 27], [4, 28], [4, 30], [4, 31], [4, 32], [4, 34], [4, 38], [4, 40], [4, 41], [4, 43], [4, 44], [4, 45], [4, 47], [4, 48], [4, 50], [4, 55], [4, 56], [4, 57], [4, 58], [4, 59], [4, 61], [4, 64], [5, 7], [5, 11], [5, 13], [5, 14], [5, 18], [5, 22], [5, 24], [5, 25], [5, 26], [5, 27], [5, 30], [5, 31], [5, 33], [5, 36], [5, 37], [5, 38], [5, 39], [5, 40], [5, 41], [5, 42], [5, 43], [5, 44], [5, 45], [5, 47], [5, 48], [5, 49], [5, 54], [5, 55], [5, 57], [5, 58], [5, 60], [5, 61], [6, 7], [6, 9], [6, 12], [6, 13], [6, 14], [6, 15], [6, 16], [6, 17], [6, 19], [6, 20], [6, 22], [6, 26], [6, 27], [6, 28], [6, 30], [6, 31], [6, 32], [6, 33], [6, 35], [6, 36], [6, 39], [6, 40], [6, 42], [6, 49], [6, 50], [6, 54], [6, 55], [6, 56], [6, 57], [6, 58], [6, 59], [6, 61], [6, 62], [6, 64], [7, 9], [7, 11], [7, 12], [7, 13], [7, 15], [7, 16], [7, 17], [7, 20], [7, 26], [7, 27], [7, 29], [7, 30], [7, 31], [7, 32], [7, 33], [7, 34], [7, 35], [7, 37], [7, 38], [7, 39], [7, 41], [7, 43], [7, 45], [7, 47], [7, 48], [7, 49], [7, 53], [7, 59], [7, 61], [7, 62], [7, 64], [8, 9], [8, 11], [8, 13], [8, 14], [8, 17], [8, 18], [8, 19], [8, 20], [8, 21], [8, 22], [8, 24], [8, 26], [8, 28], [8, 31], [8, 32], [8, 35], [8, 41], [8, 45], [8, 46], [8, 48], [8, 49], [8, 50], [8, 51], [8, 52], [8, 53], [8, 55], [8, 56], [8, 57], [8, 59], [8, 63], [9, 15], [9, 16], [9, 17], [9, 18], [9, 21], [9, 22], [9, 23], [9, 24], [9, 28], [9, 29], [9, 30], [9, 33], [9, 34], [9, 37], [9, 38], [9, 39], [9, 41], [9, 42], [9, 43], [9, 46], [9, 49], [9, 51], [9, 52], [9, 54], [9, 55], [9, 56], [9, 59], [9, 60], [9, 62], [9, 63], [9, 64], [10, 15], [10, 22], [10, 24], [10, 25], [10, 26], [10, 28], [10, 29], [10, 30], [10, 31], [10, 33], [10, 37], [10, 41], [10, 42], [10, 43], [10, 44], [10, 48], [10, 49], [10, 50], [10, 51], [10, 52], [10, 54], [10, 56], [10, 59], [10, 62], [11, 12], [11, 14], [11, 15], [11, 16], [11, 17], [11, 19], [11, 24], [11, 25], [11, 26], [11, 27], [11, 29], [11, 30], [11, 36], [11, 39], [11, 40], [11, 41], [11, 42], [11, 43], [11, 46], [11, 47], [11, 48], [11, 49], [11, 52], [11, 53], [11, 54], [11, 57], [11, 58], [11, 59], [11, 60], [11, 61], [11, 62], [11, 64], [12, 14], [12, 15], [12, 19], [12, 21], [12, 22], [12, 23], [12, 24], [12, 27], [12, 29], [12, 31], [12, 33], [12, 36], [12, 37], [12, 38], [12, 42], [12, 44], [12, 45], [12, 46], [12, 48], [12, 49], [12, 50], [12, 51], [12, 52], [12, 53], [12, 56], [12, 57], [12, 58], [12, 59], [12, 60], [12, 61], [12, 62], [12, 63], [13, 14], [13, 18], [13, 19], [13, 21], [13, 22], [13, 23], [13, 24], [13, 26], [13, 29], [13, 30], [13, 32], [13, 33], [13, 34], [13, 36], [13, 37], [13, 40], [13, 42], [13, 44], [13, 45], [13, 46], [13, 49], [13, 50], [13, 51], [13, 52], [13, 53], [13, 54], [13, 56], [13, 57], [13, 58], [13, 59], [13, 60], [13, 61], [13, 63], [14, 17], [14, 18], [14, 19], [14, 22], [14, 24], [14, 27], [14, 28], [14, 30], [14, 32], [14, 33], [14, 34], [14, 36], [14, 40], [14, 42], [14, 47], [14, 49], [14, 50], [14, 55], [14, 58], [14, 60], [14, 61], [15, 16], [15, 18], [15, 19], [15, 22], [15, 25], [15, 28], [15, 29], [15, 33], [15, 34], [15, 35], [15, 36], [15, 37], [15, 38], [15, 41], [15, 46], [15, 48], [15, 49], [15, 50], [15, 52], [15, 53], [15, 57], [15, 58], [15, 59], [15, 60], [15, 64], [16, 17], [16, 18], [16, 20], [16, 22], [16, 24], [16, 25], [16, 27], [16, 29], [16, 30], [16, 31], [16, 32], [16, 33], [16, 34], [16, 35], [16, 36], [16, 39], [16, 42], [16, 43], [16, 46], [16, 47], [16, 49], [16, 50], [16, 51], [16, 53], [16, 55], [16, 56], [16, 57], [16, 62], [17, 18], [17, 20], [17, 21], [17, 26], [17, 27], [17, 30], [17, 32], [17, 33], [17, 36], [17, 37], [17, 40], [17, 41], [17, 45], [17, 47], [17, 48], [17, 52], [17, 57], [17, 60], [17, 63], [18, 19], [18, 20], [18, 23], [18, 24], [18, 26], [18, 27], [18, 28], [18, 29], [18, 30], [18, 31], [18, 32], [18, 35], [18, 36], [18, 40], [18, 41], [18, 42], [18, 43], [18, 45], [18, 46], [18, 47], [18, 48], [18, 49], [18, 50], [18, 51], [18, 58], [18, 59], [18, 60], [18, 62], [18, 64], [19, 21], [19, 22], [19, 28], [19, 29], [19, 31], [19, 32], [19, 34], [19, 35], [19, 37], [19, 40], [19, 44], [19, 45], [19, 46], [19, 47], [19, 52], [19, 54], [19, 56], [19, 58], [19, 61], [19, 62], [19, 63], [19, 64], [20, 21], [20, 22], [20, 23], [20, 24], [20, 25], [20, 26], [20, 27], [20, 28], [20, 29], [20, 30], [20, 31], [20, 32], [20, 33], [20, 35], [20, 36], [20, 37], [20, 42], [20, 43], [20, 46], [20, 49], [20, 53], [20, 54], [20, 57], [20, 61], [20, 62], [20, 63], [21, 27], [21, 28], [21, 29], [21, 30], [21, 33], [21, 36], [21, 38], [21, 39], [21, 40], [21, 41], [21, 43], [21, 44], [21, 47], [21, 51], [21, 54], [21, 58], [21, 60], [21, 61], [21, 62], [21, 63], [21, 64], [22, 26], [22, 27], [22, 28], [22, 30], [22, 33], [22, 34], [22, 35], [22, 37], [22, 39], [22, 40], [22, 46], [22, 47], [22, 48], [22, 49], [22, 53], [22, 54], [22, 55], [22, 56], [22, 57], [22, 60], [22, 62], [22, 63], [23, 24], [23, 27], [23, 29], [23, 32], [23, 33], [23, 34], [23, 36], [23, 37], [23, 38], [23, 41], [23, 42], [23, 43], [23, 46], [23, 47], [23, 48], [23, 54], [23, 58], [23, 59], [23, 61], [23, 63], [24, 25], [24, 27], [24, 28], [24, 31], [24, 32], [24, 36], [24, 38], [24, 39], [24, 40], [24, 42], [24, 45], [24, 46], [24, 50], [24, 52], [24, 53], [24, 54], [24, 55], [24, 56], [24, 58], [24, 59], [24, 60], [24, 62], [24, 64], [25, 27], [25, 28], [25, 30], [25, 37], [25, 38], [25, 41], [25, 42], [25, 44], [25, 45], [25, 46], [25, 48], [25, 51], [25, 52], [25, 54], [25, 55], [25, 56], [25, 57], [25, 58], [25, 60], [25, 61], [25, 62], [25, 64], [26, 29], [26, 33], [26, 37], [26, 38], [26, 41], [26, 43], [26, 44], [26, 45], [26, 46], [26, 47], [26, 48], [26, 49], [26, 50], [26, 53], [26, 54], [26, 55], [26, 56], [26, 57], [26, 58], [26, 60], [26, 62], [26, 63], [27, 28], [27, 29], [27, 33], [27, 36], [27, 37], [27, 38], [27, 39], [27, 42], [27, 48], [27, 49], [27, 50], [27, 54], [27, 55], [27, 56], [27, 57], [27, 59], [27, 60], [27, 62], [28, 30], [28, 31], [28, 32], [28, 33], [28, 35], [28, 37], [28, 39], [28, 41], [28, 46], [28, 47], [28, 50], [28, 51], [28, 53], [28, 54], [28, 55], [28, 56], [28, 59], [28, 60], [28, 62], [28, 64], [29, 30], [29, 31], [29, 32], [29, 34], [29, 36], [29, 43], [29, 46], [29, 47], [29, 53], [29, 55], [29, 58], [29, 62], [30, 31], [30, 32], [30, 33], [30, 42], [30, 43], [30, 45], [30, 48], [30, 49], [30, 50], [30, 51], [30, 52], [30, 53], [30, 56], [30, 57], [30, 60], [31, 36], [31, 37], [31, 38], [31, 40], [31, 43], [31, 50], [31, 53], [31, 54], [31, 55], [31, 58], [31, 62], [31, 63], [31, 64], [32, 37], [32, 39], [32, 40], [32, 41], [32, 45], [32, 48], [32, 49], [32, 50], [32, 52], [32, 53], [32, 55], [32, 56], [32, 59], [32, 62], [32, 63], [32, 64], [33, 34], [33, 35], [33, 40], [33, 41], [33, 43], [33, 45], [33, 47], [33, 49], [33, 51], [33, 56], [33, 58], [33, 59], [33, 61], [33, 63], [33, 64], [34, 35], [34, 36], [34, 39], [34, 43], [34, 47], [34, 49], [34, 50], [34, 51], [34, 54], [34, 56], [34, 57], [34, 60], [34, 61], [34, 62], [35, 36], [35, 37], [35, 39], [35, 42], [35, 45], [35, 46], [35, 47], [35, 51], [35, 52], [35, 53], [35, 55], [35, 56], [35, 59], [35, 60], [35, 62], [35, 64], [36, 37], [36, 38], [36, 39], [36, 40], [36, 41], [36, 44], [36, 45], [36, 46], [36, 47], [36, 48], [36, 50], [36, 52], [36, 53], [36, 54], [36, 56], [36, 58], [36, 59], [36, 60], [36, 63], [37, 38], [37, 41], [37, 42], [37, 43], [37, 45], [37, 51], [37, 53], [37, 56], [37, 57], [37, 58], [37, 60], [37, 63], [37, 64], [38, 39], [38, 42], [38, 43], [38, 47], [38, 48], [38, 50], [38, 52], [38, 55], [38, 56], [38, 57], [38, 58], [38, 59], [38, 62], [39, 40], [39, 41], [39, 42], [39, 43], [39, 45], [39, 50], [39, 51], [39, 52], [39, 54], [39, 55], [39, 56], [39, 59], [39, 60], [39, 61], [39, 62], [39, 64], [40, 42], [40, 45], [40, 53], [40, 55], [40, 56], [40, 57], [40, 59], [40, 60], [40, 62], [40, 63], [41, 43], [41, 44], [41, 45], [41, 47], [41, 51], [41, 53], [41, 55], [41, 57], [41, 58], [41, 59], [41, 60], [41, 62], [41, 63], [42, 44], [42, 47], [42, 49], [42, 50], [42, 51], [42, 54], [42, 58], [42, 60], [42, 62], [43, 45], [43, 48], [43, 49], [43, 50], [43, 51], [43, 53], [43, 54], [43, 55], [43, 56], [43, 60], [43, 62], [43, 63], [43, 64], [44, 46], [44, 48], [44, 49], [44, 50], [44, 51], [44, 53], [44, 56], [44, 58], [44, 59], [44, 60], [44, 61], [44, 62], [44, 64], [45, 49], [45, 50], [45, 51], [45, 52], [45, 53], [45, 54], [45, 56], [45, 57], [45, 59], [45, 63], [46, 47], [46, 50], [46, 51], [46, 53], [46, 57], [46, 58], [46, 59], [46, 60], [46, 62], [46, 63], [46, 64], [47, 51], [47, 52], [47, 53], [47, 56], [47, 57], [47, 64], [48, 49], [48, 50], [48, 51], [48, 52], [48, 53], [48, 54], [48, 55], [48, 56], [48, 59], [48, 62], [48, 63], [48, 64], [49, 50], [49, 51], [49, 55], [49, 57], [49, 58], [49, 59], [49, 61], [49, 63], [49, 64], [50, 51], [50, 57], [50, 60], [50, 61], [50, 63], [50, 64], [51, 52], [51, 54], [51, 57], [51, 59], [51, 62], [51, 64], [52, 54], [52, 59], [52, 61], [53, 54], [53, 55], [53, 56], [53, 57], [53, 58], [53, 61], [53, 63], [53, 64], [54, 57], [54, 60], [55, 56], [55, 58], [55, 60], [55, 62], [56, 60], [56, 61], [56, 62], [57, 60], [57, 62], [57, 64], [58, 63], [59, 60], [59, 61], [59, 62], [59, 63], [59, 64], [60, 62], [61, 62], [61, 63], [63, 64]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l4-s4/solution/solve.sh b/tasks/construct-mc-max-clique-l4-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5baae2c727988872de3827055efd45bd86b7ea00 --- /dev/null +++ b/tasks/construct-mc-max-clique-l4-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": [3, 11, 26, 43, 48, 53, 54]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-clique-l4-s4/tests/check.py b/tasks/construct-mc-max-clique-l4-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3f70dbd5b155a3514c2102aa4ad460201495210 --- /dev/null +++ b/tasks/construct-mc-max-clique-l4-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-l4-s4/tests/instance.json b/tasks/construct-mc-max-clique-l4-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9a63cf58dfbd3d7abb1c2d778cceedd7991bb8b0 --- /dev/null +++ b/tasks/construct-mc-max-clique-l4-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 65, "k": 7, "edges": [[0, 1], [0, 2], [0, 5], [0, 7], [0, 12], [0, 13], [0, 16], [0, 19], [0, 23], [0, 24], [0, 26], [0, 28], [0, 29], [0, 30], [0, 32], [0, 33], [0, 34], [0, 36], [0, 37], [0, 39], [0, 40], [0, 42], [0, 43], [0, 44], [0, 45], [0, 47], [0, 48], [0, 49], [0, 50], [0, 53], [0, 54], [0, 55], [0, 56], [0, 57], [0, 58], [0, 60], [0, 62], [0, 63], [1, 5], [1, 8], [1, 9], [1, 11], [1, 13], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 20], [1, 23], [1, 25], [1, 26], [1, 28], [1, 32], [1, 38], [1, 41], [1, 48], [1, 51], [1, 52], [1, 53], [1, 54], [1, 58], [1, 59], [1, 60], [1, 62], [1, 63], [2, 3], [2, 4], [2, 6], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 17], [2, 19], [2, 22], [2, 25], [2, 26], [2, 29], [2, 30], [2, 31], [2, 33], [2, 34], [2, 38], [2, 41], [2, 46], [2, 48], [2, 50], [2, 51], [2, 52], [2, 54], [2, 55], [2, 56], [2, 57], [2, 59], [2, 61], [2, 64], [3, 5], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 14], [3, 15], [3, 17], [3, 18], [3, 19], [3, 20], [3, 21], [3, 22], [3, 23], [3, 24], [3, 25], [3, 26], [3, 30], [3, 32], [3, 34], [3, 35], [3, 36], [3, 42], [3, 43], [3, 45], [3, 47], [3, 48], [3, 50], [3, 51], [3, 52], [3, 53], [3, 54], [3, 57], [3, 59], [3, 60], [3, 62], [4, 9], [4, 10], [4, 11], [4, 12], [4, 13], [4, 14], [4, 16], [4, 17], [4, 18], [4, 20], [4, 21], [4, 22], [4, 27], [4, 28], [4, 30], [4, 31], [4, 32], [4, 34], [4, 38], [4, 40], [4, 41], [4, 43], [4, 44], [4, 45], [4, 47], [4, 48], [4, 50], [4, 55], [4, 56], [4, 57], [4, 58], [4, 59], [4, 61], [4, 64], [5, 7], [5, 11], [5, 13], [5, 14], [5, 18], [5, 22], [5, 24], [5, 25], [5, 26], [5, 27], [5, 30], [5, 31], [5, 33], [5, 36], [5, 37], [5, 38], [5, 39], [5, 40], [5, 41], [5, 42], [5, 43], [5, 44], [5, 45], [5, 47], [5, 48], [5, 49], [5, 54], [5, 55], [5, 57], [5, 58], [5, 60], [5, 61], [6, 7], [6, 9], [6, 12], [6, 13], [6, 14], [6, 15], [6, 16], [6, 17], [6, 19], [6, 20], [6, 22], [6, 26], [6, 27], [6, 28], [6, 30], [6, 31], [6, 32], [6, 33], [6, 35], [6, 36], [6, 39], [6, 40], [6, 42], [6, 49], [6, 50], [6, 54], [6, 55], [6, 56], [6, 57], [6, 58], [6, 59], [6, 61], [6, 62], [6, 64], [7, 9], [7, 11], [7, 12], [7, 13], [7, 15], [7, 16], [7, 17], [7, 20], [7, 26], [7, 27], [7, 29], [7, 30], [7, 31], [7, 32], [7, 33], [7, 34], [7, 35], [7, 37], [7, 38], [7, 39], [7, 41], [7, 43], [7, 45], [7, 47], [7, 48], [7, 49], [7, 53], [7, 59], [7, 61], [7, 62], [7, 64], [8, 9], [8, 11], [8, 13], [8, 14], [8, 17], [8, 18], [8, 19], [8, 20], [8, 21], [8, 22], [8, 24], [8, 26], [8, 28], [8, 31], [8, 32], [8, 35], [8, 41], [8, 45], [8, 46], [8, 48], [8, 49], [8, 50], [8, 51], [8, 52], [8, 53], [8, 55], [8, 56], [8, 57], [8, 59], [8, 63], [9, 15], [9, 16], [9, 17], [9, 18], [9, 21], [9, 22], [9, 23], [9, 24], [9, 28], [9, 29], [9, 30], [9, 33], [9, 34], [9, 37], [9, 38], [9, 39], [9, 41], [9, 42], [9, 43], [9, 46], [9, 49], [9, 51], [9, 52], [9, 54], [9, 55], [9, 56], [9, 59], [9, 60], [9, 62], [9, 63], [9, 64], [10, 15], [10, 22], [10, 24], [10, 25], [10, 26], [10, 28], [10, 29], [10, 30], [10, 31], [10, 33], [10, 37], [10, 41], [10, 42], [10, 43], [10, 44], [10, 48], [10, 49], [10, 50], [10, 51], [10, 52], [10, 54], [10, 56], [10, 59], [10, 62], [11, 12], [11, 14], [11, 15], [11, 16], [11, 17], [11, 19], [11, 24], [11, 25], [11, 26], [11, 27], [11, 29], [11, 30], [11, 36], [11, 39], [11, 40], [11, 41], [11, 42], [11, 43], [11, 46], [11, 47], [11, 48], [11, 49], [11, 52], [11, 53], [11, 54], [11, 57], [11, 58], [11, 59], [11, 60], [11, 61], [11, 62], [11, 64], [12, 14], [12, 15], [12, 19], [12, 21], [12, 22], [12, 23], [12, 24], [12, 27], [12, 29], [12, 31], [12, 33], [12, 36], [12, 37], [12, 38], [12, 42], [12, 44], [12, 45], [12, 46], [12, 48], [12, 49], [12, 50], [12, 51], [12, 52], [12, 53], [12, 56], [12, 57], [12, 58], [12, 59], [12, 60], [12, 61], [12, 62], [12, 63], [13, 14], [13, 18], [13, 19], [13, 21], [13, 22], [13, 23], [13, 24], [13, 26], [13, 29], [13, 30], [13, 32], [13, 33], [13, 34], [13, 36], [13, 37], [13, 40], [13, 42], [13, 44], [13, 45], [13, 46], [13, 49], [13, 50], [13, 51], [13, 52], [13, 53], [13, 54], [13, 56], [13, 57], [13, 58], [13, 59], [13, 60], [13, 61], [13, 63], [14, 17], [14, 18], [14, 19], [14, 22], [14, 24], [14, 27], [14, 28], [14, 30], [14, 32], [14, 33], [14, 34], [14, 36], [14, 40], [14, 42], [14, 47], [14, 49], [14, 50], [14, 55], [14, 58], [14, 60], [14, 61], [15, 16], [15, 18], [15, 19], [15, 22], [15, 25], [15, 28], [15, 29], [15, 33], [15, 34], [15, 35], [15, 36], [15, 37], [15, 38], [15, 41], [15, 46], [15, 48], [15, 49], [15, 50], [15, 52], [15, 53], [15, 57], [15, 58], [15, 59], [15, 60], [15, 64], [16, 17], [16, 18], [16, 20], [16, 22], [16, 24], [16, 25], [16, 27], [16, 29], [16, 30], [16, 31], [16, 32], [16, 33], [16, 34], [16, 35], [16, 36], [16, 39], [16, 42], [16, 43], [16, 46], [16, 47], [16, 49], [16, 50], [16, 51], [16, 53], [16, 55], [16, 56], [16, 57], [16, 62], [17, 18], [17, 20], [17, 21], [17, 26], [17, 27], [17, 30], [17, 32], [17, 33], [17, 36], [17, 37], [17, 40], [17, 41], [17, 45], [17, 47], [17, 48], [17, 52], [17, 57], [17, 60], [17, 63], [18, 19], [18, 20], [18, 23], [18, 24], [18, 26], [18, 27], [18, 28], [18, 29], [18, 30], [18, 31], [18, 32], [18, 35], [18, 36], [18, 40], [18, 41], [18, 42], [18, 43], [18, 45], [18, 46], [18, 47], [18, 48], [18, 49], [18, 50], [18, 51], [18, 58], [18, 59], [18, 60], [18, 62], [18, 64], [19, 21], [19, 22], [19, 28], [19, 29], [19, 31], [19, 32], [19, 34], [19, 35], [19, 37], [19, 40], [19, 44], [19, 45], [19, 46], [19, 47], [19, 52], [19, 54], [19, 56], [19, 58], [19, 61], [19, 62], [19, 63], [19, 64], [20, 21], [20, 22], [20, 23], [20, 24], [20, 25], [20, 26], [20, 27], [20, 28], [20, 29], [20, 30], [20, 31], [20, 32], [20, 33], [20, 35], [20, 36], [20, 37], [20, 42], [20, 43], [20, 46], [20, 49], [20, 53], [20, 54], [20, 57], [20, 61], [20, 62], [20, 63], [21, 27], [21, 28], [21, 29], [21, 30], [21, 33], [21, 36], [21, 38], [21, 39], [21, 40], [21, 41], [21, 43], [21, 44], [21, 47], [21, 51], [21, 54], [21, 58], [21, 60], [21, 61], [21, 62], [21, 63], [21, 64], [22, 26], [22, 27], [22, 28], [22, 30], [22, 33], [22, 34], [22, 35], [22, 37], [22, 39], [22, 40], [22, 46], [22, 47], [22, 48], [22, 49], [22, 53], [22, 54], [22, 55], [22, 56], [22, 57], [22, 60], [22, 62], [22, 63], [23, 24], [23, 27], [23, 29], [23, 32], [23, 33], [23, 34], [23, 36], [23, 37], [23, 38], [23, 41], [23, 42], [23, 43], [23, 46], [23, 47], [23, 48], [23, 54], [23, 58], [23, 59], [23, 61], [23, 63], [24, 25], [24, 27], [24, 28], [24, 31], [24, 32], [24, 36], [24, 38], [24, 39], [24, 40], [24, 42], [24, 45], [24, 46], [24, 50], [24, 52], [24, 53], [24, 54], [24, 55], [24, 56], [24, 58], [24, 59], [24, 60], [24, 62], [24, 64], [25, 27], [25, 28], [25, 30], [25, 37], [25, 38], [25, 41], [25, 42], [25, 44], [25, 45], [25, 46], [25, 48], [25, 51], [25, 52], [25, 54], [25, 55], [25, 56], [25, 57], [25, 58], [25, 60], [25, 61], [25, 62], [25, 64], [26, 29], [26, 33], [26, 37], [26, 38], [26, 41], [26, 43], [26, 44], [26, 45], [26, 46], [26, 47], [26, 48], [26, 49], [26, 50], [26, 53], [26, 54], [26, 55], [26, 56], [26, 57], [26, 58], [26, 60], [26, 62], [26, 63], [27, 28], [27, 29], [27, 33], [27, 36], [27, 37], [27, 38], [27, 39], [27, 42], [27, 48], [27, 49], [27, 50], [27, 54], [27, 55], [27, 56], [27, 57], [27, 59], [27, 60], [27, 62], [28, 30], [28, 31], [28, 32], [28, 33], [28, 35], [28, 37], [28, 39], [28, 41], [28, 46], [28, 47], [28, 50], [28, 51], [28, 53], [28, 54], [28, 55], [28, 56], [28, 59], [28, 60], [28, 62], [28, 64], [29, 30], [29, 31], [29, 32], [29, 34], [29, 36], [29, 43], [29, 46], [29, 47], [29, 53], [29, 55], [29, 58], [29, 62], [30, 31], [30, 32], [30, 33], [30, 42], [30, 43], [30, 45], [30, 48], [30, 49], [30, 50], [30, 51], [30, 52], [30, 53], [30, 56], [30, 57], [30, 60], [31, 36], [31, 37], [31, 38], [31, 40], [31, 43], [31, 50], [31, 53], [31, 54], [31, 55], [31, 58], [31, 62], [31, 63], [31, 64], [32, 37], [32, 39], [32, 40], [32, 41], [32, 45], [32, 48], [32, 49], [32, 50], [32, 52], [32, 53], [32, 55], [32, 56], [32, 59], [32, 62], [32, 63], [32, 64], [33, 34], [33, 35], [33, 40], [33, 41], [33, 43], [33, 45], [33, 47], [33, 49], [33, 51], [33, 56], [33, 58], [33, 59], [33, 61], [33, 63], [33, 64], [34, 35], [34, 36], [34, 39], [34, 43], [34, 47], [34, 49], [34, 50], [34, 51], [34, 54], [34, 56], [34, 57], [34, 60], [34, 61], [34, 62], [35, 36], [35, 37], [35, 39], [35, 42], [35, 45], [35, 46], [35, 47], [35, 51], [35, 52], [35, 53], [35, 55], [35, 56], [35, 59], [35, 60], [35, 62], [35, 64], [36, 37], [36, 38], [36, 39], [36, 40], [36, 41], [36, 44], [36, 45], [36, 46], [36, 47], [36, 48], [36, 50], [36, 52], [36, 53], [36, 54], [36, 56], [36, 58], [36, 59], [36, 60], [36, 63], [37, 38], [37, 41], [37, 42], [37, 43], [37, 45], [37, 51], [37, 53], [37, 56], [37, 57], [37, 58], [37, 60], [37, 63], [37, 64], [38, 39], [38, 42], [38, 43], [38, 47], [38, 48], [38, 50], [38, 52], [38, 55], [38, 56], [38, 57], [38, 58], [38, 59], [38, 62], [39, 40], [39, 41], [39, 42], [39, 43], [39, 45], [39, 50], [39, 51], [39, 52], [39, 54], [39, 55], [39, 56], [39, 59], [39, 60], [39, 61], [39, 62], [39, 64], [40, 42], [40, 45], [40, 53], [40, 55], [40, 56], [40, 57], [40, 59], [40, 60], [40, 62], [40, 63], [41, 43], [41, 44], [41, 45], [41, 47], [41, 51], [41, 53], [41, 55], [41, 57], [41, 58], [41, 59], [41, 60], [41, 62], [41, 63], [42, 44], [42, 47], [42, 49], [42, 50], [42, 51], [42, 54], [42, 58], [42, 60], [42, 62], [43, 45], [43, 48], [43, 49], [43, 50], [43, 51], [43, 53], [43, 54], [43, 55], [43, 56], [43, 60], [43, 62], [43, 63], [43, 64], [44, 46], [44, 48], [44, 49], [44, 50], [44, 51], [44, 53], [44, 56], [44, 58], [44, 59], [44, 60], [44, 61], [44, 62], [44, 64], [45, 49], [45, 50], [45, 51], [45, 52], [45, 53], [45, 54], [45, 56], [45, 57], [45, 59], [45, 63], [46, 47], [46, 50], [46, 51], [46, 53], [46, 57], [46, 58], [46, 59], [46, 60], [46, 62], [46, 63], [46, 64], [47, 51], [47, 52], [47, 53], [47, 56], [47, 57], [47, 64], [48, 49], [48, 50], [48, 51], [48, 52], [48, 53], [48, 54], [48, 55], [48, 56], [48, 59], [48, 62], [48, 63], [48, 64], [49, 50], [49, 51], [49, 55], [49, 57], [49, 58], [49, 59], [49, 61], [49, 63], [49, 64], [50, 51], [50, 57], [50, 60], [50, 61], [50, 63], [50, 64], [51, 52], [51, 54], [51, 57], [51, 59], [51, 62], [51, 64], [52, 54], [52, 59], [52, 61], [53, 54], [53, 55], [53, 56], [53, 57], [53, 58], [53, 61], [53, 63], [53, 64], [54, 57], [54, 60], [55, 56], [55, 58], [55, 60], [55, 62], [56, 60], [56, 61], [56, 62], [57, 60], [57, 62], [57, 64], [58, 63], [59, 60], [59, 61], [59, 62], [59, 63], [59, 64], [60, 62], [61, 62], [61, 63], [63, 64]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l4-s4/tests/run.py b/tasks/construct-mc-max-clique-l4-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-clique-l4-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-l4-s4/tests/test.sh b/tasks/construct-mc-max-clique-l4-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-clique-l4-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-independent-set-l3-s0/environment/Dockerfile b/tasks/construct-mc-max-independent-set-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-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-max-independent-set-l3-s0/environment/instance.json b/tasks/construct-mc-max-independent-set-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e8ef42a7720f5f6a947393e974405caf73271c2b --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 55, "k": 13, "edges": [[0, 3], [0, 7], [0, 8], [0, 14], [0, 16], [0, 17], [0, 18], [0, 20], [0, 21], [0, 22], [0, 23], [0, 28], [0, 32], [0, 33], [0, 34], [0, 42], [0, 48], [0, 50], [0, 54], [1, 4], [1, 8], [1, 9], [1, 11], [1, 14], [1, 18], [1, 20], [1, 34], [1, 46], [1, 50], [1, 52], [2, 5], [2, 7], [2, 12], [2, 14], [2, 20], [2, 22], [2, 25], [2, 26], [2, 27], [2, 33], [2, 37], [2, 40], [2, 49], [2, 52], [2, 53], [3, 6], [3, 7], [3, 9], [3, 18], [3, 20], [3, 21], [3, 25], [3, 27], [3, 29], [3, 30], [3, 37], [3, 38], [3, 42], [3, 47], [3, 50], [3, 52], [3, 54], [4, 5], [4, 6], [4, 12], [4, 16], [4, 24], [4, 27], [4, 30], [4, 33], [4, 34], [4, 35], [4, 44], [4, 45], [4, 47], [5, 6], [5, 9], [5, 10], [5, 11], [5, 12], [5, 15], [5, 18], [5, 20], [5, 21], [5, 23], [5, 24], [5, 29], [5, 36], [5, 37], [5, 41], [5, 42], [5, 52], [5, 53], [6, 8], [6, 11], [6, 12], [6, 15], [6, 22], [6, 27], [6, 28], [6, 30], [6, 41], [6, 45], [6, 47], [6, 48], [6, 50], [6, 51], [6, 52], [7, 8], [7, 9], [7, 11], [7, 15], [7, 17], [7, 23], [7, 25], [7, 30], [7, 42], [7, 46], [7, 50], [7, 51], [7, 52], [8, 9], [8, 13], [8, 17], [8, 21], [8, 22], [8, 26], [8, 33], [8, 34], [8, 35], [8, 37], [8, 38], [8, 40], [8, 42], [8, 44], [8, 50], [8, 53], [9, 15], [9, 20], [9, 25], [9, 26], [9, 28], [9, 39], [9, 42], [9, 54], [10, 11], [10, 18], [10, 23], [10, 27], [10, 29], [10, 33], [10, 37], [10, 46], [10, 48], [10, 49], [10, 51], [10, 53], [11, 14], [11, 16], [11, 20], [11, 23], [11, 24], [11, 26], [11, 29], [11, 31], [11, 39], [11, 42], [11, 45], [11, 46], [11, 47], [11, 48], [11, 50], [11, 51], [11, 52], [12, 13], [12, 14], [12, 16], [12, 18], [12, 21], [12, 27], [12, 31], [12, 35], [12, 42], [12, 43], [12, 46], [12, 49], [12, 54], [13, 15], [13, 21], [13, 25], [13, 28], [13, 29], [13, 30], [13, 37], [13, 39], [13, 42], [13, 49], [13, 51], [14, 22], [14, 32], [14, 35], [14, 40], [14, 41], [14, 42], [14, 46], [14, 49], [15, 16], [15, 22], [15, 25], [15, 26], [15, 27], [15, 31], [15, 35], [15, 44], [15, 48], [15, 49], [15, 54], [16, 17], [16, 18], [16, 20], [16, 22], [16, 28], [16, 30], [16, 38], [16, 41], [16, 45], [16, 47], [16, 49], [16, 53], [16, 54], [17, 24], [17, 26], [17, 28], [17, 38], [17, 42], [17, 44], [17, 45], [17, 49], [17, 52], [17, 54], [18, 23], [18, 28], [18, 29], [18, 30], [18, 31], [18, 33], [18, 35], [18, 36], [18, 44], [18, 46], [18, 47], [18, 51], [19, 20], [19, 22], [19, 28], [19, 32], [19, 36], [19, 45], [19, 48], [19, 51], [20, 21], [20, 24], [20, 25], [20, 26], [20, 32], [20, 34], [20, 40], [20, 41], [20, 43], [20, 45], [20, 46], [21, 29], [21, 30], [21, 31], [21, 33], [21, 36], [21, 38], [21, 44], [21, 45], [21, 47], [21, 50], [21, 52], [22, 24], [22, 26], [22, 36], [22, 37], [22, 38], [22, 44], [22, 47], [22, 50], [22, 53], [22, 54], [23, 27], [23, 28], [23, 30], [23, 31], [23, 39], [23, 40], [23, 49], [23, 54], [24, 27], [24, 30], [24, 33], [24, 46], [24, 49], [25, 30], [25, 32], [25, 36], [25, 38], [25, 48], [25, 50], [25, 52], [26, 27], [26, 35], [26, 36], [26, 38], [26, 39], [26, 42], [26, 44], [26, 45], [26, 46], [26, 49], [27, 28], [27, 31], [27, 35], [27, 38], [27, 40], [27, 44], [27, 45], [27, 50], [27, 52], [28, 29], [28, 30], [28, 31], [28, 33], [28, 34], [28, 42], [28, 43], [28, 44], [28, 46], [28, 51], [28, 52], [29, 40], [29, 41], [29, 43], [29, 44], [29, 45], [29, 52], [29, 53], [30, 31], [30, 34], [30, 38], [30, 39], [30, 44], [30, 46], [30, 48], [30, 50], [30, 54], [31, 32], [31, 34], [31, 38], [31, 39], [31, 41], [31, 42], [31, 44], [31, 49], [32, 41], [32, 43], [32, 46], [32, 48], [32, 51], [33, 34], [33, 40], [33, 42], [33, 43], [33, 44], [33, 46], [33, 48], [33, 52], [33, 53], [34, 44], [34, 46], [34, 48], [34, 52], [35, 36], [35, 37], [35, 38], [35, 39], [35, 41], [35, 43], [35, 46], [35, 53], [35, 54], [36, 41], [36, 44], [36, 45], [36, 46], [36, 47], [36, 48], [36, 50], [36, 51], [36, 54], [37, 38], [37, 39], [37, 41], [37, 49], [37, 52], [38, 40], [38, 50], [38, 54], [39, 44], [39, 48], [39, 49], [39, 52], [39, 54], [40, 43], [40, 44], [40, 45], [40, 50], [40, 51], [40, 54], [41, 46], [42, 43], [42, 51], [42, 52], [43, 48], [43, 49], [43, 51], [43, 52], [44, 46], [45, 54], [46, 50], [46, 52], [46, 54], [47, 51], [48, 53], [48, 54], [49, 50], [49, 53], [49, 54], [51, 54]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l3-s0/solution/solve.sh b/tasks/construct-mc-max-independent-set-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4773178bf5f6b75af466ea6c2378ace4c8526588 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-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' +{"independent_set": [6, 7, 14, 18, 19, 21, 24, 26, 34, 37, 43, 53, 54]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-independent-set-l3-s0/tests/check.py b/tasks/construct-mc-max-independent-set-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..adce413e8578d996549583b990e4ff559f38ed41 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l3-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-l3-s0/tests/instance.json b/tasks/construct-mc-max-independent-set-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e8ef42a7720f5f6a947393e974405caf73271c2b --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 55, "k": 13, "edges": [[0, 3], [0, 7], [0, 8], [0, 14], [0, 16], [0, 17], [0, 18], [0, 20], [0, 21], [0, 22], [0, 23], [0, 28], [0, 32], [0, 33], [0, 34], [0, 42], [0, 48], [0, 50], [0, 54], [1, 4], [1, 8], [1, 9], [1, 11], [1, 14], [1, 18], [1, 20], [1, 34], [1, 46], [1, 50], [1, 52], [2, 5], [2, 7], [2, 12], [2, 14], [2, 20], [2, 22], [2, 25], [2, 26], [2, 27], [2, 33], [2, 37], [2, 40], [2, 49], [2, 52], [2, 53], [3, 6], [3, 7], [3, 9], [3, 18], [3, 20], [3, 21], [3, 25], [3, 27], [3, 29], [3, 30], [3, 37], [3, 38], [3, 42], [3, 47], [3, 50], [3, 52], [3, 54], [4, 5], [4, 6], [4, 12], [4, 16], [4, 24], [4, 27], [4, 30], [4, 33], [4, 34], [4, 35], [4, 44], [4, 45], [4, 47], [5, 6], [5, 9], [5, 10], [5, 11], [5, 12], [5, 15], [5, 18], [5, 20], [5, 21], [5, 23], [5, 24], [5, 29], [5, 36], [5, 37], [5, 41], [5, 42], [5, 52], [5, 53], [6, 8], [6, 11], [6, 12], [6, 15], [6, 22], [6, 27], [6, 28], [6, 30], [6, 41], [6, 45], [6, 47], [6, 48], [6, 50], [6, 51], [6, 52], [7, 8], [7, 9], [7, 11], [7, 15], [7, 17], [7, 23], [7, 25], [7, 30], [7, 42], [7, 46], [7, 50], [7, 51], [7, 52], [8, 9], [8, 13], [8, 17], [8, 21], [8, 22], [8, 26], [8, 33], [8, 34], [8, 35], [8, 37], [8, 38], [8, 40], [8, 42], [8, 44], [8, 50], [8, 53], [9, 15], [9, 20], [9, 25], [9, 26], [9, 28], [9, 39], [9, 42], [9, 54], [10, 11], [10, 18], [10, 23], [10, 27], [10, 29], [10, 33], [10, 37], [10, 46], [10, 48], [10, 49], [10, 51], [10, 53], [11, 14], [11, 16], [11, 20], [11, 23], [11, 24], [11, 26], [11, 29], [11, 31], [11, 39], [11, 42], [11, 45], [11, 46], [11, 47], [11, 48], [11, 50], [11, 51], [11, 52], [12, 13], [12, 14], [12, 16], [12, 18], [12, 21], [12, 27], [12, 31], [12, 35], [12, 42], [12, 43], [12, 46], [12, 49], [12, 54], [13, 15], [13, 21], [13, 25], [13, 28], [13, 29], [13, 30], [13, 37], [13, 39], [13, 42], [13, 49], [13, 51], [14, 22], [14, 32], [14, 35], [14, 40], [14, 41], [14, 42], [14, 46], [14, 49], [15, 16], [15, 22], [15, 25], [15, 26], [15, 27], [15, 31], [15, 35], [15, 44], [15, 48], [15, 49], [15, 54], [16, 17], [16, 18], [16, 20], [16, 22], [16, 28], [16, 30], [16, 38], [16, 41], [16, 45], [16, 47], [16, 49], [16, 53], [16, 54], [17, 24], [17, 26], [17, 28], [17, 38], [17, 42], [17, 44], [17, 45], [17, 49], [17, 52], [17, 54], [18, 23], [18, 28], [18, 29], [18, 30], [18, 31], [18, 33], [18, 35], [18, 36], [18, 44], [18, 46], [18, 47], [18, 51], [19, 20], [19, 22], [19, 28], [19, 32], [19, 36], [19, 45], [19, 48], [19, 51], [20, 21], [20, 24], [20, 25], [20, 26], [20, 32], [20, 34], [20, 40], [20, 41], [20, 43], [20, 45], [20, 46], [21, 29], [21, 30], [21, 31], [21, 33], [21, 36], [21, 38], [21, 44], [21, 45], [21, 47], [21, 50], [21, 52], [22, 24], [22, 26], [22, 36], [22, 37], [22, 38], [22, 44], [22, 47], [22, 50], [22, 53], [22, 54], [23, 27], [23, 28], [23, 30], [23, 31], [23, 39], [23, 40], [23, 49], [23, 54], [24, 27], [24, 30], [24, 33], [24, 46], [24, 49], [25, 30], [25, 32], [25, 36], [25, 38], [25, 48], [25, 50], [25, 52], [26, 27], [26, 35], [26, 36], [26, 38], [26, 39], [26, 42], [26, 44], [26, 45], [26, 46], [26, 49], [27, 28], [27, 31], [27, 35], [27, 38], [27, 40], [27, 44], [27, 45], [27, 50], [27, 52], [28, 29], [28, 30], [28, 31], [28, 33], [28, 34], [28, 42], [28, 43], [28, 44], [28, 46], [28, 51], [28, 52], [29, 40], [29, 41], [29, 43], [29, 44], [29, 45], [29, 52], [29, 53], [30, 31], [30, 34], [30, 38], [30, 39], [30, 44], [30, 46], [30, 48], [30, 50], [30, 54], [31, 32], [31, 34], [31, 38], [31, 39], [31, 41], [31, 42], [31, 44], [31, 49], [32, 41], [32, 43], [32, 46], [32, 48], [32, 51], [33, 34], [33, 40], [33, 42], [33, 43], [33, 44], [33, 46], [33, 48], [33, 52], [33, 53], [34, 44], [34, 46], [34, 48], [34, 52], [35, 36], [35, 37], [35, 38], [35, 39], [35, 41], [35, 43], [35, 46], [35, 53], [35, 54], [36, 41], [36, 44], [36, 45], [36, 46], [36, 47], [36, 48], [36, 50], [36, 51], [36, 54], [37, 38], [37, 39], [37, 41], [37, 49], [37, 52], [38, 40], [38, 50], [38, 54], [39, 44], [39, 48], [39, 49], [39, 52], [39, 54], [40, 43], [40, 44], [40, 45], [40, 50], [40, 51], [40, 54], [41, 46], [42, 43], [42, 51], [42, 52], [43, 48], [43, 49], [43, 51], [43, 52], [44, 46], [45, 54], [46, 50], [46, 52], [46, 54], [47, 51], [48, 53], [48, 54], [49, 50], [49, 53], [49, 54], [51, 54]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l3-s0/tests/run.py b/tasks/construct-mc-max-independent-set-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-independent-set-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-max-independent-set-l3-s0/tests/test.sh b/tasks/construct-mc-max-independent-set-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-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-max-independent-set-l3-s7/environment/Dockerfile b/tasks/construct-mc-max-independent-set-l3-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-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-mc-max-independent-set-l3-s7/environment/instance.json b/tasks/construct-mc-max-independent-set-l3-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6cfcb5e1c36fc435d6dcac7cb953c3b67f01e9fe --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l3-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 45, "k": 11, "edges": [[0, 3], [0, 4], [0, 5], [0, 9], [0, 10], [0, 14], [0, 15], [0, 17], [0, 18], [0, 23], [0, 27], [0, 28], [0, 32], [0, 39], [1, 5], [1, 6], [1, 8], [1, 9], [1, 14], [1, 15], [1, 19], [1, 20], [1, 27], [1, 35], [1, 39], [1, 40], [1, 41], [2, 4], [2, 10], [2, 11], [2, 17], [2, 18], [2, 20], [2, 21], [2, 24], [2, 29], [2, 32], [2, 33], [2, 41], [3, 7], [3, 11], [3, 12], [3, 14], [3, 22], [3, 25], [3, 32], [3, 33], [3, 34], [3, 37], [3, 39], [4, 7], [4, 12], [4, 14], [4, 18], [4, 19], [4, 30], [4, 41], [4, 44], [5, 10], [5, 13], [5, 14], [5, 22], [5, 29], [5, 35], [5, 43], [6, 10], [6, 15], [6, 17], [6, 25], [6, 27], [6, 44], [7, 10], [7, 12], [7, 18], [7, 21], [7, 23], [7, 31], [7, 32], [7, 34], [7, 36], [7, 37], [7, 38], [7, 39], [8, 12], [8, 14], [8, 21], [8, 22], [8, 24], [8, 37], [8, 40], [8, 41], [8, 42], [9, 12], [9, 15], [9, 27], [9, 29], [9, 38], [10, 12], [10, 17], [10, 18], [10, 23], [10, 25], [10, 26], [10, 27], [10, 30], [10, 37], [10, 40], [10, 42], [10, 43], [11, 12], [11, 15], [11, 17], [11, 20], [11, 22], [11, 30], [11, 34], [11, 36], [11, 37], [11, 38], [11, 44], [12, 14], [12, 19], [12, 21], [12, 22], [13, 14], [13, 27], [13, 37], [13, 40], [13, 42], [14, 15], [14, 17], [14, 20], [14, 23], [14, 27], [15, 18], [15, 19], [15, 20], [15, 24], [15, 27], [15, 34], [15, 35], [15, 37], [15, 42], [16, 20], [16, 31], [16, 35], [16, 42], [16, 44], [17, 20], [17, 25], [17, 28], [17, 31], [17, 33], [17, 44], [18, 19], [18, 25], [18, 27], [18, 31], [18, 32], [18, 34], [19, 21], [19, 24], [19, 27], [19, 30], [19, 32], [19, 36], [19, 43], [19, 44], [20, 22], [20, 24], [20, 25], [20, 30], [20, 34], [20, 38], [20, 39], [20, 42], [21, 25], [21, 31], [21, 33], [21, 39], [21, 42], [22, 26], [22, 29], [22, 30], [22, 32], [22, 33], [22, 34], [22, 36], [22, 37], [22, 40], [22, 44], [23, 24], [23, 25], [23, 28], [23, 29], [23, 35], [23, 42], [23, 44], [24, 26], [24, 29], [24, 32], [24, 33], [24, 36], [24, 40], [24, 42], [24, 44], [25, 27], [25, 32], [25, 37], [25, 40], [25, 41], [25, 43], [26, 30], [26, 42], [26, 43], [26, 44], [27, 28], [27, 37], [27, 40], [27, 42], [27, 43], [27, 44], [28, 29], [28, 30], [28, 31], [28, 36], [28, 37], [28, 40], [28, 43], [29, 32], [29, 34], [29, 36], [29, 39], [29, 41], [29, 44], [30, 32], [30, 33], [30, 39], [30, 44], [31, 32], [31, 35], [31, 37], [31, 41], [31, 43], [31, 44], [32, 33], [32, 38], [33, 34], [33, 43], [33, 44], [34, 35], [34, 36], [35, 36], [35, 37], [35, 40], [35, 43], [36, 41], [37, 38], [37, 40], [37, 41], [38, 44], [39, 40], [39, 42], [39, 43], [40, 41], [40, 44]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l3-s7/solution/solve.sh b/tasks/construct-mc-max-independent-set-l3-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..86dc6334b60772f2be8d56452c829bb84e641445 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-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' +{"independent_set": [4, 5, 6, 8, 9, 16, 26, 28, 32, 34, 39]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-independent-set-l3-s7/tests/check.py b/tasks/construct-mc-max-independent-set-l3-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..adce413e8578d996549583b990e4ff559f38ed41 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l3-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-l3-s7/tests/instance.json b/tasks/construct-mc-max-independent-set-l3-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6cfcb5e1c36fc435d6dcac7cb953c3b67f01e9fe --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l3-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 45, "k": 11, "edges": [[0, 3], [0, 4], [0, 5], [0, 9], [0, 10], [0, 14], [0, 15], [0, 17], [0, 18], [0, 23], [0, 27], [0, 28], [0, 32], [0, 39], [1, 5], [1, 6], [1, 8], [1, 9], [1, 14], [1, 15], [1, 19], [1, 20], [1, 27], [1, 35], [1, 39], [1, 40], [1, 41], [2, 4], [2, 10], [2, 11], [2, 17], [2, 18], [2, 20], [2, 21], [2, 24], [2, 29], [2, 32], [2, 33], [2, 41], [3, 7], [3, 11], [3, 12], [3, 14], [3, 22], [3, 25], [3, 32], [3, 33], [3, 34], [3, 37], [3, 39], [4, 7], [4, 12], [4, 14], [4, 18], [4, 19], [4, 30], [4, 41], [4, 44], [5, 10], [5, 13], [5, 14], [5, 22], [5, 29], [5, 35], [5, 43], [6, 10], [6, 15], [6, 17], [6, 25], [6, 27], [6, 44], [7, 10], [7, 12], [7, 18], [7, 21], [7, 23], [7, 31], [7, 32], [7, 34], [7, 36], [7, 37], [7, 38], [7, 39], [8, 12], [8, 14], [8, 21], [8, 22], [8, 24], [8, 37], [8, 40], [8, 41], [8, 42], [9, 12], [9, 15], [9, 27], [9, 29], [9, 38], [10, 12], [10, 17], [10, 18], [10, 23], [10, 25], [10, 26], [10, 27], [10, 30], [10, 37], [10, 40], [10, 42], [10, 43], [11, 12], [11, 15], [11, 17], [11, 20], [11, 22], [11, 30], [11, 34], [11, 36], [11, 37], [11, 38], [11, 44], [12, 14], [12, 19], [12, 21], [12, 22], [13, 14], [13, 27], [13, 37], [13, 40], [13, 42], [14, 15], [14, 17], [14, 20], [14, 23], [14, 27], [15, 18], [15, 19], [15, 20], [15, 24], [15, 27], [15, 34], [15, 35], [15, 37], [15, 42], [16, 20], [16, 31], [16, 35], [16, 42], [16, 44], [17, 20], [17, 25], [17, 28], [17, 31], [17, 33], [17, 44], [18, 19], [18, 25], [18, 27], [18, 31], [18, 32], [18, 34], [19, 21], [19, 24], [19, 27], [19, 30], [19, 32], [19, 36], [19, 43], [19, 44], [20, 22], [20, 24], [20, 25], [20, 30], [20, 34], [20, 38], [20, 39], [20, 42], [21, 25], [21, 31], [21, 33], [21, 39], [21, 42], [22, 26], [22, 29], [22, 30], [22, 32], [22, 33], [22, 34], [22, 36], [22, 37], [22, 40], [22, 44], [23, 24], [23, 25], [23, 28], [23, 29], [23, 35], [23, 42], [23, 44], [24, 26], [24, 29], [24, 32], [24, 33], [24, 36], [24, 40], [24, 42], [24, 44], [25, 27], [25, 32], [25, 37], [25, 40], [25, 41], [25, 43], [26, 30], [26, 42], [26, 43], [26, 44], [27, 28], [27, 37], [27, 40], [27, 42], [27, 43], [27, 44], [28, 29], [28, 30], [28, 31], [28, 36], [28, 37], [28, 40], [28, 43], [29, 32], [29, 34], [29, 36], [29, 39], [29, 41], [29, 44], [30, 32], [30, 33], [30, 39], [30, 44], [31, 32], [31, 35], [31, 37], [31, 41], [31, 43], [31, 44], [32, 33], [32, 38], [33, 34], [33, 43], [33, 44], [34, 35], [34, 36], [35, 36], [35, 37], [35, 40], [35, 43], [36, 41], [37, 38], [37, 40], [37, 41], [38, 44], [39, 40], [39, 42], [39, 43], [40, 41], [40, 44]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l3-s7/tests/run.py b/tasks/construct-mc-max-independent-set-l3-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-independent-set-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-mc-max-independent-set-l3-s7/tests/test.sh b/tasks/construct-mc-max-independent-set-l3-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-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-mc-max-independent-set-l3-s9/environment/Dockerfile b/tasks/construct-mc-max-independent-set-l3-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-independent-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-mc-max-independent-set-l3-s9/environment/instance.json b/tasks/construct-mc-max-independent-set-l3-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..24f0cfbfdc1a3a669a48405f7b9407e6c2381f1b --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l3-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 45, "k": 11, "edges": [[0, 5], [0, 6], [0, 7], [0, 13], [0, 14], [0, 27], [0, 32], [0, 35], [0, 36], [0, 39], [0, 40], [0, 43], [1, 5], [1, 11], [1, 13], [1, 14], [1, 18], [1, 21], [1, 34], [1, 35], [1, 37], [1, 43], [2, 7], [2, 14], [2, 15], [2, 16], [2, 17], [2, 19], [2, 21], [2, 23], [2, 38], [2, 40], [2, 42], [3, 4], [3, 12], [3, 16], [3, 17], [3, 23], [3, 28], [3, 33], [3, 34], [3, 36], [3, 37], [3, 39], [3, 42], [4, 7], [4, 10], [4, 11], [4, 12], [4, 13], [4, 17], [4, 20], [4, 21], [4, 22], [4, 27], [4, 29], [4, 33], [4, 42], [4, 43], [5, 24], [5, 25], [5, 27], [5, 28], [5, 30], [5, 36], [5, 42], [6, 7], [6, 14], [6, 15], [6, 16], [6, 18], [6, 19], [6, 20], [6, 24], [6, 25], [6, 32], [6, 38], [6, 40], [7, 15], [7, 19], [7, 24], [7, 27], [7, 29], [7, 31], [7, 33], [7, 37], [7, 39], [7, 40], [7, 42], [7, 43], [8, 13], [8, 15], [8, 19], [8, 21], [8, 24], [8, 26], [8, 29], [8, 31], [8, 33], [8, 36], [8, 40], [9, 13], [9, 14], [9, 16], [9, 19], [9, 20], [9, 24], [9, 32], [9, 38], [9, 42], [10, 17], [10, 19], [10, 21], [10, 25], [10, 32], [10, 33], [10, 35], [10, 40], [10, 43], [11, 17], [11, 18], [11, 19], [11, 25], [11, 36], [11, 39], [11, 40], [11, 41], [11, 42], [12, 14], [12, 17], [12, 18], [12, 19], [12, 25], [12, 27], [12, 39], [12, 42], [12, 44], [13, 19], [13, 20], [13, 22], [13, 23], [13, 25], [13, 26], [13, 27], [13, 40], [13, 44], [14, 20], [14, 25], [14, 27], [14, 30], [14, 31], [14, 34], [14, 35], [14, 44], [15, 17], [15, 18], [15, 20], [15, 24], [15, 27], [15, 39], [15, 41], [16, 32], [16, 34], [16, 38], [16, 40], [17, 20], [17, 26], [17, 32], [17, 36], [17, 38], [17, 39], [17, 43], [18, 22], [18, 23], [18, 25], [18, 29], [18, 36], [18, 37], [18, 41], [18, 44], [19, 20], [19, 24], [19, 31], [19, 33], [19, 36], [19, 39], [19, 41], [20, 21], [20, 23], [20, 24], [20, 30], [20, 32], [20, 33], [20, 34], [20, 37], [20, 38], [20, 40], [21, 35], [21, 36], [21, 41], [21, 43], [21, 44], [22, 32], [22, 38], [23, 24], [23, 32], [23, 33], [23, 35], [23, 44], [24, 27], [24, 30], [24, 33], [24, 34], [24, 36], [24, 38], [25, 26], [25, 29], [25, 33], [25, 37], [25, 44], [26, 27], [26, 28], [26, 30], [26, 32], [26, 39], [26, 41], [26, 42], [26, 44], [27, 31], [27, 33], [27, 34], [27, 38], [27, 42], [27, 43], [27, 44], [28, 30], [28, 37], [28, 38], [28, 40], [29, 33], [29, 34], [29, 36], [29, 37], [29, 38], [30, 37], [31, 34], [31, 35], [31, 37], [31, 41], [32, 33], [32, 39], [32, 40], [32, 41], [32, 44], [33, 36], [33, 42], [34, 38], [34, 42], [34, 44], [35, 43], [36, 38], [36, 39], [36, 42], [36, 43], [37, 44], [38, 40], [38, 41], [39, 40], [39, 41], [39, 42], [40, 43]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l3-s9/solution/solve.sh b/tasks/construct-mc-max-independent-set-l3-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..682919ba92925108c3f02ac47dd4cf31c3099eaa --- /dev/null +++ b/tasks/construct-mc-max-independent-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' +{"independent_set": [2, 5, 6, 9, 12, 22, 26, 33, 34, 35, 37]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-independent-set-l3-s9/tests/check.py b/tasks/construct-mc-max-independent-set-l3-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..adce413e8578d996549583b990e4ff559f38ed41 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l3-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-l3-s9/tests/instance.json b/tasks/construct-mc-max-independent-set-l3-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..24f0cfbfdc1a3a669a48405f7b9407e6c2381f1b --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l3-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 45, "k": 11, "edges": [[0, 5], [0, 6], [0, 7], [0, 13], [0, 14], [0, 27], [0, 32], [0, 35], [0, 36], [0, 39], [0, 40], [0, 43], [1, 5], [1, 11], [1, 13], [1, 14], [1, 18], [1, 21], [1, 34], [1, 35], [1, 37], [1, 43], [2, 7], [2, 14], [2, 15], [2, 16], [2, 17], [2, 19], [2, 21], [2, 23], [2, 38], [2, 40], [2, 42], [3, 4], [3, 12], [3, 16], [3, 17], [3, 23], [3, 28], [3, 33], [3, 34], [3, 36], [3, 37], [3, 39], [3, 42], [4, 7], [4, 10], [4, 11], [4, 12], [4, 13], [4, 17], [4, 20], [4, 21], [4, 22], [4, 27], [4, 29], [4, 33], [4, 42], [4, 43], [5, 24], [5, 25], [5, 27], [5, 28], [5, 30], [5, 36], [5, 42], [6, 7], [6, 14], [6, 15], [6, 16], [6, 18], [6, 19], [6, 20], [6, 24], [6, 25], [6, 32], [6, 38], [6, 40], [7, 15], [7, 19], [7, 24], [7, 27], [7, 29], [7, 31], [7, 33], [7, 37], [7, 39], [7, 40], [7, 42], [7, 43], [8, 13], [8, 15], [8, 19], [8, 21], [8, 24], [8, 26], [8, 29], [8, 31], [8, 33], [8, 36], [8, 40], [9, 13], [9, 14], [9, 16], [9, 19], [9, 20], [9, 24], [9, 32], [9, 38], [9, 42], [10, 17], [10, 19], [10, 21], [10, 25], [10, 32], [10, 33], [10, 35], [10, 40], [10, 43], [11, 17], [11, 18], [11, 19], [11, 25], [11, 36], [11, 39], [11, 40], [11, 41], [11, 42], [12, 14], [12, 17], [12, 18], [12, 19], [12, 25], [12, 27], [12, 39], [12, 42], [12, 44], [13, 19], [13, 20], [13, 22], [13, 23], [13, 25], [13, 26], [13, 27], [13, 40], [13, 44], [14, 20], [14, 25], [14, 27], [14, 30], [14, 31], [14, 34], [14, 35], [14, 44], [15, 17], [15, 18], [15, 20], [15, 24], [15, 27], [15, 39], [15, 41], [16, 32], [16, 34], [16, 38], [16, 40], [17, 20], [17, 26], [17, 32], [17, 36], [17, 38], [17, 39], [17, 43], [18, 22], [18, 23], [18, 25], [18, 29], [18, 36], [18, 37], [18, 41], [18, 44], [19, 20], [19, 24], [19, 31], [19, 33], [19, 36], [19, 39], [19, 41], [20, 21], [20, 23], [20, 24], [20, 30], [20, 32], [20, 33], [20, 34], [20, 37], [20, 38], [20, 40], [21, 35], [21, 36], [21, 41], [21, 43], [21, 44], [22, 32], [22, 38], [23, 24], [23, 32], [23, 33], [23, 35], [23, 44], [24, 27], [24, 30], [24, 33], [24, 34], [24, 36], [24, 38], [25, 26], [25, 29], [25, 33], [25, 37], [25, 44], [26, 27], [26, 28], [26, 30], [26, 32], [26, 39], [26, 41], [26, 42], [26, 44], [27, 31], [27, 33], [27, 34], [27, 38], [27, 42], [27, 43], [27, 44], [28, 30], [28, 37], [28, 38], [28, 40], [29, 33], [29, 34], [29, 36], [29, 37], [29, 38], [30, 37], [31, 34], [31, 35], [31, 37], [31, 41], [32, 33], [32, 39], [32, 40], [32, 41], [32, 44], [33, 36], [33, 42], [34, 38], [34, 42], [34, 44], [35, 43], [36, 38], [36, 39], [36, 42], [36, 43], [37, 44], [38, 40], [38, 41], [39, 40], [39, 41], [39, 42], [40, 43]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l3-s9/tests/run.py b/tasks/construct-mc-max-independent-set-l3-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-independent-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-mc-max-independent-set-l3-s9/tests/test.sh b/tasks/construct-mc-max-independent-set-l3-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-independent-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-mc-non-transitive-dice-l3-s0/environment/Dockerfile b/tasks/construct-mc-non-transitive-dice-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-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-non-transitive-dice-l3-s0/environment/instance.json b/tasks/construct-mc-non-transitive-dice-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6e9fd7399301ddb0b3dfca7d023e887b61853771 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 4, "m": 6, "family": "mc_non_transitive_dice", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-non-transitive-dice-l3-s0/solution/solve.sh b/tasks/construct-mc-non-transitive-dice-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..61b3b0c877977655f3e403a273e2e2f79ffedf81 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-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' +{"dice": [[0, 5, 5, 6, 7, 7], [2, 3, 3, 5, 6, 11], [1, 2, 2, 5, 9, 11], [0, 0, 4, 8, 8, 9]]} +RLMATH_EOF diff --git a/tasks/construct-mc-non-transitive-dice-l3-s0/tests/check.py b/tasks/construct-mc-non-transitive-dice-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3d5c04fa6e2819bf32f34fafe13a383437dc62a --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l3-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-l3-s0/tests/instance.json b/tasks/construct-mc-non-transitive-dice-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6e9fd7399301ddb0b3dfca7d023e887b61853771 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 4, "m": 6, "family": "mc_non_transitive_dice", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-non-transitive-dice-l3-s0/tests/run.py b/tasks/construct-mc-non-transitive-dice-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-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-non-transitive-dice-l3-s0/tests/test.sh b/tasks/construct-mc-non-transitive-dice-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-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-number-partitioning-l3-s3/environment/Dockerfile b/tasks/construct-mc-number-partitioning-l3-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-mc-number-partitioning-l3-s3/environment/instance.json b/tasks/construct-mc-number-partitioning-l3-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cc5cf2c9c344748011fb372f77313ffbbbcdfb95 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l3-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 5, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l3-s3/solution/solve.sh b/tasks/construct-mc-number-partitioning-l3-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..473a7a9ed6e99e2e7a58266d3eabdb74b96b6fd8 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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' +{"x": [0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 4, 3, 2, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-number-partitioning-l3-s3/tests/check.py b/tasks/construct-mc-number-partitioning-l3-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..67793721db8ba7d3c3979ea0e1e07091491ffa7e --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l3-s3/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-l3-s3/tests/instance.json b/tasks/construct-mc-number-partitioning-l3-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cc5cf2c9c344748011fb372f77313ffbbbcdfb95 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l3-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 5, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l3-s3/tests/run.py b/tasks/construct-mc-number-partitioning-l3-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-mc-number-partitioning-l3-s3/tests/test.sh b/tasks/construct-mc-number-partitioning-l3-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-mc-number-partitioning-l3-s4/environment/Dockerfile b/tasks/construct-mc-number-partitioning-l3-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-mc-number-partitioning-l3-s4/environment/instance.json b/tasks/construct-mc-number-partitioning-l3-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8cd9ed4e650fed36a4c1f055cd1475151e559b75 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l3-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 16, "k": 4, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l3-s4/solution/solve.sh b/tasks/construct-mc-number-partitioning-l3-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..93a5bff3cb60fe2ec1ab22d59ecac23b3728dc5d --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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' +{"x": [0, 3, 2, 1, 1, 0, 2, 2, 3, 3, 1, 0, 3, 1, 0, 2]} +RLMATH_EOF diff --git a/tasks/construct-mc-number-partitioning-l3-s4/tests/check.py b/tasks/construct-mc-number-partitioning-l3-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..67793721db8ba7d3c3979ea0e1e07091491ffa7e --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l3-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-l3-s4/tests/instance.json b/tasks/construct-mc-number-partitioning-l3-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8cd9ed4e650fed36a4c1f055cd1475151e559b75 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l3-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 16, "k": 4, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l3-s4/tests/run.py b/tasks/construct-mc-number-partitioning-l3-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-mc-number-partitioning-l3-s4/tests/test.sh b/tasks/construct-mc-number-partitioning-l3-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-pysms-chromatic-girth-l1-s3/environment/Dockerfile b/tasks/construct-mc-pysms-chromatic-girth-l1-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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-pysms-chromatic-girth-l1-s3/environment/instance.json b/tasks/construct-mc-pysms-chromatic-girth-l1-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9dde67c78ee889593b742cf9cebf452e65ca6ad0 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-l1-s3/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 14, "required_edges": [], "max_chromatic_number": 4, "min_edges": 16, "min_girth": 4, "family": "mc_pysms_chromatic_girth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-chromatic-girth-l1-s3/solution/solve.sh b/tasks/construct-mc-pysms-chromatic-girth-l1-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..832958a1c9ae0c570544b497b6cc53d30c596469 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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' +{"edges": [[0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13]], "coloring": [0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-chromatic-girth-l1-s3/tests/check.py b/tasks/construct-mc-pysms-chromatic-girth-l1-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-l1-s3/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-chromatic-girth-l1-s3/tests/instance.json b/tasks/construct-mc-pysms-chromatic-girth-l1-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9dde67c78ee889593b742cf9cebf452e65ca6ad0 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-l1-s3/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 14, "required_edges": [], "max_chromatic_number": 4, "min_edges": 16, "min_girth": 4, "family": "mc_pysms_chromatic_girth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-chromatic-girth-l1-s3/tests/run.py b/tasks/construct-mc-pysms-chromatic-girth-l1-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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-pysms-chromatic-girth-l1-s3/tests/test.sh b/tasks/construct-mc-pysms-chromatic-girth-l1-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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-pysms-chromatic-girth-l5-s2/environment/Dockerfile b/tasks/construct-mc-pysms-chromatic-girth-l5-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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-pysms-chromatic-girth-l5-s2/environment/instance.json b/tasks/construct-mc-pysms-chromatic-girth-l5-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..da1fbbbe95a28316ce831df71660a7e76c90d457 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-l5-s2/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 24, "required_edges": [], "max_chromatic_number": 5, "min_edges": 33, "min_girth": 7, "family": "mc_pysms_chromatic_girth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-chromatic-girth-l5-s2/solution/solve.sh b/tasks/construct-mc-pysms-chromatic-girth-l5-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f10dc938061e9bdaa1f627da4c427b3e05811f35 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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' +{"edges": [[0, 21], [0, 22], [0, 23], [1, 19], [1, 20], [1, 23], [2, 17], [2, 18], [2, 23], [3, 15], [3, 16], [3, 22], [4, 14], [4, 16], [4, 20], [5, 13], [5, 16], [5, 18], [6, 12], [6, 15], [6, 19], [7, 11], [7, 14], [7, 17], [8, 10], [8, 12], [8, 18], [9, 10], [9, 11], [9, 22], [10, 20], [11, 13], [12, 21], [13, 19], [14, 21], [15, 17]], "coloring": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 2, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-chromatic-girth-l5-s2/tests/check.py b/tasks/construct-mc-pysms-chromatic-girth-l5-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-l5-s2/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-chromatic-girth-l5-s2/tests/instance.json b/tasks/construct-mc-pysms-chromatic-girth-l5-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..da1fbbbe95a28316ce831df71660a7e76c90d457 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-l5-s2/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 24, "required_edges": [], "max_chromatic_number": 5, "min_edges": 33, "min_girth": 7, "family": "mc_pysms_chromatic_girth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-chromatic-girth-l5-s2/tests/run.py b/tasks/construct-mc-pysms-chromatic-girth-l5-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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-pysms-chromatic-girth-l5-s2/tests/test.sh b/tasks/construct-mc-pysms-chromatic-girth-l5-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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-pysms-degree-bounds-l5-s2/environment/Dockerfile b/tasks/construct-mc-pysms-degree-bounds-l5-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-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-pysms-degree-bounds-l5-s2/environment/instance.json b/tasks/construct-mc-pysms-degree-bounds-l5-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5ed88a79ecebb35726c61fee957a31e67a6a92b0 --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-l5-s2/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 12, "required_edges": [], "max_degree": 6, "min_degree": 3, "family": "mc_pysms_degree_bounds", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-degree-bounds-l5-s2/solution/solve.sh b/tasks/construct-mc-pysms-degree-bounds-l5-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d1d09102e31d41f15a3033d7a31bb5b25d370e2e --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-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' +{"edges": [[0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-degree-bounds-l5-s2/tests/check.py b/tasks/construct-mc-pysms-degree-bounds-l5-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-l5-s2/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-degree-bounds-l5-s2/tests/instance.json b/tasks/construct-mc-pysms-degree-bounds-l5-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5ed88a79ecebb35726c61fee957a31e67a6a92b0 --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-l5-s2/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 12, "required_edges": [], "max_degree": 6, "min_degree": 3, "family": "mc_pysms_degree_bounds", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-degree-bounds-l5-s2/tests/run.py b/tasks/construct-mc-pysms-degree-bounds-l5-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-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-pysms-degree-bounds-l5-s2/tests/test.sh b/tasks/construct-mc-pysms-degree-bounds-l5-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-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-pysms-girth-degree-l2-s1/environment/Dockerfile b/tasks/construct-mc-pysms-girth-degree-l2-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-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-mc-pysms-girth-degree-l2-s1/environment/instance.json b/tasks/construct-mc-pysms-girth-degree-l2-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fbdc11c847fe56efd9fce6da3dae199de9c4db0e --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-l2-s1/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 14, "required_edges": [], "max_degree": 3, "min_degree": 3, "min_girth": 5, "family": "mc_pysms_girth_degree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-girth-degree-l2-s1/solution/solve.sh b/tasks/construct-mc-pysms-girth-degree-l2-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..29af107aafce37d2a6e517e52531d835d6a8b870 --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-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' +{"edges": [[0, 11], [0, 12], [0, 13], [1, 9], [1, 10], [1, 13], [2, 8], [2, 10], [2, 12], [3, 7], [3, 10], [3, 11], [4, 6], [4, 9], [4, 12], [5, 6], [5, 7], [5, 8], [6, 13], [7, 9], [8, 11]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-girth-degree-l2-s1/tests/check.py b/tasks/construct-mc-pysms-girth-degree-l2-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-l2-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-girth-degree-l2-s1/tests/instance.json b/tasks/construct-mc-pysms-girth-degree-l2-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fbdc11c847fe56efd9fce6da3dae199de9c4db0e --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-l2-s1/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 14, "required_edges": [], "max_degree": 3, "min_degree": 3, "min_girth": 5, "family": "mc_pysms_girth_degree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-girth-degree-l2-s1/tests/run.py b/tasks/construct-mc-pysms-girth-degree-l2-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-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-mc-pysms-girth-degree-l2-s1/tests/test.sh b/tasks/construct-mc-pysms-girth-degree-l2-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-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-mc-pysms-girth-degree-l6-s0/environment/Dockerfile b/tasks/construct-mc-pysms-girth-degree-l6-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-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-mc-pysms-girth-degree-l6-s0/environment/instance.json b/tasks/construct-mc-pysms-girth-degree-l6-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..705c1c8d2ae05998de55d4953540a7423b7081ff --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-l6-s0/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 24, "required_edges": [], "max_degree": 6, "min_degree": 3, "min_girth": 7, "family": "mc_pysms_girth_degree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-girth-degree-l6-s0/solution/solve.sh b/tasks/construct-mc-pysms-girth-degree-l6-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..bfe00871b8706710dc5fbe22ce43aad419c5b2b3 --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-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' +{"edges": [[0, 21], [0, 22], [0, 23], [1, 19], [1, 20], [1, 23], [2, 17], [2, 18], [2, 23], [3, 15], [3, 16], [3, 22], [4, 14], [4, 16], [4, 20], [5, 13], [5, 16], [5, 18], [6, 12], [6, 15], [6, 19], [7, 11], [7, 14], [7, 17], [8, 10], [8, 12], [8, 18], [9, 10], [9, 11], [9, 22], [10, 20], [11, 13], [12, 21], [13, 19], [14, 21], [15, 17]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-girth-degree-l6-s0/tests/check.py b/tasks/construct-mc-pysms-girth-degree-l6-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-l6-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-girth-degree-l6-s0/tests/instance.json b/tasks/construct-mc-pysms-girth-degree-l6-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..705c1c8d2ae05998de55d4953540a7423b7081ff --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-l6-s0/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 24, "required_edges": [], "max_degree": 6, "min_degree": 3, "min_girth": 7, "family": "mc_pysms_girth_degree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-girth-degree-l6-s0/tests/run.py b/tasks/construct-mc-pysms-girth-degree-l6-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-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-mc-pysms-girth-degree-l6-s0/tests/test.sh b/tasks/construct-mc-pysms-girth-degree-l6-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-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-mc-pysms-independent-connectivity-l3-s1/environment/Dockerfile b/tasks/construct-mc-pysms-independent-connectivity-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-independent-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-independent-connectivity-l3-s1/environment/instance.json b/tasks/construct-mc-pysms-independent-connectivity-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d6b7f7b7a4ee88a1d309191189c9ab920227b17d --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 9, "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-l3-s1/solution/solve.sh b/tasks/construct-mc-pysms-independent-connectivity-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..266b10696d549d81ec1db10a95e1067a0f575ccd --- /dev/null +++ b/tasks/construct-mc-pysms-independent-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], [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-l3-s1/tests/check.py b/tasks/construct-mc-pysms-independent-connectivity-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-independent-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-independent-connectivity-l3-s1/tests/instance.json b/tasks/construct-mc-pysms-independent-connectivity-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d6b7f7b7a4ee88a1d309191189c9ab920227b17d --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 9, "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-l3-s1/tests/run.py b/tasks/construct-mc-pysms-independent-connectivity-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-independent-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-independent-connectivity-l3-s1/tests/test.sh b/tasks/construct-mc-pysms-independent-connectivity-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-independent-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-connectivity-l1-s0/environment/Dockerfile b/tasks/construct-mc-pysms-min-connectivity-l1-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-min-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-min-connectivity-l1-s0/environment/instance.json b/tasks/construct-mc-pysms-min-connectivity-l1-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ffb5fa147ec2e4bb48e50e6b1ca3b595cdd37afe --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-l1-s0/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 8, "required_edges": [], "min_connectivity": 1, "family": "mc_pysms_min_connectivity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-min-connectivity-l1-s0/solution/solve.sh b/tasks/construct-mc-pysms-min-connectivity-l1-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a411bb51ad0fd830529a244c60057cdaa691261e --- /dev/null +++ b/tasks/construct-mc-pysms-min-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], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [3, 4], [3, 5], [3, 6], [3, 7], [4, 5], [4, 6], [4, 7], [5, 6], [5, 7], [6, 7]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-min-connectivity-l1-s0/tests/check.py b/tasks/construct-mc-pysms-min-connectivity-l1-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-min-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-min-connectivity-l1-s0/tests/instance.json b/tasks/construct-mc-pysms-min-connectivity-l1-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ffb5fa147ec2e4bb48e50e6b1ca3b595cdd37afe --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-l1-s0/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 8, "required_edges": [], "min_connectivity": 1, "family": "mc_pysms_min_connectivity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-min-connectivity-l1-s0/tests/run.py b/tasks/construct-mc-pysms-min-connectivity-l1-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-min-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-min-connectivity-l1-s0/tests/test.sh b/tasks/construct-mc-pysms-min-connectivity-l1-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-min-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-num-edges-bounds-l1-s1/environment/Dockerfile b/tasks/construct-mc-pysms-num-edges-bounds-l1-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-num-edges-bounds-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-num-edges-bounds-l1-s1/environment/instance.json b/tasks/construct-mc-pysms-num-edges-bounds-l1-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c5f72316d28a0d279ebff30baa83582a711718a2 --- /dev/null +++ b/tasks/construct-mc-pysms-num-edges-bounds-l1-s1/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 8, "required_edges": [], "max_edges": 16, "min_edges": 11, "family": "mc_pysms_num_edges_bounds", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-num-edges-bounds-l1-s1/solution/solve.sh b/tasks/construct-mc-pysms-num-edges-bounds-l1-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8c787192a83d8aa912bc6cd12be86635cbb652b6 --- /dev/null +++ b/tasks/construct-mc-pysms-num-edges-bounds-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, 4], [0, 5], [0, 6], [0, 7], [1, 4], [1, 5], [1, 6], [1, 7], [2, 4], [2, 5], [2, 6], [2, 7], [3, 4], [3, 5], [3, 6], [3, 7]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-num-edges-bounds-l1-s1/tests/check.py b/tasks/construct-mc-pysms-num-edges-bounds-l1-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-num-edges-bounds-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-num-edges-bounds-l1-s1/tests/instance.json b/tasks/construct-mc-pysms-num-edges-bounds-l1-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c5f72316d28a0d279ebff30baa83582a711718a2 --- /dev/null +++ b/tasks/construct-mc-pysms-num-edges-bounds-l1-s1/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 8, "required_edges": [], "max_edges": 16, "min_edges": 11, "family": "mc_pysms_num_edges_bounds", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-num-edges-bounds-l1-s1/tests/run.py b/tasks/construct-mc-pysms-num-edges-bounds-l1-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-num-edges-bounds-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-num-edges-bounds-l1-s1/tests/test.sh b/tasks/construct-mc-pysms-num-edges-bounds-l1-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-num-edges-bounds-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-quasigroup-idempotent-l6-s2/environment/Dockerfile b/tasks/construct-mc-quasigroup-idempotent-l6-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-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-quasigroup-idempotent-l6-s2/environment/instance.json b/tasks/construct-mc-quasigroup-idempotent-l6-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..47927855201bb5f399bc119accf411dd56fb2b79 --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-l6-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 52, "family": "mc_quasigroup_idempotent", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-quasigroup-idempotent-l6-s2/solution/solve.sh b/tasks/construct-mc-quasigroup-idempotent-l6-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e20ccad5753996bb0e942742e28389c629e11927 --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-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' +{"table": [[0, 3, 12, 9, 7, 4, 10, 5, 2, 1, 11, 6, 8, 39, 42, 51, 48, 46, 43, 49, 44, 41, 40, 50, 45, 47, 13, 16, 25, 22, 20, 17, 23, 18, 15, 14, 24, 19, 21, 26, 29, 38, 35, 33, 30, 36, 31, 28, 27, 37, 32, 34], [9, 1, 4, 0, 10, 8, 5, 11, 6, 3, 2, 12, 7, 48, 40, 43, 39, 49, 47, 44, 50, 45, 42, 41, 51, 46, 22, 14, 17, 13, 23, 21, 18, 24, 19, 16, 15, 25, 20, 35, 27, 30, 26, 36, 34, 31, 37, 32, 29, 28, 38, 33], [8, 10, 2, 5, 1, 11, 9, 6, 12, 7, 4, 3, 0, 47, 49, 41, 44, 40, 50, 48, 45, 51, 46, 43, 42, 39, 21, 23, 15, 18, 14, 24, 22, 19, 25, 20, 17, 16, 13, 34, 36, 28, 31, 27, 37, 35, 32, 38, 33, 30, 29, 26], [1, 9, 11, 3, 6, 2, 12, 10, 7, 0, 8, 5, 4, 40, 48, 50, 42, 45, 41, 51, 49, 46, 39, 47, 44, 43, 14, 22, 24, 16, 19, 15, 25, 23, 20, 13, 21, 18, 17, 27, 35, 37, 29, 32, 28, 38, 36, 33, 26, 34, 31, 30], [5, 2, 10, 12, 4, 7, 3, 0, 11, 8, 1, 9, 6, 44, 41, 49, 51, 43, 46, 42, 39, 50, 47, 40, 48, 45, 18, 15, 23, 25, 17, 20, 16, 13, 24, 21, 14, 22, 19, 31, 28, 36, 38, 30, 33, 29, 26, 37, 34, 27, 35, 32], [7, 6, 3, 11, 0, 5, 8, 4, 1, 12, 9, 2, 10, 46, 45, 42, 50, 39, 44, 47, 43, 40, 51, 48, 41, 49, 20, 19, 16, 24, 13, 18, 21, 17, 14, 25, 22, 15, 23, 33, 32, 29, 37, 26, 31, 34, 30, 27, 38, 35, 28, 36], [11, 8, 7, 4, 12, 1, 6, 9, 5, 2, 0, 10, 3, 50, 47, 46, 43, 51, 40, 45, 48, 44, 41, 39, 49, 42, 24, 21, 20, 17, 25, 14, 19, 22, 18, 15, 13, 23, 16, 37, 34, 33, 30, 38, 27, 32, 35, 31, 28, 26, 36, 29], [4, 12, 9, 8, 5, 0, 2, 7, 10, 6, 3, 1, 11, 43, 51, 48, 47, 44, 39, 41, 46, 49, 45, 42, 40, 50, 17, 25, 22, 21, 18, 13, 15, 20, 23, 19, 16, 14, 24, 30, 38, 35, 34, 31, 26, 28, 33, 36, 32, 29, 27, 37], [12, 5, 0, 10, 9, 6, 1, 3, 8, 11, 7, 4, 2, 51, 44, 39, 49, 48, 45, 40, 42, 47, 50, 46, 43, 41, 25, 18, 13, 23, 22, 19, 14, 16, 21, 24, 20, 17, 15, 38, 31, 26, 36, 35, 32, 27, 29, 34, 37, 33, 30, 28], [3, 0, 6, 1, 11, 10, 7, 2, 4, 9, 12, 8, 5, 42, 39, 45, 40, 50, 49, 46, 41, 43, 48, 51, 47, 44, 16, 13, 19, 14, 24, 23, 20, 15, 17, 22, 25, 21, 18, 29, 26, 32, 27, 37, 36, 33, 28, 30, 35, 38, 34, 31], [6, 4, 1, 7, 2, 12, 11, 8, 3, 5, 10, 0, 9, 45, 43, 40, 46, 41, 51, 50, 47, 42, 44, 49, 39, 48, 19, 17, 14, 20, 15, 25, 24, 21, 16, 18, 23, 13, 22, 32, 30, 27, 33, 28, 38, 37, 34, 29, 31, 36, 26, 35], [10, 7, 5, 2, 8, 3, 0, 12, 9, 4, 6, 11, 1, 49, 46, 44, 41, 47, 42, 39, 51, 48, 43, 45, 50, 40, 23, 20, 18, 15, 21, 16, 13, 25, 22, 17, 19, 24, 14, 36, 33, 31, 28, 34, 29, 26, 38, 35, 30, 32, 37, 27], [2, 11, 8, 6, 3, 9, 4, 1, 0, 10, 5, 7, 12, 41, 50, 47, 45, 42, 48, 43, 40, 39, 49, 44, 46, 51, 15, 24, 21, 19, 16, 22, 17, 14, 13, 23, 18, 20, 25, 28, 37, 34, 32, 29, 35, 30, 27, 26, 36, 31, 33, 38], [26, 29, 38, 35, 33, 30, 36, 31, 28, 27, 37, 32, 34, 13, 16, 25, 22, 20, 17, 23, 18, 15, 14, 24, 19, 21, 39, 42, 51, 48, 46, 43, 49, 44, 41, 40, 50, 45, 47, 0, 3, 12, 9, 7, 4, 10, 5, 2, 1, 11, 6, 8], [35, 27, 30, 26, 36, 34, 31, 37, 32, 29, 28, 38, 33, 22, 14, 17, 13, 23, 21, 18, 24, 19, 16, 15, 25, 20, 48, 40, 43, 39, 49, 47, 44, 50, 45, 42, 41, 51, 46, 9, 1, 4, 0, 10, 8, 5, 11, 6, 3, 2, 12, 7], [34, 36, 28, 31, 27, 37, 35, 32, 38, 33, 30, 29, 26, 21, 23, 15, 18, 14, 24, 22, 19, 25, 20, 17, 16, 13, 47, 49, 41, 44, 40, 50, 48, 45, 51, 46, 43, 42, 39, 8, 10, 2, 5, 1, 11, 9, 6, 12, 7, 4, 3, 0], [27, 35, 37, 29, 32, 28, 38, 36, 33, 26, 34, 31, 30, 14, 22, 24, 16, 19, 15, 25, 23, 20, 13, 21, 18, 17, 40, 48, 50, 42, 45, 41, 51, 49, 46, 39, 47, 44, 43, 1, 9, 11, 3, 6, 2, 12, 10, 7, 0, 8, 5, 4], [31, 28, 36, 38, 30, 33, 29, 26, 37, 34, 27, 35, 32, 18, 15, 23, 25, 17, 20, 16, 13, 24, 21, 14, 22, 19, 44, 41, 49, 51, 43, 46, 42, 39, 50, 47, 40, 48, 45, 5, 2, 10, 12, 4, 7, 3, 0, 11, 8, 1, 9, 6], [33, 32, 29, 37, 26, 31, 34, 30, 27, 38, 35, 28, 36, 20, 19, 16, 24, 13, 18, 21, 17, 14, 25, 22, 15, 23, 46, 45, 42, 50, 39, 44, 47, 43, 40, 51, 48, 41, 49, 7, 6, 3, 11, 0, 5, 8, 4, 1, 12, 9, 2, 10], [37, 34, 33, 30, 38, 27, 32, 35, 31, 28, 26, 36, 29, 24, 21, 20, 17, 25, 14, 19, 22, 18, 15, 13, 23, 16, 50, 47, 46, 43, 51, 40, 45, 48, 44, 41, 39, 49, 42, 11, 8, 7, 4, 12, 1, 6, 9, 5, 2, 0, 10, 3], [30, 38, 35, 34, 31, 26, 28, 33, 36, 32, 29, 27, 37, 17, 25, 22, 21, 18, 13, 15, 20, 23, 19, 16, 14, 24, 43, 51, 48, 47, 44, 39, 41, 46, 49, 45, 42, 40, 50, 4, 12, 9, 8, 5, 0, 2, 7, 10, 6, 3, 1, 11], [38, 31, 26, 36, 35, 32, 27, 29, 34, 37, 33, 30, 28, 25, 18, 13, 23, 22, 19, 14, 16, 21, 24, 20, 17, 15, 51, 44, 39, 49, 48, 45, 40, 42, 47, 50, 46, 43, 41, 12, 5, 0, 10, 9, 6, 1, 3, 8, 11, 7, 4, 2], [29, 26, 32, 27, 37, 36, 33, 28, 30, 35, 38, 34, 31, 16, 13, 19, 14, 24, 23, 20, 15, 17, 22, 25, 21, 18, 42, 39, 45, 40, 50, 49, 46, 41, 43, 48, 51, 47, 44, 3, 0, 6, 1, 11, 10, 7, 2, 4, 9, 12, 8, 5], [32, 30, 27, 33, 28, 38, 37, 34, 29, 31, 36, 26, 35, 19, 17, 14, 20, 15, 25, 24, 21, 16, 18, 23, 13, 22, 45, 43, 40, 46, 41, 51, 50, 47, 42, 44, 49, 39, 48, 6, 4, 1, 7, 2, 12, 11, 8, 3, 5, 10, 0, 9], [36, 33, 31, 28, 34, 29, 26, 38, 35, 30, 32, 37, 27, 23, 20, 18, 15, 21, 16, 13, 25, 22, 17, 19, 24, 14, 49, 46, 44, 41, 47, 42, 39, 51, 48, 43, 45, 50, 40, 10, 7, 5, 2, 8, 3, 0, 12, 9, 4, 6, 11, 1], [28, 37, 34, 32, 29, 35, 30, 27, 26, 36, 31, 33, 38, 15, 24, 21, 19, 16, 22, 17, 14, 13, 23, 18, 20, 25, 41, 50, 47, 45, 42, 48, 43, 40, 39, 49, 44, 46, 51, 2, 11, 8, 6, 3, 9, 4, 1, 0, 10, 5, 7, 12], [39, 42, 51, 48, 46, 43, 49, 44, 41, 40, 50, 45, 47, 0, 3, 12, 9, 7, 4, 10, 5, 2, 1, 11, 6, 8, 26, 29, 38, 35, 33, 30, 36, 31, 28, 27, 37, 32, 34, 13, 16, 25, 22, 20, 17, 23, 18, 15, 14, 24, 19, 21], [48, 40, 43, 39, 49, 47, 44, 50, 45, 42, 41, 51, 46, 9, 1, 4, 0, 10, 8, 5, 11, 6, 3, 2, 12, 7, 35, 27, 30, 26, 36, 34, 31, 37, 32, 29, 28, 38, 33, 22, 14, 17, 13, 23, 21, 18, 24, 19, 16, 15, 25, 20], [47, 49, 41, 44, 40, 50, 48, 45, 51, 46, 43, 42, 39, 8, 10, 2, 5, 1, 11, 9, 6, 12, 7, 4, 3, 0, 34, 36, 28, 31, 27, 37, 35, 32, 38, 33, 30, 29, 26, 21, 23, 15, 18, 14, 24, 22, 19, 25, 20, 17, 16, 13], [40, 48, 50, 42, 45, 41, 51, 49, 46, 39, 47, 44, 43, 1, 9, 11, 3, 6, 2, 12, 10, 7, 0, 8, 5, 4, 27, 35, 37, 29, 32, 28, 38, 36, 33, 26, 34, 31, 30, 14, 22, 24, 16, 19, 15, 25, 23, 20, 13, 21, 18, 17], [44, 41, 49, 51, 43, 46, 42, 39, 50, 47, 40, 48, 45, 5, 2, 10, 12, 4, 7, 3, 0, 11, 8, 1, 9, 6, 31, 28, 36, 38, 30, 33, 29, 26, 37, 34, 27, 35, 32, 18, 15, 23, 25, 17, 20, 16, 13, 24, 21, 14, 22, 19], [46, 45, 42, 50, 39, 44, 47, 43, 40, 51, 48, 41, 49, 7, 6, 3, 11, 0, 5, 8, 4, 1, 12, 9, 2, 10, 33, 32, 29, 37, 26, 31, 34, 30, 27, 38, 35, 28, 36, 20, 19, 16, 24, 13, 18, 21, 17, 14, 25, 22, 15, 23], [50, 47, 46, 43, 51, 40, 45, 48, 44, 41, 39, 49, 42, 11, 8, 7, 4, 12, 1, 6, 9, 5, 2, 0, 10, 3, 37, 34, 33, 30, 38, 27, 32, 35, 31, 28, 26, 36, 29, 24, 21, 20, 17, 25, 14, 19, 22, 18, 15, 13, 23, 16], [43, 51, 48, 47, 44, 39, 41, 46, 49, 45, 42, 40, 50, 4, 12, 9, 8, 5, 0, 2, 7, 10, 6, 3, 1, 11, 30, 38, 35, 34, 31, 26, 28, 33, 36, 32, 29, 27, 37, 17, 25, 22, 21, 18, 13, 15, 20, 23, 19, 16, 14, 24], [51, 44, 39, 49, 48, 45, 40, 42, 47, 50, 46, 43, 41, 12, 5, 0, 10, 9, 6, 1, 3, 8, 11, 7, 4, 2, 38, 31, 26, 36, 35, 32, 27, 29, 34, 37, 33, 30, 28, 25, 18, 13, 23, 22, 19, 14, 16, 21, 24, 20, 17, 15], [42, 39, 45, 40, 50, 49, 46, 41, 43, 48, 51, 47, 44, 3, 0, 6, 1, 11, 10, 7, 2, 4, 9, 12, 8, 5, 29, 26, 32, 27, 37, 36, 33, 28, 30, 35, 38, 34, 31, 16, 13, 19, 14, 24, 23, 20, 15, 17, 22, 25, 21, 18], [45, 43, 40, 46, 41, 51, 50, 47, 42, 44, 49, 39, 48, 6, 4, 1, 7, 2, 12, 11, 8, 3, 5, 10, 0, 9, 32, 30, 27, 33, 28, 38, 37, 34, 29, 31, 36, 26, 35, 19, 17, 14, 20, 15, 25, 24, 21, 16, 18, 23, 13, 22], [49, 46, 44, 41, 47, 42, 39, 51, 48, 43, 45, 50, 40, 10, 7, 5, 2, 8, 3, 0, 12, 9, 4, 6, 11, 1, 36, 33, 31, 28, 34, 29, 26, 38, 35, 30, 32, 37, 27, 23, 20, 18, 15, 21, 16, 13, 25, 22, 17, 19, 24, 14], [41, 50, 47, 45, 42, 48, 43, 40, 39, 49, 44, 46, 51, 2, 11, 8, 6, 3, 9, 4, 1, 0, 10, 5, 7, 12, 28, 37, 34, 32, 29, 35, 30, 27, 26, 36, 31, 33, 38, 15, 24, 21, 19, 16, 22, 17, 14, 13, 23, 18, 20, 25], [13, 16, 25, 22, 20, 17, 23, 18, 15, 14, 24, 19, 21, 26, 29, 38, 35, 33, 30, 36, 31, 28, 27, 37, 32, 34, 0, 3, 12, 9, 7, 4, 10, 5, 2, 1, 11, 6, 8, 39, 42, 51, 48, 46, 43, 49, 44, 41, 40, 50, 45, 47], [22, 14, 17, 13, 23, 21, 18, 24, 19, 16, 15, 25, 20, 35, 27, 30, 26, 36, 34, 31, 37, 32, 29, 28, 38, 33, 9, 1, 4, 0, 10, 8, 5, 11, 6, 3, 2, 12, 7, 48, 40, 43, 39, 49, 47, 44, 50, 45, 42, 41, 51, 46], [21, 23, 15, 18, 14, 24, 22, 19, 25, 20, 17, 16, 13, 34, 36, 28, 31, 27, 37, 35, 32, 38, 33, 30, 29, 26, 8, 10, 2, 5, 1, 11, 9, 6, 12, 7, 4, 3, 0, 47, 49, 41, 44, 40, 50, 48, 45, 51, 46, 43, 42, 39], [14, 22, 24, 16, 19, 15, 25, 23, 20, 13, 21, 18, 17, 27, 35, 37, 29, 32, 28, 38, 36, 33, 26, 34, 31, 30, 1, 9, 11, 3, 6, 2, 12, 10, 7, 0, 8, 5, 4, 40, 48, 50, 42, 45, 41, 51, 49, 46, 39, 47, 44, 43], [18, 15, 23, 25, 17, 20, 16, 13, 24, 21, 14, 22, 19, 31, 28, 36, 38, 30, 33, 29, 26, 37, 34, 27, 35, 32, 5, 2, 10, 12, 4, 7, 3, 0, 11, 8, 1, 9, 6, 44, 41, 49, 51, 43, 46, 42, 39, 50, 47, 40, 48, 45], [20, 19, 16, 24, 13, 18, 21, 17, 14, 25, 22, 15, 23, 33, 32, 29, 37, 26, 31, 34, 30, 27, 38, 35, 28, 36, 7, 6, 3, 11, 0, 5, 8, 4, 1, 12, 9, 2, 10, 46, 45, 42, 50, 39, 44, 47, 43, 40, 51, 48, 41, 49], [24, 21, 20, 17, 25, 14, 19, 22, 18, 15, 13, 23, 16, 37, 34, 33, 30, 38, 27, 32, 35, 31, 28, 26, 36, 29, 11, 8, 7, 4, 12, 1, 6, 9, 5, 2, 0, 10, 3, 50, 47, 46, 43, 51, 40, 45, 48, 44, 41, 39, 49, 42], [17, 25, 22, 21, 18, 13, 15, 20, 23, 19, 16, 14, 24, 30, 38, 35, 34, 31, 26, 28, 33, 36, 32, 29, 27, 37, 4, 12, 9, 8, 5, 0, 2, 7, 10, 6, 3, 1, 11, 43, 51, 48, 47, 44, 39, 41, 46, 49, 45, 42, 40, 50], [25, 18, 13, 23, 22, 19, 14, 16, 21, 24, 20, 17, 15, 38, 31, 26, 36, 35, 32, 27, 29, 34, 37, 33, 30, 28, 12, 5, 0, 10, 9, 6, 1, 3, 8, 11, 7, 4, 2, 51, 44, 39, 49, 48, 45, 40, 42, 47, 50, 46, 43, 41], [16, 13, 19, 14, 24, 23, 20, 15, 17, 22, 25, 21, 18, 29, 26, 32, 27, 37, 36, 33, 28, 30, 35, 38, 34, 31, 3, 0, 6, 1, 11, 10, 7, 2, 4, 9, 12, 8, 5, 42, 39, 45, 40, 50, 49, 46, 41, 43, 48, 51, 47, 44], [19, 17, 14, 20, 15, 25, 24, 21, 16, 18, 23, 13, 22, 32, 30, 27, 33, 28, 38, 37, 34, 29, 31, 36, 26, 35, 6, 4, 1, 7, 2, 12, 11, 8, 3, 5, 10, 0, 9, 45, 43, 40, 46, 41, 51, 50, 47, 42, 44, 49, 39, 48], [23, 20, 18, 15, 21, 16, 13, 25, 22, 17, 19, 24, 14, 36, 33, 31, 28, 34, 29, 26, 38, 35, 30, 32, 37, 27, 10, 7, 5, 2, 8, 3, 0, 12, 9, 4, 6, 11, 1, 49, 46, 44, 41, 47, 42, 39, 51, 48, 43, 45, 50, 40], [15, 24, 21, 19, 16, 22, 17, 14, 13, 23, 18, 20, 25, 28, 37, 34, 32, 29, 35, 30, 27, 26, 36, 31, 33, 38, 2, 11, 8, 6, 3, 9, 4, 1, 0, 10, 5, 7, 12, 41, 50, 47, 45, 42, 48, 43, 40, 39, 49, 44, 46, 51]]} +RLMATH_EOF diff --git a/tasks/construct-mc-quasigroup-idempotent-l6-s2/tests/check.py b/tasks/construct-mc-quasigroup-idempotent-l6-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4563f2e9a90050cdd7c56dfc33831acde74c9ef2 --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-l6-s2/tests/check.py @@ -0,0 +1,21 @@ +"""Idempotent quasigroup satisfying QG3, (x*y)*(y*x) = x (MathConstraint quasigroup_idempotent, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + T = ans.get("table") + if not isinstance(T, list) or len(T) != n: + raise Invalid(f"table must be a list of {n} rows") + T = [int_list(r, n, 0, n - 1, "table row") for r in T] + full = list(range(n)) + for i in range(n): + if sorted(T[i]) != full or sorted(T[r][i] for r in range(n)) != full: + raise Invalid(f"row/column {i} is not a permutation (not a Latin square)") + if T[i][i] != i: + raise Invalid(f"not idempotent: {i}*{i} = {T[i][i]}") + for i in range(n): + for j in range(n): + if T[T[i][j]][T[j][i]] != i: + raise Invalid(f"QG3 fails for (x, y) = ({i}, {j})") + return None, {} diff --git a/tasks/construct-mc-quasigroup-idempotent-l6-s2/tests/instance.json b/tasks/construct-mc-quasigroup-idempotent-l6-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..47927855201bb5f399bc119accf411dd56fb2b79 --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-l6-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 52, "family": "mc_quasigroup_idempotent", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-quasigroup-idempotent-l6-s2/tests/run.py b/tasks/construct-mc-quasigroup-idempotent-l6-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-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-quasigroup-idempotent-l6-s2/tests/test.sh b/tasks/construct-mc-quasigroup-idempotent-l6-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-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-ramsey-l3-s9/environment/Dockerfile b/tasks/construct-mc-ramsey-l3-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-ramsey-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-mc-ramsey-l3-s9/environment/instance.json b/tasks/construct-mc-ramsey-l3-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b897e2a93952d18e87c2c40295f03d01c2c18819 --- /dev/null +++ b/tasks/construct-mc-ramsey-l3-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 15, "r": 3, "s": 6, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l3-s9/solution/solve.sh b/tasks/construct-mc-ramsey-l3-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..48596b67b11a93711cd9f7a91ff64be8c1fd1c80 --- /dev/null +++ b/tasks/construct-mc-ramsey-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' +{"colors": [0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-ramsey-l3-s9/tests/check.py b/tasks/construct-mc-ramsey-l3-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..53526c0bc87af6298219d3e1eac5f95f01b57541 --- /dev/null +++ b/tasks/construct-mc-ramsey-l3-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-l3-s9/tests/instance.json b/tasks/construct-mc-ramsey-l3-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b897e2a93952d18e87c2c40295f03d01c2c18819 --- /dev/null +++ b/tasks/construct-mc-ramsey-l3-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 15, "r": 3, "s": 6, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l3-s9/tests/run.py b/tasks/construct-mc-ramsey-l3-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-ramsey-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-mc-ramsey-l3-s9/tests/test.sh b/tasks/construct-mc-ramsey-l3-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-ramsey-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-mc-social-golfers-l2-s3/environment/Dockerfile b/tasks/construct-mc-social-golfers-l2-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-social-golfers-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-social-golfers-l2-s3/environment/instance.json b/tasks/construct-mc-social-golfers-l2-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..29a8e5a1b640eda8414036817e5c6733194ee604 --- /dev/null +++ b/tasks/construct-mc-social-golfers-l2-s3/environment/instance.json @@ -0,0 +1 @@ +{"n_groups": 8, "group_size": 4, "n_weeks": 6, "family": "mc_social_golfers", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-social-golfers-l2-s3/solution/solve.sh b/tasks/construct-mc-social-golfers-l2-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d259b16a34a9e90196d163d10e6e855d1af2fa47 --- /dev/null +++ b/tasks/construct-mc-social-golfers-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' +{"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], [3, 0, 1, 2, 7, 1, 2, 0, 1, 6, 0, 2, 6, 7, 5, 4, 7, 6, 4, 2, 5, 7, 0, 3, 4, 5, 3, 1, 5, 6, 4, 3], [5, 7, 3, 4, 0, 2, 5, 6, 6, 4, 3, 7, 5, 6, 1, 0, 5, 7, 4, 3, 7, 4, 2, 1, 6, 0, 2, 1, 3, 2, 1, 0], [1, 3, 0, 2, 5, 7, 3, 6, 3, 1, 5, 4, 7, 1, 3, 2, 4, 5, 0, 1, 2, 6, 0, 7, 4, 6, 2, 5, 7, 4, 6, 0], [7, 5, 6, 3, 2, 7, 6, 4, 2, 6, 7, 4, 5, 1, 7, 4, 3, 0, 1, 5, 2, 0, 3, 4, 0, 6, 1, 5, 1, 2, 3, 0], [4, 3, 0, 5, 4, 7, 6, 5, 1, 7, 2, 0, 2, 3, 0, 1, 7, 6, 2, 1, 2, 0, 1, 3, 4, 3, 6, 5, 4, 5, 6, 7]]} +RLMATH_EOF diff --git a/tasks/construct-mc-social-golfers-l2-s3/tests/check.py b/tasks/construct-mc-social-golfers-l2-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..73977815b7b6094a8491075b6dc2ae1293e44930 --- /dev/null +++ b/tasks/construct-mc-social-golfers-l2-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-l2-s3/tests/instance.json b/tasks/construct-mc-social-golfers-l2-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..29a8e5a1b640eda8414036817e5c6733194ee604 --- /dev/null +++ b/tasks/construct-mc-social-golfers-l2-s3/tests/instance.json @@ -0,0 +1 @@ +{"n_groups": 8, "group_size": 4, "n_weeks": 6, "family": "mc_social_golfers", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-social-golfers-l2-s3/tests/run.py b/tasks/construct-mc-social-golfers-l2-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-social-golfers-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-social-golfers-l2-s3/tests/test.sh b/tasks/construct-mc-social-golfers-l2-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-social-golfers-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-van-der-waerden-l3-s2/environment/Dockerfile b/tasks/construct-mc-van-der-waerden-l3-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l3-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-l3-s2/environment/instance.json b/tasks/construct-mc-van-der-waerden-l3-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..08f3760be4be7072ba7784b55f5b3c7b41855bb1 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l3-s2/environment/instance.json @@ -0,0 +1 @@ +{"k": 3, "L": 3, "n": 26, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l3-s2/solution/solve.sh b/tasks/construct-mc-van-der-waerden-l3-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c92a00e42b0c7a80d7133fc458dcdffffa0fe61a --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l3-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, 0, 2, 2, 1, 0, 0, 1, 0, 1, 2, 2, 1, 1, 2, 2, 1, 0, 1, 0, 0, 1, 2, 2, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-van-der-waerden-l3-s2/tests/check.py b/tasks/construct-mc-van-der-waerden-l3-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9853b089b6ac1773d80eac8e9e02ceb4019ad41f --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l3-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-l3-s2/tests/instance.json b/tasks/construct-mc-van-der-waerden-l3-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..08f3760be4be7072ba7784b55f5b3c7b41855bb1 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l3-s2/tests/instance.json @@ -0,0 +1 @@ +{"k": 3, "L": 3, "n": 26, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l3-s2/tests/run.py b/tasks/construct-mc-van-der-waerden-l3-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l3-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-l3-s2/tests/test.sh b/tasks/construct-mc-van-der-waerden-l3-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l3-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-l3-s5/environment/Dockerfile b/tasks/construct-mc-van-der-waerden-l3-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l3-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-l3-s5/environment/instance.json b/tasks/construct-mc-van-der-waerden-l3-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e64533be614c9427be3e1c58e8ab137aa2855c0d --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l3-s5/environment/instance.json @@ -0,0 +1 @@ +{"k": 2, "L": 4, "n": 34, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l3-s5/solution/solve.sh b/tasks/construct-mc-van-der-waerden-l3-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f7151564620ea4c4ba828be6de5e96d126c73af4 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l3-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, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-van-der-waerden-l3-s5/tests/check.py b/tasks/construct-mc-van-der-waerden-l3-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9853b089b6ac1773d80eac8e9e02ceb4019ad41f --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l3-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-l3-s5/tests/instance.json b/tasks/construct-mc-van-der-waerden-l3-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e64533be614c9427be3e1c58e8ab137aa2855c0d --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l3-s5/tests/instance.json @@ -0,0 +1 @@ +{"k": 2, "L": 4, "n": 34, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l3-s5/tests/run.py b/tasks/construct-mc-van-der-waerden-l3-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l3-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-l3-s5/tests/test.sh b/tasks/construct-mc-van-der-waerden-l3-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l3-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-l6-s3/environment/Dockerfile b/tasks/construct-mc-vertex-cover-l6-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-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-mc-vertex-cover-l6-s3/environment/instance.json b/tasks/construct-mc-vertex-cover-l6-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8b0fabeb716ac445d92914934b4890501d700a44 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l6-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 140, "k": 107, "edges": [[0, 1], [0, 25], [0, 26], [0, 31], [0, 47], [0, 55], [0, 57], [0, 59], [0, 67], [0, 80], [0, 101], [0, 112], [0, 119], [0, 127], [0, 131], [0, 135], [0, 136], [1, 2], [1, 9], [1, 15], [1, 25], [1, 27], [1, 31], [1, 34], [1, 45], [1, 49], [1, 51], [1, 52], [1, 63], [1, 68], [1, 77], [1, 98], [1, 104], [1, 105], [1, 115], [1, 118], [1, 123], [1, 127], [1, 129], [1, 132], [1, 135], [2, 11], [2, 12], [2, 17], [2, 18], [2, 28], [2, 30], [2, 34], [2, 37], [2, 43], [2, 46], [2, 50], [2, 54], [2, 69], [2, 96], [2, 99], [2, 117], [2, 131], [3, 15], [3, 16], [3, 29], [3, 30], [3, 33], [3, 45], [3, 48], [3, 64], [3, 79], [3, 83], [3, 88], [3, 93], [3, 96], [3, 106], [3, 107], [3, 114], [3, 124], [3, 134], [4, 8], [4, 16], [4, 19], [4, 29], [4, 49], [4, 50], [4, 56], [4, 59], [4, 61], [4, 63], [4, 64], [4, 66], [4, 69], [4, 73], [4, 77], [4, 99], [4, 106], [4, 107], [4, 108], [4, 111], [4, 113], [4, 123], [4, 126], [4, 138], [4, 139], [5, 7], [5, 13], [5, 22], [5, 25], [5, 28], [5, 33], [5, 34], [5, 36], [5, 47], [5, 49], [5, 56], [5, 58], [5, 65], [5, 71], [5, 78], [5, 79], [5, 90], [5, 99], [5, 101], [5, 118], [5, 136], [5, 139], [6, 24], [6, 31], [6, 42], [6, 52], [6, 90], [6, 92], [6, 95], [6, 110], [6, 115], [6, 121], [6, 128], [6, 132], [6, 135], [7, 17], [7, 26], [7, 38], [7, 51], [7, 59], [7, 89], [7, 90], [7, 93], [7, 96], [7, 113], [7, 120], [7, 125], [7, 136], [8, 25], [8, 33], [8, 46], [8, 57], [8, 61], [8, 74], [8, 77], [8, 95], [8, 97], [8, 108], [8, 109], [8, 115], [8, 122], [8, 124], [8, 125], [8, 128], [8, 130], [8, 133], [9, 10], [9, 15], [9, 19], [9, 26], [9, 31], [9, 44], [9, 45], [9, 52], [9, 54], [9, 63], [9, 87], [9, 88], [9, 89], [9, 99], [9, 111], [9, 112], [9, 113], [9, 117], [9, 119], [9, 123], [9, 127], [9, 133], [10, 22], [10, 31], [10, 34], [10, 57], [10, 74], [10, 81], [10, 83], [10, 96], [10, 98], [10, 127], [10, 131], [11, 14], [11, 17], [11, 19], [11, 31], [11, 34], [11, 50], [11, 52], [11, 53], [11, 54], [11, 61], [11, 62], [11, 68], [11, 81], [11, 85], [11, 87], [11, 92], [11, 112], [11, 125], [11, 126], [11, 139], [12, 16], [12, 26], [12, 32], [12, 49], [12, 60], [12, 76], [12, 83], [12, 87], [12, 91], [12, 94], [12, 101], [12, 104], [12, 110], [12, 126], [12, 130], [12, 132], [12, 138], [13, 26], [13, 29], [13, 33], [13, 46], [13, 47], [13, 54], [13, 57], [13, 69], [13, 70], [13, 77], [13, 88], [13, 105], [13, 108], [13, 115], [13, 125], [13, 135], [14, 15], [14, 17], [14, 22], [14, 34], [14, 37], [14, 46], [14, 49], [14, 50], [14, 59], [14, 66], [14, 67], [14, 71], [14, 72], [14, 92], [14, 93], [14, 95], [14, 112], [14, 113], [14, 114], [14, 125], [14, 126], [15, 18], [15, 26], [15, 31], [15, 33], [15, 35], [15, 36], [15, 44], [15, 49], [15, 63], [15, 71], [15, 73], [15, 75], [15, 85], [15, 93], [15, 96], [15, 97], [15, 106], [15, 107], [15, 123], [15, 126], [15, 139], [16, 31], [16, 39], [16, 45], [16, 51], [16, 52], [16, 56], [16, 65], [16, 69], [16, 92], [16, 93], [16, 113], [16, 123], [16, 131], [16, 133], [17, 27], [17, 29], [17, 38], [17, 55], [17, 56], [17, 68], [17, 69], [17, 91], [17, 115], [17, 139], [18, 22], [18, 35], [18, 38], [18, 61], [18, 85], [18, 101], [18, 108], [18, 113], [18, 117], [18, 124], [19, 24], [19, 25], [19, 30], [19, 38], [19, 39], [19, 42], [19, 45], [19, 51], [19, 52], [19, 68], [19, 74], [19, 78], [19, 87], [19, 90], [19, 99], [19, 103], [19, 108], [19, 109], [19, 112], [19, 113], [19, 124], [19, 133], [19, 137], [20, 57], [20, 63], [20, 64], [20, 67], [20, 71], [20, 76], [20, 100], [20, 109], [20, 110], [20, 115], [20, 127], [20, 133], [20, 135], [20, 139], [21, 27], [21, 30], [21, 52], [21, 59], [21, 68], [21, 74], [21, 90], [21, 101], [21, 115], [21, 127], [21, 133], [21, 134], [22, 45], [22, 50], [22, 51], [22, 54], [22, 55], [22, 56], [22, 58], [22, 64], [22, 76], [22, 79], [22, 103], [22, 106], [22, 108], [22, 111], [22, 116], [22, 132], [22, 133], [22, 138], [23, 26], [23, 51], [23, 55], [23, 65], [23, 70], [23, 72], [23, 74], [23, 83], [23, 91], [23, 97], [23, 109], [23, 122], [24, 30], [24, 32], [24, 46], [24, 51], [24, 66], [24, 75], [24, 81], [24, 85], [24, 86], [24, 89], [24, 95], [24, 98], [24, 102], [24, 108], [24, 117], [24, 124], [24, 125], [24, 132], [25, 37], [25, 45], [25, 47], [25, 48], [25, 61], [25, 65], [25, 75], [25, 82], [25, 99], [25, 103], [25, 107], [25, 126], [25, 129], [25, 139], [26, 35], [26, 49], [26, 54], [26, 59], [26, 72], [26, 78], [26, 85], [26, 86], [26, 90], [26, 93], [26, 95], [26, 96], [26, 102], [26, 106], [26, 125], [26, 138], [26, 139], [27, 30], [27, 40], [27, 49], [27, 54], [27, 64], [27, 66], [27, 67], [27, 68], [27, 69], [27, 72], [27, 79], [27, 86], [27, 97], [27, 108], [27, 110], [27, 126], [27, 127], [27, 128], [27, 132], [27, 134], [28, 30], [28, 31], [28, 40], [28, 43], [28, 49], [28, 62], [28, 64], [28, 65], [28, 69], [28, 85], [28, 86], [28, 98], [28, 104], [28, 106], [28, 119], [28, 121], [28, 122], [28, 133], [29, 43], [29, 47], [29, 49], [29, 50], [29, 66], [29, 70], [29, 71], [29, 78], [29, 89], [29, 101], [29, 103], [29, 110], [29, 114], [29, 118], [29, 120], [29, 128], [29, 134], [29, 137], [30, 31], [30, 53], [30, 68], [30, 80], [30, 85], [30, 89], [30, 105], [30, 106], [30, 115], [30, 122], [30, 130], [30, 132], [31, 33], [31, 35], [31, 36], [31, 55], [31, 57], [31, 68], [31, 76], [31, 78], [31, 82], [31, 87], [31, 94], [31, 99], [31, 102], [31, 109], [31, 116], [31, 124], [31, 125], [31, 134], [32, 34], [32, 47], [32, 48], [32, 54], [32, 59], [32, 69], [32, 73], [32, 91], [32, 109], [32, 113], [32, 115], [32, 116], [32, 133], [32, 134], [33, 37], [33, 51], [33, 60], [33, 71], [33, 73], [33, 74], [33, 76], [33, 79], [33, 84], [33, 89], [33, 93], [33, 106], [33, 108], [33, 117], [33, 118], [33, 127], [33, 134], [33, 135], [34, 37], [34, 38], [34, 49], [34, 56], [34, 61], [34, 62], [34, 70], [34, 71], [34, 109], [34, 114], [34, 117], [34, 120], [34, 127], [34, 131], [34, 138], [35, 52], [35, 55], [35, 60], [35, 76], [35, 80], [35, 87], [35, 97], [35, 111], [35, 119], [35, 132], [36, 60], [36, 64], [36, 67], [36, 69], [36, 71], [36, 92], [36, 98], [36, 109], [36, 121], [37, 38], [37, 72], [37, 95], [37, 96], [37, 104], [37, 112], [37, 115], [37, 125], [37, 127], [37, 138], [38, 50], [38, 54], [38, 58], [38, 62], [38, 64], [38, 83], [38, 86], [38, 92], [38, 118], [38, 121], [38, 129], [38, 136], [39, 42], [39, 43], [39, 45], [39, 62], [39, 70], [39, 73], [39, 81], [39, 98], [39, 102], [39, 104], [39, 105], [39, 109], [39, 110], [39, 113], [39, 121], [39, 128], [39, 133], [40, 42], [40, 64], [40, 65], [40, 66], [40, 70], [40, 80], [40, 81], [40, 93], [40, 98], [40, 103], [40, 116], [40, 125], [40, 132], [41, 42], [41, 45], [41, 50], [41, 51], [41, 52], [41, 53], [41, 59], [41, 62], [41, 63], [41, 67], [41, 70], [41, 71], [41, 72], [41, 78], [41, 106], [41, 118], [41, 120], [41, 122], [41, 127], [41, 128], [41, 138], [42, 54], [42, 62], [42, 63], [42, 68], [42, 82], [42, 86], [42, 89], [42, 93], [42, 95], [42, 97], [42, 98], [42, 104], [42, 106], [42, 117], [42, 119], [42, 120], [42, 124], [42, 125], [42, 126], [43, 44], [43, 46], [43, 49], [43, 51], [43, 53], [43, 57], [43, 64], [43, 66], [43, 82], [43, 83], [43, 91], [43, 102], [43, 103], [43, 111], [43, 122], [43, 130], [43, 131], [43, 132], [43, 136], [44, 62], [44, 65], [44, 90], [44, 93], [44, 97], [44, 99], [44, 109], [44, 112], [44, 114], [44, 121], [44, 130], [44, 135], [45, 48], [45, 72], [45, 76], [45, 80], [45, 88], [45, 90], [45, 95], [45, 96], [45, 101], [45, 110], [45, 112], [45, 123], [45, 127], [45, 129], [46, 61], [46, 62], [46, 70], [46, 79], [46, 81], [46, 85], [46, 89], [46, 93], [46, 95], [46, 105], [46, 108], [46, 109], [46, 132], [47, 48], [47, 51], [47, 54], [47, 61], [47, 79], [47, 84], [47, 87], [47, 88], [47, 95], [47, 106], [47, 112], [47, 114], [47, 123], [47, 128], [47, 130], [47, 138], [48, 52], [48, 55], [48, 56], [48, 65], [48, 66], [48, 68], [48, 69], [48, 77], [48, 99], [48, 100], [48, 112], [48, 113], [48, 114], [48, 116], [48, 119], [48, 130], [48, 132], [49, 54], [49, 57], [49, 60], [49, 61], [49, 89], [49, 96], [49, 102], [49, 110], [49, 119], [49, 125], [50, 54], [50, 77], [50, 92], [50, 93], [50, 114], [50, 135], [51, 59], [51, 66], [51, 70], [51, 88], [51, 102], [51, 105], [51, 108], [51, 123], [51, 126], [51, 128], [51, 131], [51, 135], [51, 139], [52, 68], [52, 73], [52, 74], [52, 78], [52, 93], [52, 97], [52, 102], [52, 111], [52, 114], [52, 116], [52, 129], [52, 133], [52, 134], [52, 137], [53, 55], [53, 102], [53, 111], [53, 114], [53, 119], [53, 130], [54, 63], [54, 64], [54, 69], [54, 91], [54, 103], [54, 108], [54, 111], [54, 112], [54, 114], [54, 121], [54, 122], [55, 59], [55, 65], [55, 66], [55, 76], [55, 77], [55, 91], [55, 100], [55, 118], [55, 122], [55, 126], [55, 132], [56, 60], [56, 77], [56, 84], [56, 85], [56, 87], [56, 89], [56, 90], [56, 91], [56, 93], [56, 101], [56, 107], [56, 123], [57, 61], [57, 62], [57, 76], [57, 89], [57, 90], [57, 98], [57, 108], [57, 117], [57, 120], [57, 122], [58, 59], [58, 80], [58, 87], [58, 88], [58, 92], [58, 100], [58, 104], [58, 112], [58, 113], [58, 128], [58, 134], [59, 72], [59, 79], [59, 81], [59, 83], [59, 96], [59, 97], [59, 118], [59, 134], [59, 137], [60, 61], [60, 96], [60, 111], [60, 112], [60, 117], [60, 122], [60, 128], [60, 135], [61, 65], [61, 72], [61, 79], [61, 89], [61, 91], [61, 92], [61, 94], [61, 95], [61, 103], [61, 104], [61, 110], [61, 115], [61, 117], [61, 122], [61, 126], [61, 129], [62, 75], [62, 80], [62, 86], [62, 92], [62, 93], [62, 94], [62, 96], [62, 97], [62, 100], [62, 104], [62, 106], [62, 117], [62, 118], [62, 119], [62, 130], [62, 132], [62, 139], [63, 64], [63, 73], [63, 84], [63, 90], [63, 92], [63, 106], [63, 109], [63, 118], [63, 136], [63, 137], [64, 76], [64, 78], [64, 79], [64, 82], [64, 107], [64, 125], [64, 129], [64, 131], [64, 132], [65, 70], [65, 80], [65, 87], [65, 97], [65, 104], [65, 110], [65, 117], [65, 120], [65, 121], [65, 130], [65, 132], [65, 135], [65, 137], [65, 139], [66, 76], [66, 101], [66, 104], [66, 105], [66, 107], [66, 116], [66, 120], [66, 123], [66, 126], [66, 127], [66, 129], [66, 135], [67, 84], [67, 92], [67, 123], [67, 126], [68, 70], [68, 75], [68, 78], [68, 90], [68, 92], [68, 96], [68, 99], [68, 105], [68, 109], [68, 114], [68, 124], [68, 130], [69, 70], [69, 87], [69, 88], [69, 97], [69, 98], [69, 99], [69, 108], [69, 110], [69, 121], [69, 130], [69, 131], [69, 136], [70, 75], [70, 95], [70, 97], [70, 104], [70, 107], [70, 109], [70, 112], [70, 115], [70, 116], [70, 124], [70, 126], [70, 133], [71, 76], [71, 88], [71, 89], [71, 102], [71, 112], [71, 115], [71, 135], [72, 75], [72, 81], [72, 86], [72, 128], [72, 131], [73, 82], [73, 88], [73, 93], [73, 99], [73, 104], [73, 112], [73, 113], [74, 76], [74, 87], [74, 94], [74, 100], [74, 104], [74, 105], [74, 110], [74, 112], [74, 122], [74, 125], [74, 126], [74, 127], [74, 132], [74, 138], [75, 76], [75, 82], [75, 90], [75, 98], [75, 108], [75, 110], [75, 122], [75, 124], [75, 134], [75, 135], [76, 80], [76, 81], [76, 85], [76, 100], [76, 111], [76, 125], [76, 127], [77, 80], [77, 82], [77, 109], [77, 115], [77, 116], [77, 124], [77, 127], [77, 131], [77, 135], [77, 136], [78, 82], [78, 84], [78, 86], [78, 91], [78, 100], [78, 103], [78, 109], [78, 114], [78, 118], [78, 123], [78, 127], [78, 130], [78, 135], [78, 136], [79, 83], [79, 96], [79, 97], [79, 102], [79, 104], [79, 115], [79, 130], [80, 106], [80, 107], [80, 129], [80, 139], [81, 90], [81, 103], [81, 105], [81, 125], [81, 134], [81, 135], [82, 97], [82, 99], [82, 105], [82, 108], [82, 126], [82, 130], [82, 135], [83, 84], [83, 87], [83, 94], [83, 97], [83, 101], [83, 111], [83, 113], [83, 114], [83, 121], [83, 123], [83, 129], [83, 130], [83, 131], [83, 132], [83, 136], [83, 138], [84, 116], [84, 122], [84, 127], [84, 139], [85, 99], [85, 100], [85, 103], [85, 115], [85, 119], [85, 128], [85, 131], [85, 132], [86, 100], [86, 101], [86, 117], [86, 121], [86, 134], [86, 135], [87, 94], [87, 95], [87, 96], [87, 102], [87, 103], [87, 109], [87, 114], [87, 116], [87, 118], [87, 122], [87, 128], [87, 130], [87, 131], [87, 132], [87, 134], [88, 105], [88, 106], [88, 107], [88, 113], [88, 114], [88, 118], [88, 119], [88, 122], [88, 123], [88, 124], [88, 127], [88, 131], [88, 133], [88, 136], [89, 92], [89, 93], [89, 96], [89, 105], [89, 113], [89, 123], [89, 125], [89, 128], [89, 133], [90, 96], [90, 97], [90, 121], [90, 125], [90, 126], [90, 132], [90, 135], [90, 139], [91, 96], [91, 108], [91, 110], [91, 112], [91, 113], [91, 117], [91, 119], [91, 127], [91, 129], [91, 137], [92, 95], [92, 105], [92, 106], [92, 111], [92, 115], [92, 116], [92, 119], [92, 134], [93, 95], [93, 101], [93, 104], [93, 108], [93, 131], [94, 99], [94, 110], [94, 112], [94, 127], [94, 128], [94, 132], [94, 135], [94, 137], [94, 139], [95, 97], [95, 104], [95, 114], [95, 115], [95, 136], [96, 100], [96, 110], [96, 114], [96, 116], [96, 121], [97, 102], [97, 111], [97, 114], [97, 115], [97, 116], [97, 123], [97, 133], [97, 136], [97, 137], [98, 101], [98, 103], [98, 106], [98, 107], [98, 124], [98, 125], [99, 106], [99, 108], [99, 116], [99, 121], [99, 125], [99, 126], [99, 128], [99, 134], [100, 108], [100, 113], [100, 120], [100, 125], [100, 129], [100, 133], [101, 105], [101, 106], [101, 107], [101, 109], [101, 116], [101, 118], [101, 127], [101, 130], [101, 136], [102, 111], [102, 115], [102, 129], [102, 135], [103, 104], [103, 119], [103, 124], [103, 135], [104, 113], [104, 117], [104, 119], [104, 139], [105, 110], [105, 112], [105, 114], [105, 121], [105, 124], [105, 126], [105, 127], [105, 135], [106, 111], [106, 116], [106, 121], [106, 131], [106, 132], [106, 135], [106, 139], [107, 109], [107, 117], [107, 127], [107, 128], [107, 130], [107, 138], [108, 122], [108, 130], [108, 138], [109, 114], [109, 119], [109, 134], [109, 139], [110, 111], [110, 130], [110, 136], [110, 137], [111, 128], [111, 132], [112, 120], [112, 131], [112, 135], [112, 139], [113, 131], [114, 120], [114, 121], [114, 125], [114, 127], [115, 120], [115, 121], [115, 122], [115, 123], [115, 135], [116, 120], [116, 124], [116, 136], [117, 118], [118, 122], [118, 130], [118, 137], [119, 121], [119, 122], [119, 123], [119, 132], [119, 134], [120, 133], [120, 137], [121, 124], [121, 126], [121, 129], [121, 137], [122, 125], [122, 128], [122, 134], [122, 135], [122, 136], [123, 124], [123, 125], [123, 132], [124, 130], [124, 131], [124, 136], [125, 127], [125, 134], [127, 136], [128, 132], [128, 136], [129, 135], [131, 134], [132, 135], [132, 137], [135, 136], [135, 137]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l6-s3/solution/solve.sh b/tasks/construct-mc-vertex-cover-l6-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ac2f672e6b96c68468acc458f57cfe05c76fd66f --- /dev/null +++ b/tasks/construct-mc-vertex-cover-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' +{"cover": [0, 1, 2, 3, 4, 5, 7, 9, 11, 12, 14, 15, 18, 22, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 37, 38, 39, 41, 42, 43, 45, 46, 47, 51, 52, 54, 55, 56, 57, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 74, 76, 77, 78, 80, 81, 82, 83, 87, 88, 89, 90, 91, 92, 93, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 119, 121, 122, 123, 124, 125, 127, 128, 130, 131, 132, 133, 134, 135, 137, 138, 139]} +RLMATH_EOF diff --git a/tasks/construct-mc-vertex-cover-l6-s3/tests/check.py b/tasks/construct-mc-vertex-cover-l6-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3accb3da1c773fd2126b8b5b0a97b099e29c83b --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l6-s3/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-l6-s3/tests/instance.json b/tasks/construct-mc-vertex-cover-l6-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8b0fabeb716ac445d92914934b4890501d700a44 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l6-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 140, "k": 107, "edges": [[0, 1], [0, 25], [0, 26], [0, 31], [0, 47], [0, 55], [0, 57], [0, 59], [0, 67], [0, 80], [0, 101], [0, 112], [0, 119], [0, 127], [0, 131], [0, 135], [0, 136], [1, 2], [1, 9], [1, 15], [1, 25], [1, 27], [1, 31], [1, 34], [1, 45], [1, 49], [1, 51], [1, 52], [1, 63], [1, 68], [1, 77], [1, 98], [1, 104], [1, 105], [1, 115], [1, 118], [1, 123], [1, 127], [1, 129], [1, 132], [1, 135], [2, 11], [2, 12], [2, 17], [2, 18], [2, 28], [2, 30], [2, 34], [2, 37], [2, 43], [2, 46], [2, 50], [2, 54], [2, 69], [2, 96], [2, 99], [2, 117], [2, 131], [3, 15], [3, 16], [3, 29], [3, 30], [3, 33], [3, 45], [3, 48], [3, 64], [3, 79], [3, 83], [3, 88], [3, 93], [3, 96], [3, 106], [3, 107], [3, 114], [3, 124], [3, 134], [4, 8], [4, 16], [4, 19], [4, 29], [4, 49], [4, 50], [4, 56], [4, 59], [4, 61], [4, 63], [4, 64], [4, 66], [4, 69], [4, 73], [4, 77], [4, 99], [4, 106], [4, 107], [4, 108], [4, 111], [4, 113], [4, 123], [4, 126], [4, 138], [4, 139], [5, 7], [5, 13], [5, 22], [5, 25], [5, 28], [5, 33], [5, 34], [5, 36], [5, 47], [5, 49], [5, 56], [5, 58], [5, 65], [5, 71], [5, 78], [5, 79], [5, 90], [5, 99], [5, 101], [5, 118], [5, 136], [5, 139], [6, 24], [6, 31], [6, 42], [6, 52], [6, 90], [6, 92], [6, 95], [6, 110], [6, 115], [6, 121], [6, 128], [6, 132], [6, 135], [7, 17], [7, 26], [7, 38], [7, 51], [7, 59], [7, 89], [7, 90], [7, 93], [7, 96], [7, 113], [7, 120], [7, 125], [7, 136], [8, 25], [8, 33], [8, 46], [8, 57], [8, 61], [8, 74], [8, 77], [8, 95], [8, 97], [8, 108], [8, 109], [8, 115], [8, 122], [8, 124], [8, 125], [8, 128], [8, 130], [8, 133], [9, 10], [9, 15], [9, 19], [9, 26], [9, 31], [9, 44], [9, 45], [9, 52], [9, 54], [9, 63], [9, 87], [9, 88], [9, 89], [9, 99], [9, 111], [9, 112], [9, 113], [9, 117], [9, 119], [9, 123], [9, 127], [9, 133], [10, 22], [10, 31], [10, 34], [10, 57], [10, 74], [10, 81], [10, 83], [10, 96], [10, 98], [10, 127], [10, 131], [11, 14], [11, 17], [11, 19], [11, 31], [11, 34], [11, 50], [11, 52], [11, 53], [11, 54], [11, 61], [11, 62], [11, 68], [11, 81], [11, 85], [11, 87], [11, 92], [11, 112], [11, 125], [11, 126], [11, 139], [12, 16], [12, 26], [12, 32], [12, 49], [12, 60], [12, 76], [12, 83], [12, 87], [12, 91], [12, 94], [12, 101], [12, 104], [12, 110], [12, 126], [12, 130], [12, 132], [12, 138], [13, 26], [13, 29], [13, 33], [13, 46], [13, 47], [13, 54], [13, 57], [13, 69], [13, 70], [13, 77], [13, 88], [13, 105], [13, 108], [13, 115], [13, 125], [13, 135], [14, 15], [14, 17], [14, 22], [14, 34], [14, 37], [14, 46], [14, 49], [14, 50], [14, 59], [14, 66], [14, 67], [14, 71], [14, 72], [14, 92], [14, 93], [14, 95], [14, 112], [14, 113], [14, 114], [14, 125], [14, 126], [15, 18], [15, 26], [15, 31], [15, 33], [15, 35], [15, 36], [15, 44], [15, 49], [15, 63], [15, 71], [15, 73], [15, 75], [15, 85], [15, 93], [15, 96], [15, 97], [15, 106], [15, 107], [15, 123], [15, 126], [15, 139], [16, 31], [16, 39], [16, 45], [16, 51], [16, 52], [16, 56], [16, 65], [16, 69], [16, 92], [16, 93], [16, 113], [16, 123], [16, 131], [16, 133], [17, 27], [17, 29], [17, 38], [17, 55], [17, 56], [17, 68], [17, 69], [17, 91], [17, 115], [17, 139], [18, 22], [18, 35], [18, 38], [18, 61], [18, 85], [18, 101], [18, 108], [18, 113], [18, 117], [18, 124], [19, 24], [19, 25], [19, 30], [19, 38], [19, 39], [19, 42], [19, 45], [19, 51], [19, 52], [19, 68], [19, 74], [19, 78], [19, 87], [19, 90], [19, 99], [19, 103], [19, 108], [19, 109], [19, 112], [19, 113], [19, 124], [19, 133], [19, 137], [20, 57], [20, 63], [20, 64], [20, 67], [20, 71], [20, 76], [20, 100], [20, 109], [20, 110], [20, 115], [20, 127], [20, 133], [20, 135], [20, 139], [21, 27], [21, 30], [21, 52], [21, 59], [21, 68], [21, 74], [21, 90], [21, 101], [21, 115], [21, 127], [21, 133], [21, 134], [22, 45], [22, 50], [22, 51], [22, 54], [22, 55], [22, 56], [22, 58], [22, 64], [22, 76], [22, 79], [22, 103], [22, 106], [22, 108], [22, 111], [22, 116], [22, 132], [22, 133], [22, 138], [23, 26], [23, 51], [23, 55], [23, 65], [23, 70], [23, 72], [23, 74], [23, 83], [23, 91], [23, 97], [23, 109], [23, 122], [24, 30], [24, 32], [24, 46], [24, 51], [24, 66], [24, 75], [24, 81], [24, 85], [24, 86], [24, 89], [24, 95], [24, 98], [24, 102], [24, 108], [24, 117], [24, 124], [24, 125], [24, 132], [25, 37], [25, 45], [25, 47], [25, 48], [25, 61], [25, 65], [25, 75], [25, 82], [25, 99], [25, 103], [25, 107], [25, 126], [25, 129], [25, 139], [26, 35], [26, 49], [26, 54], [26, 59], [26, 72], [26, 78], [26, 85], [26, 86], [26, 90], [26, 93], [26, 95], [26, 96], [26, 102], [26, 106], [26, 125], [26, 138], [26, 139], [27, 30], [27, 40], [27, 49], [27, 54], [27, 64], [27, 66], [27, 67], [27, 68], [27, 69], [27, 72], [27, 79], [27, 86], [27, 97], [27, 108], [27, 110], [27, 126], [27, 127], [27, 128], [27, 132], [27, 134], [28, 30], [28, 31], [28, 40], [28, 43], [28, 49], [28, 62], [28, 64], [28, 65], [28, 69], [28, 85], [28, 86], [28, 98], [28, 104], [28, 106], [28, 119], [28, 121], [28, 122], [28, 133], [29, 43], [29, 47], [29, 49], [29, 50], [29, 66], [29, 70], [29, 71], [29, 78], [29, 89], [29, 101], [29, 103], [29, 110], [29, 114], [29, 118], [29, 120], [29, 128], [29, 134], [29, 137], [30, 31], [30, 53], [30, 68], [30, 80], [30, 85], [30, 89], [30, 105], [30, 106], [30, 115], [30, 122], [30, 130], [30, 132], [31, 33], [31, 35], [31, 36], [31, 55], [31, 57], [31, 68], [31, 76], [31, 78], [31, 82], [31, 87], [31, 94], [31, 99], [31, 102], [31, 109], [31, 116], [31, 124], [31, 125], [31, 134], [32, 34], [32, 47], [32, 48], [32, 54], [32, 59], [32, 69], [32, 73], [32, 91], [32, 109], [32, 113], [32, 115], [32, 116], [32, 133], [32, 134], [33, 37], [33, 51], [33, 60], [33, 71], [33, 73], [33, 74], [33, 76], [33, 79], [33, 84], [33, 89], [33, 93], [33, 106], [33, 108], [33, 117], [33, 118], [33, 127], [33, 134], [33, 135], [34, 37], [34, 38], [34, 49], [34, 56], [34, 61], [34, 62], [34, 70], [34, 71], [34, 109], [34, 114], [34, 117], [34, 120], [34, 127], [34, 131], [34, 138], [35, 52], [35, 55], [35, 60], [35, 76], [35, 80], [35, 87], [35, 97], [35, 111], [35, 119], [35, 132], [36, 60], [36, 64], [36, 67], [36, 69], [36, 71], [36, 92], [36, 98], [36, 109], [36, 121], [37, 38], [37, 72], [37, 95], [37, 96], [37, 104], [37, 112], [37, 115], [37, 125], [37, 127], [37, 138], [38, 50], [38, 54], [38, 58], [38, 62], [38, 64], [38, 83], [38, 86], [38, 92], [38, 118], [38, 121], [38, 129], [38, 136], [39, 42], [39, 43], [39, 45], [39, 62], [39, 70], [39, 73], [39, 81], [39, 98], [39, 102], [39, 104], [39, 105], [39, 109], [39, 110], [39, 113], [39, 121], [39, 128], [39, 133], [40, 42], [40, 64], [40, 65], [40, 66], [40, 70], [40, 80], [40, 81], [40, 93], [40, 98], [40, 103], [40, 116], [40, 125], [40, 132], [41, 42], [41, 45], [41, 50], [41, 51], [41, 52], [41, 53], [41, 59], [41, 62], [41, 63], [41, 67], [41, 70], [41, 71], [41, 72], [41, 78], [41, 106], [41, 118], [41, 120], [41, 122], [41, 127], [41, 128], [41, 138], [42, 54], [42, 62], [42, 63], [42, 68], [42, 82], [42, 86], [42, 89], [42, 93], [42, 95], [42, 97], [42, 98], [42, 104], [42, 106], [42, 117], [42, 119], [42, 120], [42, 124], [42, 125], [42, 126], [43, 44], [43, 46], [43, 49], [43, 51], [43, 53], [43, 57], [43, 64], [43, 66], [43, 82], [43, 83], [43, 91], [43, 102], [43, 103], [43, 111], [43, 122], [43, 130], [43, 131], [43, 132], [43, 136], [44, 62], [44, 65], [44, 90], [44, 93], [44, 97], [44, 99], [44, 109], [44, 112], [44, 114], [44, 121], [44, 130], [44, 135], [45, 48], [45, 72], [45, 76], [45, 80], [45, 88], [45, 90], [45, 95], [45, 96], [45, 101], [45, 110], [45, 112], [45, 123], [45, 127], [45, 129], [46, 61], [46, 62], [46, 70], [46, 79], [46, 81], [46, 85], [46, 89], [46, 93], [46, 95], [46, 105], [46, 108], [46, 109], [46, 132], [47, 48], [47, 51], [47, 54], [47, 61], [47, 79], [47, 84], [47, 87], [47, 88], [47, 95], [47, 106], [47, 112], [47, 114], [47, 123], [47, 128], [47, 130], [47, 138], [48, 52], [48, 55], [48, 56], [48, 65], [48, 66], [48, 68], [48, 69], [48, 77], [48, 99], [48, 100], [48, 112], [48, 113], [48, 114], [48, 116], [48, 119], [48, 130], [48, 132], [49, 54], [49, 57], [49, 60], [49, 61], [49, 89], [49, 96], [49, 102], [49, 110], [49, 119], [49, 125], [50, 54], [50, 77], [50, 92], [50, 93], [50, 114], [50, 135], [51, 59], [51, 66], [51, 70], [51, 88], [51, 102], [51, 105], [51, 108], [51, 123], [51, 126], [51, 128], [51, 131], [51, 135], [51, 139], [52, 68], [52, 73], [52, 74], [52, 78], [52, 93], [52, 97], [52, 102], [52, 111], [52, 114], [52, 116], [52, 129], [52, 133], [52, 134], [52, 137], [53, 55], [53, 102], [53, 111], [53, 114], [53, 119], [53, 130], [54, 63], [54, 64], [54, 69], [54, 91], [54, 103], [54, 108], [54, 111], [54, 112], [54, 114], [54, 121], [54, 122], [55, 59], [55, 65], [55, 66], [55, 76], [55, 77], [55, 91], [55, 100], [55, 118], [55, 122], [55, 126], [55, 132], [56, 60], [56, 77], [56, 84], [56, 85], [56, 87], [56, 89], [56, 90], [56, 91], [56, 93], [56, 101], [56, 107], [56, 123], [57, 61], [57, 62], [57, 76], [57, 89], [57, 90], [57, 98], [57, 108], [57, 117], [57, 120], [57, 122], [58, 59], [58, 80], [58, 87], [58, 88], [58, 92], [58, 100], [58, 104], [58, 112], [58, 113], [58, 128], [58, 134], [59, 72], [59, 79], [59, 81], [59, 83], [59, 96], [59, 97], [59, 118], [59, 134], [59, 137], [60, 61], [60, 96], [60, 111], [60, 112], [60, 117], [60, 122], [60, 128], [60, 135], [61, 65], [61, 72], [61, 79], [61, 89], [61, 91], [61, 92], [61, 94], [61, 95], [61, 103], [61, 104], [61, 110], [61, 115], [61, 117], [61, 122], [61, 126], [61, 129], [62, 75], [62, 80], [62, 86], [62, 92], [62, 93], [62, 94], [62, 96], [62, 97], [62, 100], [62, 104], [62, 106], [62, 117], [62, 118], [62, 119], [62, 130], [62, 132], [62, 139], [63, 64], [63, 73], [63, 84], [63, 90], [63, 92], [63, 106], [63, 109], [63, 118], [63, 136], [63, 137], [64, 76], [64, 78], [64, 79], [64, 82], [64, 107], [64, 125], [64, 129], [64, 131], [64, 132], [65, 70], [65, 80], [65, 87], [65, 97], [65, 104], [65, 110], [65, 117], [65, 120], [65, 121], [65, 130], [65, 132], [65, 135], [65, 137], [65, 139], [66, 76], [66, 101], [66, 104], [66, 105], [66, 107], [66, 116], [66, 120], [66, 123], [66, 126], [66, 127], [66, 129], [66, 135], [67, 84], [67, 92], [67, 123], [67, 126], [68, 70], [68, 75], [68, 78], [68, 90], [68, 92], [68, 96], [68, 99], [68, 105], [68, 109], [68, 114], [68, 124], [68, 130], [69, 70], [69, 87], [69, 88], [69, 97], [69, 98], [69, 99], [69, 108], [69, 110], [69, 121], [69, 130], [69, 131], [69, 136], [70, 75], [70, 95], [70, 97], [70, 104], [70, 107], [70, 109], [70, 112], [70, 115], [70, 116], [70, 124], [70, 126], [70, 133], [71, 76], [71, 88], [71, 89], [71, 102], [71, 112], [71, 115], [71, 135], [72, 75], [72, 81], [72, 86], [72, 128], [72, 131], [73, 82], [73, 88], [73, 93], [73, 99], [73, 104], [73, 112], [73, 113], [74, 76], [74, 87], [74, 94], [74, 100], [74, 104], [74, 105], [74, 110], [74, 112], [74, 122], [74, 125], [74, 126], [74, 127], [74, 132], [74, 138], [75, 76], [75, 82], [75, 90], [75, 98], [75, 108], [75, 110], [75, 122], [75, 124], [75, 134], [75, 135], [76, 80], [76, 81], [76, 85], [76, 100], [76, 111], [76, 125], [76, 127], [77, 80], [77, 82], [77, 109], [77, 115], [77, 116], [77, 124], [77, 127], [77, 131], [77, 135], [77, 136], [78, 82], [78, 84], [78, 86], [78, 91], [78, 100], [78, 103], [78, 109], [78, 114], [78, 118], [78, 123], [78, 127], [78, 130], [78, 135], [78, 136], [79, 83], [79, 96], [79, 97], [79, 102], [79, 104], [79, 115], [79, 130], [80, 106], [80, 107], [80, 129], [80, 139], [81, 90], [81, 103], [81, 105], [81, 125], [81, 134], [81, 135], [82, 97], [82, 99], [82, 105], [82, 108], [82, 126], [82, 130], [82, 135], [83, 84], [83, 87], [83, 94], [83, 97], [83, 101], [83, 111], [83, 113], [83, 114], [83, 121], [83, 123], [83, 129], [83, 130], [83, 131], [83, 132], [83, 136], [83, 138], [84, 116], [84, 122], [84, 127], [84, 139], [85, 99], [85, 100], [85, 103], [85, 115], [85, 119], [85, 128], [85, 131], [85, 132], [86, 100], [86, 101], [86, 117], [86, 121], [86, 134], [86, 135], [87, 94], [87, 95], [87, 96], [87, 102], [87, 103], [87, 109], [87, 114], [87, 116], [87, 118], [87, 122], [87, 128], [87, 130], [87, 131], [87, 132], [87, 134], [88, 105], [88, 106], [88, 107], [88, 113], [88, 114], [88, 118], [88, 119], [88, 122], [88, 123], [88, 124], [88, 127], [88, 131], [88, 133], [88, 136], [89, 92], [89, 93], [89, 96], [89, 105], [89, 113], [89, 123], [89, 125], [89, 128], [89, 133], [90, 96], [90, 97], [90, 121], [90, 125], [90, 126], [90, 132], [90, 135], [90, 139], [91, 96], [91, 108], [91, 110], [91, 112], [91, 113], [91, 117], [91, 119], [91, 127], [91, 129], [91, 137], [92, 95], [92, 105], [92, 106], [92, 111], [92, 115], [92, 116], [92, 119], [92, 134], [93, 95], [93, 101], [93, 104], [93, 108], [93, 131], [94, 99], [94, 110], [94, 112], [94, 127], [94, 128], [94, 132], [94, 135], [94, 137], [94, 139], [95, 97], [95, 104], [95, 114], [95, 115], [95, 136], [96, 100], [96, 110], [96, 114], [96, 116], [96, 121], [97, 102], [97, 111], [97, 114], [97, 115], [97, 116], [97, 123], [97, 133], [97, 136], [97, 137], [98, 101], [98, 103], [98, 106], [98, 107], [98, 124], [98, 125], [99, 106], [99, 108], [99, 116], [99, 121], [99, 125], [99, 126], [99, 128], [99, 134], [100, 108], [100, 113], [100, 120], [100, 125], [100, 129], [100, 133], [101, 105], [101, 106], [101, 107], [101, 109], [101, 116], [101, 118], [101, 127], [101, 130], [101, 136], [102, 111], [102, 115], [102, 129], [102, 135], [103, 104], [103, 119], [103, 124], [103, 135], [104, 113], [104, 117], [104, 119], [104, 139], [105, 110], [105, 112], [105, 114], [105, 121], [105, 124], [105, 126], [105, 127], [105, 135], [106, 111], [106, 116], [106, 121], [106, 131], [106, 132], [106, 135], [106, 139], [107, 109], [107, 117], [107, 127], [107, 128], [107, 130], [107, 138], [108, 122], [108, 130], [108, 138], [109, 114], [109, 119], [109, 134], [109, 139], [110, 111], [110, 130], [110, 136], [110, 137], [111, 128], [111, 132], [112, 120], [112, 131], [112, 135], [112, 139], [113, 131], [114, 120], [114, 121], [114, 125], [114, 127], [115, 120], [115, 121], [115, 122], [115, 123], [115, 135], [116, 120], [116, 124], [116, 136], [117, 118], [118, 122], [118, 130], [118, 137], [119, 121], [119, 122], [119, 123], [119, 132], [119, 134], [120, 133], [120, 137], [121, 124], [121, 126], [121, 129], [121, 137], [122, 125], [122, 128], [122, 134], [122, 135], [122, 136], [123, 124], [123, 125], [123, 132], [124, 130], [124, 131], [124, 136], [125, 127], [125, 134], [127, 136], [128, 132], [128, 136], [129, 135], [131, 134], [132, 135], [132, 137], [135, 136], [135, 137]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l6-s3/tests/run.py b/tasks/construct-mc-vertex-cover-l6-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-vertex-cover-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-mc-vertex-cover-l6-s3/tests/test.sh b/tasks/construct-mc-vertex-cover-l6-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-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-mc-vertex-cover-l6-s4/environment/Dockerfile b/tasks/construct-mc-vertex-cover-l6-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-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-mc-vertex-cover-l6-s4/environment/instance.json b/tasks/construct-mc-vertex-cover-l6-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..06fe46b88a26f4c7fe978110a23a60644371fd5e --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l6-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 140, "k": 107, "edges": [[0, 1], [0, 6], [0, 15], [0, 20], [0, 21], [0, 26], [0, 50], [0, 59], [0, 76], [0, 85], [0, 94], [0, 96], [0, 107], [0, 108], [0, 121], [0, 122], [0, 126], [0, 127], [0, 129], [1, 6], [1, 10], [1, 27], [1, 29], [1, 30], [1, 36], [1, 56], [1, 58], [1, 67], [1, 71], [1, 76], [1, 77], [1, 90], [1, 96], [1, 99], [1, 111], [1, 121], [1, 132], [2, 28], [2, 32], [2, 33], [2, 42], [2, 57], [2, 60], [2, 62], [2, 67], [2, 69], [2, 75], [2, 77], [2, 79], [2, 83], [2, 91], [2, 94], [2, 96], [2, 99], [2, 113], [2, 117], [2, 121], [2, 122], [2, 134], [2, 136], [2, 137], [3, 21], [3, 22], [3, 23], [3, 28], [3, 57], [3, 90], [3, 92], [3, 104], [3, 107], [3, 108], [3, 114], [3, 123], [3, 135], [4, 25], [4, 50], [4, 55], [4, 60], [4, 66], [4, 90], [4, 92], [4, 100], [4, 102], [4, 119], [4, 122], [4, 135], [5, 11], [5, 15], [5, 18], [5, 45], [5, 57], [5, 63], [5, 71], [5, 78], [5, 85], [5, 89], [5, 93], [5, 103], [5, 105], [5, 107], [5, 108], [5, 120], [5, 121], [5, 125], [5, 134], [5, 139], [6, 16], [6, 23], [6, 30], [6, 40], [6, 45], [6, 46], [6, 59], [6, 60], [6, 66], [6, 74], [6, 92], [6, 94], [6, 103], [6, 114], [6, 126], [6, 127], [6, 128], [6, 134], [6, 135], [7, 14], [7, 16], [7, 17], [7, 18], [7, 21], [7, 27], [7, 36], [7, 45], [7, 49], [7, 51], [7, 58], [7, 67], [7, 68], [7, 71], [7, 73], [7, 82], [7, 89], [7, 94], [7, 98], [7, 107], [7, 109], [7, 114], [7, 115], [7, 117], [7, 131], [8, 11], [8, 20], [8, 28], [8, 30], [8, 48], [8, 66], [8, 74], [8, 90], [8, 92], [8, 102], [8, 105], [8, 116], [8, 117], [8, 124], [8, 130], [9, 11], [9, 14], [9, 19], [9, 21], [9, 24], [9, 37], [9, 41], [9, 48], [9, 57], [9, 59], [9, 63], [9, 65], [9, 66], [9, 70], [9, 74], [9, 87], [9, 88], [9, 100], [9, 110], [9, 117], [9, 118], [9, 119], [9, 122], [9, 125], [9, 137], [10, 12], [10, 20], [10, 33], [10, 37], [10, 41], [10, 50], [10, 59], [10, 99], [10, 100], [10, 103], [10, 105], [10, 108], [10, 110], [10, 112], [10, 115], [10, 135], [10, 137], [11, 19], [11, 21], [11, 35], [11, 48], [11, 49], [11, 51], [11, 61], [11, 94], [11, 97], [11, 102], [11, 108], [11, 115], [11, 119], [11, 122], [11, 123], [11, 124], [11, 125], [11, 128], [11, 135], [11, 138], [12, 21], [12, 39], [12, 41], [12, 54], [12, 56], [12, 59], [12, 64], [12, 81], [12, 99], [12, 107], [12, 108], [12, 116], [12, 117], [12, 118], [12, 119], [12, 121], [12, 124], [12, 135], [13, 19], [13, 20], [13, 27], [13, 43], [13, 47], [13, 48], [13, 57], [13, 60], [13, 66], [13, 70], [13, 74], [13, 77], [13, 84], [13, 89], [13, 94], [13, 108], [13, 139], [14, 17], [14, 18], [14, 29], [14, 33], [14, 35], [14, 38], [14, 45], [14, 50], [14, 57], [14, 88], [14, 89], [14, 100], [14, 103], [14, 110], [15, 16], [15, 19], [15, 28], [15, 30], [15, 49], [15, 63], [15, 64], [15, 67], [15, 68], [15, 81], [15, 88], [15, 95], [15, 105], [15, 107], [15, 112], [15, 118], [15, 121], [15, 132], [15, 135], [16, 22], [16, 36], [16, 41], [16, 45], [16, 49], [16, 52], [16, 59], [16, 60], [16, 74], [16, 78], [16, 86], [16, 95], [16, 97], [16, 100], [16, 102], [16, 106], [16, 126], [17, 23], [17, 52], [17, 75], [17, 80], [17, 82], [17, 93], [17, 96], [17, 102], [17, 104], [17, 108], [17, 127], [17, 133], [17, 137], [18, 19], [18, 21], [18, 22], [18, 25], [18, 26], [18, 52], [18, 64], [18, 69], [18, 92], [18, 98], [18, 108], [18, 112], [18, 133], [18, 134], [18, 137], [19, 27], [19, 29], [19, 35], [19, 40], [19, 57], [19, 69], [19, 81], [19, 84], [19, 90], [19, 97], [19, 99], [19, 100], [19, 122], [19, 126], [19, 134], [20, 25], [20, 26], [20, 30], [20, 37], [20, 42], [20, 47], [20, 61], [20, 76], [20, 88], [20, 89], [20, 92], [20, 96], [20, 107], [20, 119], [21, 22], [21, 26], [21, 42], [21, 63], [21, 68], [21, 69], [21, 74], [21, 76], [21, 77], [21, 89], [21, 97], [21, 115], [21, 126], [21, 128], [21, 133], [21, 136], [22, 23], [22, 47], [22, 51], [22, 58], [22, 59], [22, 66], [22, 86], [22, 90], [22, 96], [22, 103], [22, 104], [22, 110], [22, 111], [22, 133], [23, 27], [23, 30], [23, 37], [23, 39], [23, 44], [23, 50], [23, 53], [23, 54], [23, 55], [23, 57], [23, 70], [23, 71], [23, 74], [23, 84], [23, 85], [23, 89], [23, 90], [23, 112], [23, 119], [23, 126], [23, 128], [23, 137], [23, 138], [23, 139], [24, 34], [24, 40], [24, 51], [24, 58], [24, 63], [24, 67], [24, 71], [24, 75], [24, 87], [24, 102], [24, 103], [24, 113], [24, 115], [24, 117], [24, 124], [24, 127], [24, 136], [25, 30], [25, 35], [25, 38], [25, 45], [25, 47], [25, 63], [25, 76], [25, 77], [25, 79], [25, 86], [25, 87], [25, 92], [25, 97], [25, 102], [25, 130], [26, 46], [26, 48], [26, 60], [26, 64], [26, 84], [26, 88], [26, 90], [26, 98], [26, 103], [26, 114], [27, 49], [27, 52], [27, 59], [27, 62], [27, 66], [27, 87], [27, 92], [27, 101], [27, 105], [27, 125], [27, 139], [28, 29], [28, 49], [28, 58], [28, 62], [28, 63], [28, 67], [28, 72], [28, 86], [28, 104], [28, 119], [28, 123], [28, 128], [28, 137], [29, 40], [29, 50], [29, 63], [29, 66], [29, 76], [29, 90], [29, 118], [29, 121], [29, 127], [29, 128], [29, 139], [30, 41], [30, 43], [30, 49], [30, 62], [30, 63], [30, 64], [30, 71], [30, 88], [30, 97], [30, 115], [30, 132], [30, 134], [31, 55], [31, 58], [31, 77], [31, 85], [31, 106], [31, 108], [31, 122], [31, 127], [31, 135], [32, 34], [32, 48], [32, 49], [32, 62], [32, 74], [32, 78], [32, 79], [32, 80], [32, 83], [32, 88], [32, 92], [32, 100], [32, 106], [32, 118], [32, 121], [33, 55], [33, 66], [33, 70], [33, 76], [33, 82], [33, 89], [33, 105], [33, 111], [33, 124], [33, 128], [33, 137], [34, 38], [34, 40], [34, 41], [34, 42], [34, 57], [34, 68], [34, 69], [34, 84], [34, 87], [34, 91], [34, 101], [34, 105], [34, 108], [34, 115], [34, 118], [34, 124], [34, 130], [35, 56], [35, 58], [35, 60], [35, 66], [35, 68], [35, 71], [35, 80], [35, 83], [35, 94], [35, 95], [35, 97], [35, 102], [35, 128], [35, 130], [36, 39], [36, 44], [36, 47], [36, 53], [36, 57], [36, 63], [36, 64], [36, 67], [36, 77], [36, 87], [36, 89], [36, 91], [36, 105], [36, 106], [36, 111], [36, 114], [36, 115], [36, 118], [36, 127], [36, 134], [37, 43], [37, 44], [37, 45], [37, 48], [37, 51], [37, 57], [37, 70], [37, 76], [37, 78], [37, 91], [37, 94], [37, 95], [37, 98], [37, 102], [37, 104], [37, 119], [37, 128], [37, 130], [37, 134], [38, 42], [38, 51], [38, 63], [38, 74], [38, 96], [38, 99], [38, 103], [38, 106], [38, 109], [38, 113], [38, 118], [39, 76], [39, 87], [39, 90], [39, 101], [39, 110], [39, 129], [40, 64], [40, 76], [40, 77], [40, 79], [40, 82], [40, 89], [40, 91], [40, 96], [40, 99], [40, 101], [40, 112], [40, 116], [40, 118], [40, 119], [40, 122], [40, 132], [41, 55], [41, 68], [41, 75], [41, 97], [41, 107], [41, 108], [41, 118], [41, 126], [41, 131], [42, 48], [42, 52], [42, 55], [42, 73], [42, 75], [42, 92], [42, 93], [42, 103], [42, 105], [42, 116], [42, 120], [42, 123], [42, 128], [42, 129], [42, 133], [43, 62], [43, 63], [43, 66], [43, 72], [43, 85], [43, 97], [43, 106], [43, 118], [43, 126], [43, 138], [44, 45], [44, 49], [44, 69], [44, 73], [44, 74], [44, 79], [44, 86], [44, 94], [44, 103], [44, 104], [44, 106], [44, 108], [44, 135], [44, 137], [45, 50], [45, 53], [45, 58], [45, 68], [45, 69], [45, 71], [45, 83], [45, 85], [45, 96], [45, 98], [45, 109], [45, 117], [45, 118], [45, 129], [45, 138], [46, 54], [46, 58], [46, 60], [46, 66], [46, 77], [46, 84], [46, 85], [46, 94], [46, 97], [46, 100], [46, 104], [46, 109], [46, 110], [46, 115], [46, 134], [47, 50], [47, 58], [47, 64], [47, 91], [47, 101], [47, 107], [47, 109], [47, 111], [47, 124], [47, 129], [47, 137], [48, 50], [48, 62], [48, 64], [48, 82], [48, 83], [48, 98], [48, 102], [48, 113], [48, 121], [48, 135], [49, 66], [49, 69], [49, 70], [49, 76], [49, 78], [49, 83], [49, 102], [49, 109], [49, 116], [49, 135], [49, 136], [49, 137], [49, 138], [50, 60], [50, 66], [50, 74], [50, 79], [50, 89], [50, 93], [50, 94], [50, 95], [50, 107], [50, 121], [50, 125], [51, 62], [51, 66], [51, 67], [51, 80], [51, 85], [51, 86], [51, 88], [51, 101], [51, 104], [51, 107], [51, 111], [51, 119], [51, 134], [52, 53], [52, 54], [52, 58], [52, 70], [52, 77], [52, 81], [52, 82], [52, 95], [52, 101], [52, 109], [52, 126], [52, 131], [52, 135], [53, 72], [53, 75], [53, 78], [53, 90], [53, 91], [53, 100], [53, 103], [53, 108], [53, 112], [53, 119], [54, 63], [54, 74], [54, 76], [54, 81], [54, 94], [54, 99], [54, 115], [54, 129], [54, 134], [55, 58], [55, 65], [55, 79], [55, 83], [55, 101], [55, 102], [55, 103], [55, 117], [55, 124], [55, 129], [55, 137], [55, 139], [56, 58], [56, 61], [56, 74], [56, 82], [56, 94], [56, 99], [56, 109], [56, 114], [56, 118], [56, 124], [56, 130], [56, 134], [56, 136], [56, 139], [57, 60], [57, 95], [57, 97], [57, 107], [57, 120], [57, 121], [57, 133], [58, 61], [58, 65], [58, 68], [58, 89], [58, 104], [58, 110], [58, 116], [58, 123], [58, 128], [58, 132], [59, 69], [59, 74], [59, 99], [59, 102], [59, 105], [59, 116], [60, 70], [60, 76], [60, 77], [60, 85], [60, 93], [60, 113], [60, 133], [60, 138], [60, 139], [61, 75], [61, 86], [61, 87], [61, 102], [61, 103], [61, 110], [61, 118], [61, 119], [61, 125], [61, 128], [61, 131], [61, 138], [61, 139], [62, 70], [62, 83], [62, 89], [62, 101], [62, 110], [62, 132], [62, 139], [63, 66], [63, 69], [63, 72], [63, 75], [63, 82], [63, 88], [63, 90], [63, 91], [63, 93], [63, 98], [63, 101], [63, 122], [63, 127], [63, 130], [63, 133], [63, 137], [64, 66], [64, 67], [64, 74], [64, 76], [64, 77], [64, 81], [64, 114], [64, 124], [64, 130], [65, 81], [65, 83], [65, 90], [65, 91], [65, 99], [65, 103], [65, 110], [65, 111], [65, 120], [65, 123], [66, 67], [66, 68], [66, 71], [66, 73], [66, 77], [66, 79], [66, 87], [66, 91], [66, 94], [66, 105], [66, 110], [66, 123], [66, 127], [66, 133], [66, 136], [67, 95], [67, 102], [67, 113], [67, 127], [68, 74], [68, 76], [68, 81], [68, 85], [68, 88], [68, 101], [68, 108], [68, 111], [68, 112], [68, 126], [69, 79], [69, 80], [69, 82], [69, 92], [69, 96], [69, 100], [69, 102], [69, 121], [69, 125], [69, 137], [70, 71], [70, 75], [70, 89], [70, 91], [70, 96], [70, 97], [70, 98], [70, 112], [70, 125], [70, 130], [70, 132], [70, 133], [70, 139], [71, 75], [71, 80], [71, 99], [71, 103], [71, 112], [71, 120], [71, 125], [71, 139], [72, 78], [72, 79], [72, 88], [72, 90], [72, 105], [72, 108], [72, 114], [72, 115], [72, 116], [72, 120], [72, 137], [73, 76], [73, 80], [73, 91], [73, 94], [73, 97], [73, 99], [73, 101], [73, 118], [73, 121], [73, 128], [73, 134], [74, 83], [74, 102], [74, 109], [74, 112], [74, 114], [74, 118], [74, 121], [74, 123], [74, 128], [74, 133], [75, 77], [75, 92], [75, 93], [75, 97], [75, 99], [75, 105], [75, 109], [75, 118], [75, 126], [75, 127], [75, 128], [75, 134], [75, 136], [76, 77], [76, 78], [76, 80], [76, 82], [76, 95], [76, 97], [76, 106], [76, 108], [76, 113], [76, 122], [76, 124], [76, 138], [77, 83], [77, 95], [77, 105], [77, 110], [77, 112], [77, 125], [77, 127], [78, 97], [78, 98], [78, 103], [78, 121], [78, 123], [78, 132], [78, 136], [79, 80], [79, 86], [79, 89], [79, 93], [79, 96], [79, 100], [79, 103], [79, 117], [79, 132], [79, 136], [79, 137], [80, 84], [80, 91], [80, 94], [80, 98], [80, 101], [80, 103], [80, 108], [80, 117], [80, 128], [80, 134], [80, 136], [81, 83], [81, 85], [81, 88], [81, 90], [81, 97], [81, 102], [81, 111], [81, 118], [81, 128], [81, 130], [81, 132], [81, 139], [82, 92], [82, 109], [82, 111], [82, 118], [82, 119], [82, 121], [82, 124], [82, 125], [83, 97], [83, 114], [83, 120], [83, 125], [83, 131], [83, 132], [83, 136], [83, 139], [84, 86], [84, 88], [84, 96], [84, 109], [84, 111], [84, 124], [84, 133], [85, 91], [85, 117], [85, 128], [86, 93], [86, 97], [86, 98], [86, 104], [86, 109], [86, 114], [86, 134], [86, 135], [87, 90], [87, 109], [87, 120], [87, 121], [87, 132], [87, 135], [88, 91], [88, 96], [88, 104], [88, 105], [88, 113], [88, 126], [88, 138], [89, 91], [89, 92], [89, 101], [89, 103], [89, 105], [89, 119], [89, 125], [89, 126], [90, 95], [90, 96], [90, 97], [90, 112], [90, 115], [90, 119], [90, 126], [90, 127], [90, 135], [91, 96], [91, 100], [91, 105], [91, 109], [91, 119], [91, 127], [91, 128], [91, 132], [91, 135], [91, 136], [91, 137], [91, 139], [92, 99], [92, 102], [92, 125], [92, 133], [92, 137], [93, 119], [93, 127], [93, 139], [94, 96], [94, 107], [95, 98], [95, 103], [95, 107], [95, 115], [95, 116], [95, 122], [95, 131], [95, 132], [95, 138], [96, 97], [96, 101], [96, 113], [96, 126], [96, 134], [96, 137], [96, 138], [97, 102], [97, 105], [97, 109], [97, 122], [97, 124], [97, 127], [97, 135], [97, 138], [98, 100], [98, 105], [98, 111], [98, 115], [98, 118], [98, 121], [98, 126], [98, 133], [98, 134], [98, 138], [99, 101], [99, 102], [99, 117], [99, 122], [99, 123], [99, 131], [99, 132], [99, 136], [99, 137], [100, 129], [100, 134], [101, 106], [101, 109], [101, 110], [101, 115], [101, 121], [101, 131], [102, 121], [102, 134], [103, 106], [103, 107], [103, 120], [103, 123], [103, 129], [103, 130], [103, 131], [104, 106], [104, 113], [104, 121], [104, 122], [104, 123], [104, 125], [104, 129], [104, 133], [105, 110], [105, 114], [105, 131], [105, 132], [106, 115], [106, 116], [106, 123], [106, 137], [106, 138], [107, 112], [107, 122], [107, 123], [107, 128], [107, 129], [108, 124], [108, 127], [108, 132], [109, 113], [109, 122], [109, 129], [109, 132], [110, 122], [110, 128], [110, 129], [110, 132], [111, 126], [111, 128], [112, 114], [112, 122], [112, 128], [112, 131], [112, 132], [112, 135], [113, 116], [113, 117], [113, 118], [113, 132], [114, 119], [114, 120], [114, 133], [114, 134], [114, 139], [115, 117], [115, 118], [115, 130], [115, 135], [115, 138], [116, 120], [116, 123], [116, 138], [116, 139], [118, 122], [118, 123], [118, 126], [118, 128], [119, 137], [120, 122], [120, 135], [120, 137], [120, 139], [121, 129], [122, 128], [122, 131], [122, 138], [123, 128], [123, 129], [124, 136], [125, 131], [125, 136], [125, 138], [127, 137], [128, 133], [129, 130], [129, 134], [129, 137], [129, 139], [130, 135], [130, 137], [131, 133], [131, 137], [135, 138], [137, 138]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l6-s4/solution/solve.sh b/tasks/construct-mc-vertex-cover-l6-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4e47cba62a060af19d12cb9cf3c1487e763389b9 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-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' +{"cover": [1, 2, 3, 5, 6, 7, 8, 9, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 28, 30, 31, 33, 34, 35, 36, 37, 40, 41, 42, 44, 45, 46, 48, 49, 50, 51, 52, 55, 56, 58, 59, 60, 61, 62, 63, 64, 66, 69, 70, 72, 74, 75, 76, 78, 79, 80, 81, 83, 85, 86, 87, 88, 90, 91, 92, 94, 95, 96, 97, 99, 100, 101, 102, 103, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 133, 134, 135, 137, 138, 139]} +RLMATH_EOF diff --git a/tasks/construct-mc-vertex-cover-l6-s4/tests/check.py b/tasks/construct-mc-vertex-cover-l6-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3accb3da1c773fd2126b8b5b0a97b099e29c83b --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l6-s4/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-l6-s4/tests/instance.json b/tasks/construct-mc-vertex-cover-l6-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..06fe46b88a26f4c7fe978110a23a60644371fd5e --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l6-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 140, "k": 107, "edges": [[0, 1], [0, 6], [0, 15], [0, 20], [0, 21], [0, 26], [0, 50], [0, 59], [0, 76], [0, 85], [0, 94], [0, 96], [0, 107], [0, 108], [0, 121], [0, 122], [0, 126], [0, 127], [0, 129], [1, 6], [1, 10], [1, 27], [1, 29], [1, 30], [1, 36], [1, 56], [1, 58], [1, 67], [1, 71], [1, 76], [1, 77], [1, 90], [1, 96], [1, 99], [1, 111], [1, 121], [1, 132], [2, 28], [2, 32], [2, 33], [2, 42], [2, 57], [2, 60], [2, 62], [2, 67], [2, 69], [2, 75], [2, 77], [2, 79], [2, 83], [2, 91], [2, 94], [2, 96], [2, 99], [2, 113], [2, 117], [2, 121], [2, 122], [2, 134], [2, 136], [2, 137], [3, 21], [3, 22], [3, 23], [3, 28], [3, 57], [3, 90], [3, 92], [3, 104], [3, 107], [3, 108], [3, 114], [3, 123], [3, 135], [4, 25], [4, 50], [4, 55], [4, 60], [4, 66], [4, 90], [4, 92], [4, 100], [4, 102], [4, 119], [4, 122], [4, 135], [5, 11], [5, 15], [5, 18], [5, 45], [5, 57], [5, 63], [5, 71], [5, 78], [5, 85], [5, 89], [5, 93], [5, 103], [5, 105], [5, 107], [5, 108], [5, 120], [5, 121], [5, 125], [5, 134], [5, 139], [6, 16], [6, 23], [6, 30], [6, 40], [6, 45], [6, 46], [6, 59], [6, 60], [6, 66], [6, 74], [6, 92], [6, 94], [6, 103], [6, 114], [6, 126], [6, 127], [6, 128], [6, 134], [6, 135], [7, 14], [7, 16], [7, 17], [7, 18], [7, 21], [7, 27], [7, 36], [7, 45], [7, 49], [7, 51], [7, 58], [7, 67], [7, 68], [7, 71], [7, 73], [7, 82], [7, 89], [7, 94], [7, 98], [7, 107], [7, 109], [7, 114], [7, 115], [7, 117], [7, 131], [8, 11], [8, 20], [8, 28], [8, 30], [8, 48], [8, 66], [8, 74], [8, 90], [8, 92], [8, 102], [8, 105], [8, 116], [8, 117], [8, 124], [8, 130], [9, 11], [9, 14], [9, 19], [9, 21], [9, 24], [9, 37], [9, 41], [9, 48], [9, 57], [9, 59], [9, 63], [9, 65], [9, 66], [9, 70], [9, 74], [9, 87], [9, 88], [9, 100], [9, 110], [9, 117], [9, 118], [9, 119], [9, 122], [9, 125], [9, 137], [10, 12], [10, 20], [10, 33], [10, 37], [10, 41], [10, 50], [10, 59], [10, 99], [10, 100], [10, 103], [10, 105], [10, 108], [10, 110], [10, 112], [10, 115], [10, 135], [10, 137], [11, 19], [11, 21], [11, 35], [11, 48], [11, 49], [11, 51], [11, 61], [11, 94], [11, 97], [11, 102], [11, 108], [11, 115], [11, 119], [11, 122], [11, 123], [11, 124], [11, 125], [11, 128], [11, 135], [11, 138], [12, 21], [12, 39], [12, 41], [12, 54], [12, 56], [12, 59], [12, 64], [12, 81], [12, 99], [12, 107], [12, 108], [12, 116], [12, 117], [12, 118], [12, 119], [12, 121], [12, 124], [12, 135], [13, 19], [13, 20], [13, 27], [13, 43], [13, 47], [13, 48], [13, 57], [13, 60], [13, 66], [13, 70], [13, 74], [13, 77], [13, 84], [13, 89], [13, 94], [13, 108], [13, 139], [14, 17], [14, 18], [14, 29], [14, 33], [14, 35], [14, 38], [14, 45], [14, 50], [14, 57], [14, 88], [14, 89], [14, 100], [14, 103], [14, 110], [15, 16], [15, 19], [15, 28], [15, 30], [15, 49], [15, 63], [15, 64], [15, 67], [15, 68], [15, 81], [15, 88], [15, 95], [15, 105], [15, 107], [15, 112], [15, 118], [15, 121], [15, 132], [15, 135], [16, 22], [16, 36], [16, 41], [16, 45], [16, 49], [16, 52], [16, 59], [16, 60], [16, 74], [16, 78], [16, 86], [16, 95], [16, 97], [16, 100], [16, 102], [16, 106], [16, 126], [17, 23], [17, 52], [17, 75], [17, 80], [17, 82], [17, 93], [17, 96], [17, 102], [17, 104], [17, 108], [17, 127], [17, 133], [17, 137], [18, 19], [18, 21], [18, 22], [18, 25], [18, 26], [18, 52], [18, 64], [18, 69], [18, 92], [18, 98], [18, 108], [18, 112], [18, 133], [18, 134], [18, 137], [19, 27], [19, 29], [19, 35], [19, 40], [19, 57], [19, 69], [19, 81], [19, 84], [19, 90], [19, 97], [19, 99], [19, 100], [19, 122], [19, 126], [19, 134], [20, 25], [20, 26], [20, 30], [20, 37], [20, 42], [20, 47], [20, 61], [20, 76], [20, 88], [20, 89], [20, 92], [20, 96], [20, 107], [20, 119], [21, 22], [21, 26], [21, 42], [21, 63], [21, 68], [21, 69], [21, 74], [21, 76], [21, 77], [21, 89], [21, 97], [21, 115], [21, 126], [21, 128], [21, 133], [21, 136], [22, 23], [22, 47], [22, 51], [22, 58], [22, 59], [22, 66], [22, 86], [22, 90], [22, 96], [22, 103], [22, 104], [22, 110], [22, 111], [22, 133], [23, 27], [23, 30], [23, 37], [23, 39], [23, 44], [23, 50], [23, 53], [23, 54], [23, 55], [23, 57], [23, 70], [23, 71], [23, 74], [23, 84], [23, 85], [23, 89], [23, 90], [23, 112], [23, 119], [23, 126], [23, 128], [23, 137], [23, 138], [23, 139], [24, 34], [24, 40], [24, 51], [24, 58], [24, 63], [24, 67], [24, 71], [24, 75], [24, 87], [24, 102], [24, 103], [24, 113], [24, 115], [24, 117], [24, 124], [24, 127], [24, 136], [25, 30], [25, 35], [25, 38], [25, 45], [25, 47], [25, 63], [25, 76], [25, 77], [25, 79], [25, 86], [25, 87], [25, 92], [25, 97], [25, 102], [25, 130], [26, 46], [26, 48], [26, 60], [26, 64], [26, 84], [26, 88], [26, 90], [26, 98], [26, 103], [26, 114], [27, 49], [27, 52], [27, 59], [27, 62], [27, 66], [27, 87], [27, 92], [27, 101], [27, 105], [27, 125], [27, 139], [28, 29], [28, 49], [28, 58], [28, 62], [28, 63], [28, 67], [28, 72], [28, 86], [28, 104], [28, 119], [28, 123], [28, 128], [28, 137], [29, 40], [29, 50], [29, 63], [29, 66], [29, 76], [29, 90], [29, 118], [29, 121], [29, 127], [29, 128], [29, 139], [30, 41], [30, 43], [30, 49], [30, 62], [30, 63], [30, 64], [30, 71], [30, 88], [30, 97], [30, 115], [30, 132], [30, 134], [31, 55], [31, 58], [31, 77], [31, 85], [31, 106], [31, 108], [31, 122], [31, 127], [31, 135], [32, 34], [32, 48], [32, 49], [32, 62], [32, 74], [32, 78], [32, 79], [32, 80], [32, 83], [32, 88], [32, 92], [32, 100], [32, 106], [32, 118], [32, 121], [33, 55], [33, 66], [33, 70], [33, 76], [33, 82], [33, 89], [33, 105], [33, 111], [33, 124], [33, 128], [33, 137], [34, 38], [34, 40], [34, 41], [34, 42], [34, 57], [34, 68], [34, 69], [34, 84], [34, 87], [34, 91], [34, 101], [34, 105], [34, 108], [34, 115], [34, 118], [34, 124], [34, 130], [35, 56], [35, 58], [35, 60], [35, 66], [35, 68], [35, 71], [35, 80], [35, 83], [35, 94], [35, 95], [35, 97], [35, 102], [35, 128], [35, 130], [36, 39], [36, 44], [36, 47], [36, 53], [36, 57], [36, 63], [36, 64], [36, 67], [36, 77], [36, 87], [36, 89], [36, 91], [36, 105], [36, 106], [36, 111], [36, 114], [36, 115], [36, 118], [36, 127], [36, 134], [37, 43], [37, 44], [37, 45], [37, 48], [37, 51], [37, 57], [37, 70], [37, 76], [37, 78], [37, 91], [37, 94], [37, 95], [37, 98], [37, 102], [37, 104], [37, 119], [37, 128], [37, 130], [37, 134], [38, 42], [38, 51], [38, 63], [38, 74], [38, 96], [38, 99], [38, 103], [38, 106], [38, 109], [38, 113], [38, 118], [39, 76], [39, 87], [39, 90], [39, 101], [39, 110], [39, 129], [40, 64], [40, 76], [40, 77], [40, 79], [40, 82], [40, 89], [40, 91], [40, 96], [40, 99], [40, 101], [40, 112], [40, 116], [40, 118], [40, 119], [40, 122], [40, 132], [41, 55], [41, 68], [41, 75], [41, 97], [41, 107], [41, 108], [41, 118], [41, 126], [41, 131], [42, 48], [42, 52], [42, 55], [42, 73], [42, 75], [42, 92], [42, 93], [42, 103], [42, 105], [42, 116], [42, 120], [42, 123], [42, 128], [42, 129], [42, 133], [43, 62], [43, 63], [43, 66], [43, 72], [43, 85], [43, 97], [43, 106], [43, 118], [43, 126], [43, 138], [44, 45], [44, 49], [44, 69], [44, 73], [44, 74], [44, 79], [44, 86], [44, 94], [44, 103], [44, 104], [44, 106], [44, 108], [44, 135], [44, 137], [45, 50], [45, 53], [45, 58], [45, 68], [45, 69], [45, 71], [45, 83], [45, 85], [45, 96], [45, 98], [45, 109], [45, 117], [45, 118], [45, 129], [45, 138], [46, 54], [46, 58], [46, 60], [46, 66], [46, 77], [46, 84], [46, 85], [46, 94], [46, 97], [46, 100], [46, 104], [46, 109], [46, 110], [46, 115], [46, 134], [47, 50], [47, 58], [47, 64], [47, 91], [47, 101], [47, 107], [47, 109], [47, 111], [47, 124], [47, 129], [47, 137], [48, 50], [48, 62], [48, 64], [48, 82], [48, 83], [48, 98], [48, 102], [48, 113], [48, 121], [48, 135], [49, 66], [49, 69], [49, 70], [49, 76], [49, 78], [49, 83], [49, 102], [49, 109], [49, 116], [49, 135], [49, 136], [49, 137], [49, 138], [50, 60], [50, 66], [50, 74], [50, 79], [50, 89], [50, 93], [50, 94], [50, 95], [50, 107], [50, 121], [50, 125], [51, 62], [51, 66], [51, 67], [51, 80], [51, 85], [51, 86], [51, 88], [51, 101], [51, 104], [51, 107], [51, 111], [51, 119], [51, 134], [52, 53], [52, 54], [52, 58], [52, 70], [52, 77], [52, 81], [52, 82], [52, 95], [52, 101], [52, 109], [52, 126], [52, 131], [52, 135], [53, 72], [53, 75], [53, 78], [53, 90], [53, 91], [53, 100], [53, 103], [53, 108], [53, 112], [53, 119], [54, 63], [54, 74], [54, 76], [54, 81], [54, 94], [54, 99], [54, 115], [54, 129], [54, 134], [55, 58], [55, 65], [55, 79], [55, 83], [55, 101], [55, 102], [55, 103], [55, 117], [55, 124], [55, 129], [55, 137], [55, 139], [56, 58], [56, 61], [56, 74], [56, 82], [56, 94], [56, 99], [56, 109], [56, 114], [56, 118], [56, 124], [56, 130], [56, 134], [56, 136], [56, 139], [57, 60], [57, 95], [57, 97], [57, 107], [57, 120], [57, 121], [57, 133], [58, 61], [58, 65], [58, 68], [58, 89], [58, 104], [58, 110], [58, 116], [58, 123], [58, 128], [58, 132], [59, 69], [59, 74], [59, 99], [59, 102], [59, 105], [59, 116], [60, 70], [60, 76], [60, 77], [60, 85], [60, 93], [60, 113], [60, 133], [60, 138], [60, 139], [61, 75], [61, 86], [61, 87], [61, 102], [61, 103], [61, 110], [61, 118], [61, 119], [61, 125], [61, 128], [61, 131], [61, 138], [61, 139], [62, 70], [62, 83], [62, 89], [62, 101], [62, 110], [62, 132], [62, 139], [63, 66], [63, 69], [63, 72], [63, 75], [63, 82], [63, 88], [63, 90], [63, 91], [63, 93], [63, 98], [63, 101], [63, 122], [63, 127], [63, 130], [63, 133], [63, 137], [64, 66], [64, 67], [64, 74], [64, 76], [64, 77], [64, 81], [64, 114], [64, 124], [64, 130], [65, 81], [65, 83], [65, 90], [65, 91], [65, 99], [65, 103], [65, 110], [65, 111], [65, 120], [65, 123], [66, 67], [66, 68], [66, 71], [66, 73], [66, 77], [66, 79], [66, 87], [66, 91], [66, 94], [66, 105], [66, 110], [66, 123], [66, 127], [66, 133], [66, 136], [67, 95], [67, 102], [67, 113], [67, 127], [68, 74], [68, 76], [68, 81], [68, 85], [68, 88], [68, 101], [68, 108], [68, 111], [68, 112], [68, 126], [69, 79], [69, 80], [69, 82], [69, 92], [69, 96], [69, 100], [69, 102], [69, 121], [69, 125], [69, 137], [70, 71], [70, 75], [70, 89], [70, 91], [70, 96], [70, 97], [70, 98], [70, 112], [70, 125], [70, 130], [70, 132], [70, 133], [70, 139], [71, 75], [71, 80], [71, 99], [71, 103], [71, 112], [71, 120], [71, 125], [71, 139], [72, 78], [72, 79], [72, 88], [72, 90], [72, 105], [72, 108], [72, 114], [72, 115], [72, 116], [72, 120], [72, 137], [73, 76], [73, 80], [73, 91], [73, 94], [73, 97], [73, 99], [73, 101], [73, 118], [73, 121], [73, 128], [73, 134], [74, 83], [74, 102], [74, 109], [74, 112], [74, 114], [74, 118], [74, 121], [74, 123], [74, 128], [74, 133], [75, 77], [75, 92], [75, 93], [75, 97], [75, 99], [75, 105], [75, 109], [75, 118], [75, 126], [75, 127], [75, 128], [75, 134], [75, 136], [76, 77], [76, 78], [76, 80], [76, 82], [76, 95], [76, 97], [76, 106], [76, 108], [76, 113], [76, 122], [76, 124], [76, 138], [77, 83], [77, 95], [77, 105], [77, 110], [77, 112], [77, 125], [77, 127], [78, 97], [78, 98], [78, 103], [78, 121], [78, 123], [78, 132], [78, 136], [79, 80], [79, 86], [79, 89], [79, 93], [79, 96], [79, 100], [79, 103], [79, 117], [79, 132], [79, 136], [79, 137], [80, 84], [80, 91], [80, 94], [80, 98], [80, 101], [80, 103], [80, 108], [80, 117], [80, 128], [80, 134], [80, 136], [81, 83], [81, 85], [81, 88], [81, 90], [81, 97], [81, 102], [81, 111], [81, 118], [81, 128], [81, 130], [81, 132], [81, 139], [82, 92], [82, 109], [82, 111], [82, 118], [82, 119], [82, 121], [82, 124], [82, 125], [83, 97], [83, 114], [83, 120], [83, 125], [83, 131], [83, 132], [83, 136], [83, 139], [84, 86], [84, 88], [84, 96], [84, 109], [84, 111], [84, 124], [84, 133], [85, 91], [85, 117], [85, 128], [86, 93], [86, 97], [86, 98], [86, 104], [86, 109], [86, 114], [86, 134], [86, 135], [87, 90], [87, 109], [87, 120], [87, 121], [87, 132], [87, 135], [88, 91], [88, 96], [88, 104], [88, 105], [88, 113], [88, 126], [88, 138], [89, 91], [89, 92], [89, 101], [89, 103], [89, 105], [89, 119], [89, 125], [89, 126], [90, 95], [90, 96], [90, 97], [90, 112], [90, 115], [90, 119], [90, 126], [90, 127], [90, 135], [91, 96], [91, 100], [91, 105], [91, 109], [91, 119], [91, 127], [91, 128], [91, 132], [91, 135], [91, 136], [91, 137], [91, 139], [92, 99], [92, 102], [92, 125], [92, 133], [92, 137], [93, 119], [93, 127], [93, 139], [94, 96], [94, 107], [95, 98], [95, 103], [95, 107], [95, 115], [95, 116], [95, 122], [95, 131], [95, 132], [95, 138], [96, 97], [96, 101], [96, 113], [96, 126], [96, 134], [96, 137], [96, 138], [97, 102], [97, 105], [97, 109], [97, 122], [97, 124], [97, 127], [97, 135], [97, 138], [98, 100], [98, 105], [98, 111], [98, 115], [98, 118], [98, 121], [98, 126], [98, 133], [98, 134], [98, 138], [99, 101], [99, 102], [99, 117], [99, 122], [99, 123], [99, 131], [99, 132], [99, 136], [99, 137], [100, 129], [100, 134], [101, 106], [101, 109], [101, 110], [101, 115], [101, 121], [101, 131], [102, 121], [102, 134], [103, 106], [103, 107], [103, 120], [103, 123], [103, 129], [103, 130], [103, 131], [104, 106], [104, 113], [104, 121], [104, 122], [104, 123], [104, 125], [104, 129], [104, 133], [105, 110], [105, 114], [105, 131], [105, 132], [106, 115], [106, 116], [106, 123], [106, 137], [106, 138], [107, 112], [107, 122], [107, 123], [107, 128], [107, 129], [108, 124], [108, 127], [108, 132], [109, 113], [109, 122], [109, 129], [109, 132], [110, 122], [110, 128], [110, 129], [110, 132], [111, 126], [111, 128], [112, 114], [112, 122], [112, 128], [112, 131], [112, 132], [112, 135], [113, 116], [113, 117], [113, 118], [113, 132], [114, 119], [114, 120], [114, 133], [114, 134], [114, 139], [115, 117], [115, 118], [115, 130], [115, 135], [115, 138], [116, 120], [116, 123], [116, 138], [116, 139], [118, 122], [118, 123], [118, 126], [118, 128], [119, 137], [120, 122], [120, 135], [120, 137], [120, 139], [121, 129], [122, 128], [122, 131], [122, 138], [123, 128], [123, 129], [124, 136], [125, 131], [125, 136], [125, 138], [127, 137], [128, 133], [129, 130], [129, 134], [129, 137], [129, 139], [130, 135], [130, 137], [131, 133], [131, 137], [135, 138], [137, 138]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l6-s4/tests/run.py b/tasks/construct-mc-vertex-cover-l6-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-vertex-cover-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-mc-vertex-cover-l6-s4/tests/test.sh b/tasks/construct-mc-vertex-cover-l6-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-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-nppc-3col-l2-s2/environment/Dockerfile b/tasks/construct-nppc-3col-l2-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-3col-l2-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-l2-s2/environment/instance.json b/tasks/construct-nppc-3col-l2-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6480eb238862ad9c9f41a6de4a477b05af456c51 --- /dev/null +++ b/tasks/construct-nppc-3col-l2-s2/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 15, "edges": [[0, 1], [0, 5], [0, 6], [0, 8], [0, 10], [0, 12], [1, 3], [1, 4], [1, 6], [1, 13], [1, 14], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 12], [2, 14], [3, 4], [3, 10], [3, 12], [4, 7], [4, 8], [4, 9], [4, 10], [5, 7], [5, 10], [5, 12], [6, 10], [6, 11], [6, 12], [7, 14], [8, 9], [8, 11], [8, 14], [9, 10], [9, 11], [9, 13], [10, 13], [11, 14]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l2-s2/solution/solve.sh b/tasks/construct-nppc-3col-l2-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..695508fdecad1ea38350b0afe34af100b0a2e4f5 --- /dev/null +++ b/tasks/construct-nppc-3col-l2-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' +{"coloring": [1, 2, 1, 0, 1, 0, 0, 2, 2, 0, 2, 1, 2, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-nppc-3col-l2-s2/tests/check.py b/tasks/construct-nppc-3col-l2-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..72362ed9180250b6c53ce0c71867ca476ac2af20 --- /dev/null +++ b/tasks/construct-nppc-3col-l2-s2/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-l2-s2/tests/instance.json b/tasks/construct-nppc-3col-l2-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6480eb238862ad9c9f41a6de4a477b05af456c51 --- /dev/null +++ b/tasks/construct-nppc-3col-l2-s2/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 15, "edges": [[0, 1], [0, 5], [0, 6], [0, 8], [0, 10], [0, 12], [1, 3], [1, 4], [1, 6], [1, 13], [1, 14], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 12], [2, 14], [3, 4], [3, 10], [3, 12], [4, 7], [4, 8], [4, 9], [4, 10], [5, 7], [5, 10], [5, 12], [6, 10], [6, 11], [6, 12], [7, 14], [8, 9], [8, 11], [8, 14], [9, 10], [9, 11], [9, 13], [10, 13], [11, 14]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l2-s2/tests/run.py b/tasks/construct-nppc-3col-l2-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-3col-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-nppc-3col-l2-s2/tests/test.sh b/tasks/construct-nppc-3col-l2-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-3col-l2-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-nppc-3col-l2-s5/environment/Dockerfile b/tasks/construct-nppc-3col-l2-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-3col-l2-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-l2-s5/environment/instance.json b/tasks/construct-nppc-3col-l2-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..be61b43be97326ad22bf94945f403f3f1dfeebee --- /dev/null +++ b/tasks/construct-nppc-3col-l2-s5/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 15, "edges": [[0, 4], [0, 8], [0, 10], [0, 11], [0, 12], [0, 14], [1, 3], [1, 7], [1, 8], [1, 11], [2, 4], [2, 7], [2, 9], [2, 10], [2, 11], [2, 12], [2, 14], [3, 4], [3, 9], [3, 11], [3, 12], [3, 14], [4, 13], [5, 6], [5, 7], [5, 9], [5, 10], [5, 12], [5, 14], [6, 7], [6, 8], [6, 13], [7, 10], [8, 12], [8, 13], [9, 10], [9, 12], [11, 13], [11, 14], [13, 14]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l2-s5/solution/solve.sh b/tasks/construct-nppc-3col-l2-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ad690a5f5ead3aba750665aaee21a68b6de1359 --- /dev/null +++ b/tasks/construct-nppc-3col-l2-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, 2, 0, 0, 1, 0, 2, 1, 1, 1, 2, 1, 2, 0, 2]} +RLMATH_EOF diff --git a/tasks/construct-nppc-3col-l2-s5/tests/check.py b/tasks/construct-nppc-3col-l2-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..72362ed9180250b6c53ce0c71867ca476ac2af20 --- /dev/null +++ b/tasks/construct-nppc-3col-l2-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-l2-s5/tests/instance.json b/tasks/construct-nppc-3col-l2-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..be61b43be97326ad22bf94945f403f3f1dfeebee --- /dev/null +++ b/tasks/construct-nppc-3col-l2-s5/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 15, "edges": [[0, 4], [0, 8], [0, 10], [0, 11], [0, 12], [0, 14], [1, 3], [1, 7], [1, 8], [1, 11], [2, 4], [2, 7], [2, 9], [2, 10], [2, 11], [2, 12], [2, 14], [3, 4], [3, 9], [3, 11], [3, 12], [3, 14], [4, 13], [5, 6], [5, 7], [5, 9], [5, 10], [5, 12], [5, 14], [6, 7], [6, 8], [6, 13], [7, 10], [8, 12], [8, 13], [9, 10], [9, 12], [11, 13], [11, 14], [13, 14]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l2-s5/tests/run.py b/tasks/construct-nppc-3col-l2-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-3col-l2-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-l2-s5/tests/test.sh b/tasks/construct-nppc-3col-l2-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-3col-l2-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-l4-s0/environment/Dockerfile b/tasks/construct-nppc-bandwidth-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-nppc-bandwidth-l4-s0/environment/instance.json b/tasks/construct-nppc-bandwidth-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4865f89c5ccb8c06a4530d6ae1363795c7d1632a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 20, "bandwidth": 3, "edges": [[0, 2], [0, 7], [0, 12], [0, 18], [0, 19], [1, 3], [1, 8], [1, 14], [1, 17], [2, 7], [2, 12], [3, 8], [3, 14], [3, 16], [3, 19], [4, 5], [4, 11], [5, 6], [5, 9], [5, 11], [5, 13], [6, 9], [6, 15], [7, 12], [7, 18], [8, 10], [9, 10], [9, 13], [9, 14], [9, 15], [10, 14], [11, 13], [12, 17], [13, 15], [14, 15], [16, 17], [16, 18], [16, 19], [17, 18], [17, 19], [18, 19]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l4-s0/solution/solve.sh b/tasks/construct-nppc-bandwidth-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..51d23fb227796e9105098b380541f9adad2e541a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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' +{"layout": [17, 10, 19, 11, 0, 2, 4, 18, 9, 5, 7, 1, 16, 3, 8, 6, 12, 13, 15, 14]} +RLMATH_EOF diff --git a/tasks/construct-nppc-bandwidth-l4-s0/tests/check.py b/tasks/construct-nppc-bandwidth-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0f847cded257e6c404063dfafde33fa44163afa2 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l4-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-l4-s0/tests/instance.json b/tasks/construct-nppc-bandwidth-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4865f89c5ccb8c06a4530d6ae1363795c7d1632a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 20, "bandwidth": 3, "edges": [[0, 2], [0, 7], [0, 12], [0, 18], [0, 19], [1, 3], [1, 8], [1, 14], [1, 17], [2, 7], [2, 12], [3, 8], [3, 14], [3, 16], [3, 19], [4, 5], [4, 11], [5, 6], [5, 9], [5, 11], [5, 13], [6, 9], [6, 15], [7, 12], [7, 18], [8, 10], [9, 10], [9, 13], [9, 14], [9, 15], [10, 14], [11, 13], [12, 17], [13, 15], [14, 15], [16, 17], [16, 18], [16, 19], [17, 18], [17, 19], [18, 19]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l4-s0/tests/run.py b/tasks/construct-nppc-bandwidth-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-nppc-bandwidth-l4-s0/tests/test.sh b/tasks/construct-nppc-bandwidth-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-nppc-bandwidth-l4-s7/environment/Dockerfile b/tasks/construct-nppc-bandwidth-l4-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-nppc-bandwidth-l4-s7/environment/instance.json b/tasks/construct-nppc-bandwidth-l4-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6a128bfd4ffa0bb7be1b07184c49acc88ec2304c --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l4-s7/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 20, "bandwidth": 3, "edges": [[0, 4], [0, 9], [0, 19], [1, 3], [1, 7], [1, 14], [1, 15], [1, 16], [2, 11], [2, 14], [3, 5], [3, 15], [3, 18], [4, 5], [4, 9], [4, 19], [5, 8], [5, 15], [5, 18], [6, 10], [6, 12], [7, 13], [7, 15], [8, 9], [8, 15], [8, 16], [8, 18], [9, 12], [9, 18], [10, 19], [11, 14], [11, 17], [12, 18], [12, 19], [13, 14], [13, 16], [14, 17], [15, 16]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l4-s7/solution/solve.sh b/tasks/construct-nppc-bandwidth-l4-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..460e3920481b3c175775852ab7a2597be588888a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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' +{"layout": [3, 13, 18, 10, 5, 8, 1, 14, 9, 6, 0, 19, 4, 15, 16, 11, 12, 17, 7, 2]} +RLMATH_EOF diff --git a/tasks/construct-nppc-bandwidth-l4-s7/tests/check.py b/tasks/construct-nppc-bandwidth-l4-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0f847cded257e6c404063dfafde33fa44163afa2 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l4-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-l4-s7/tests/instance.json b/tasks/construct-nppc-bandwidth-l4-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6a128bfd4ffa0bb7be1b07184c49acc88ec2304c --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l4-s7/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 20, "bandwidth": 3, "edges": [[0, 4], [0, 9], [0, 19], [1, 3], [1, 7], [1, 14], [1, 15], [1, 16], [2, 11], [2, 14], [3, 5], [3, 15], [3, 18], [4, 5], [4, 9], [4, 19], [5, 8], [5, 15], [5, 18], [6, 10], [6, 12], [7, 13], [7, 15], [8, 9], [8, 15], [8, 16], [8, 18], [9, 12], [9, 18], [10, 19], [11, 14], [11, 17], [12, 18], [12, 19], [13, 14], [13, 16], [14, 17], [15, 16]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l4-s7/tests/run.py b/tasks/construct-nppc-bandwidth-l4-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-nppc-bandwidth-l4-s7/tests/test.sh b/tasks/construct-nppc-bandwidth-l4-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-nppc-clique-l1-s1/environment/Dockerfile b/tasks/construct-nppc-clique-l1-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-clique-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-nppc-clique-l1-s1/environment/instance.json b/tasks/construct-nppc-clique-l1-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1800e24e307e3976f5d4f5958d5cae340be03376 --- /dev/null +++ b/tasks/construct-nppc-clique-l1-s1/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "k": 4, "edges": [[0, 2], [0, 3], [0, 6], [0, 7], [1, 3], [1, 4], [1, 6], [2, 3], [2, 4], [2, 6], [2, 7], [3, 5], [3, 7], [4, 5], [5, 6], [5, 7]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l1-s1/solution/solve.sh b/tasks/construct-nppc-clique-l1-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..91360ad427ed32bd4cf56306e668576f17f674eb --- /dev/null +++ b/tasks/construct-nppc-clique-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' +{"clique": [0, 2, 3, 7]} +RLMATH_EOF diff --git a/tasks/construct-nppc-clique-l1-s1/tests/check.py b/tasks/construct-nppc-clique-l1-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..98eb4fc9097fcfa31988cf0a8b79280cec2b7980 --- /dev/null +++ b/tasks/construct-nppc-clique-l1-s1/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-l1-s1/tests/instance.json b/tasks/construct-nppc-clique-l1-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1800e24e307e3976f5d4f5958d5cae340be03376 --- /dev/null +++ b/tasks/construct-nppc-clique-l1-s1/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "k": 4, "edges": [[0, 2], [0, 3], [0, 6], [0, 7], [1, 3], [1, 4], [1, 6], [2, 3], [2, 4], [2, 6], [2, 7], [3, 5], [3, 7], [4, 5], [5, 6], [5, 7]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l1-s1/tests/run.py b/tasks/construct-nppc-clique-l1-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-clique-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-nppc-clique-l1-s1/tests/test.sh b/tasks/construct-nppc-clique-l1-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-clique-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-nppc-clique-l1-s6/environment/Dockerfile b/tasks/construct-nppc-clique-l1-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-clique-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-nppc-clique-l1-s6/environment/instance.json b/tasks/construct-nppc-clique-l1-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4c3a4ddb8026744692a654a73affec83a3cf452d --- /dev/null +++ b/tasks/construct-nppc-clique-l1-s6/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "k": 4, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [1, 3], [1, 4], [1, 5], [2, 4], [3, 4], [3, 5], [3, 6], [3, 7], [4, 5], [4, 6], [5, 6], [6, 7]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l1-s6/solution/solve.sh b/tasks/construct-nppc-clique-l1-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..bb09dfeda303cb467c5ab44b0f1b9f38b54b676e --- /dev/null +++ b/tasks/construct-nppc-clique-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' +{"clique": [0, 4, 5, 6]} +RLMATH_EOF diff --git a/tasks/construct-nppc-clique-l1-s6/tests/check.py b/tasks/construct-nppc-clique-l1-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..98eb4fc9097fcfa31988cf0a8b79280cec2b7980 --- /dev/null +++ b/tasks/construct-nppc-clique-l1-s6/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-l1-s6/tests/instance.json b/tasks/construct-nppc-clique-l1-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4c3a4ddb8026744692a654a73affec83a3cf452d --- /dev/null +++ b/tasks/construct-nppc-clique-l1-s6/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "k": 4, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [1, 3], [1, 4], [1, 5], [2, 4], [3, 4], [3, 5], [3, 6], [3, 7], [4, 5], [4, 6], [5, 6], [6, 7]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l1-s6/tests/run.py b/tasks/construct-nppc-clique-l1-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-clique-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-nppc-clique-l1-s6/tests/test.sh b/tasks/construct-nppc-clique-l1-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-clique-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-nppc-clique-l5-s7/environment/Dockerfile b/tasks/construct-nppc-clique-l5-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-clique-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-nppc-clique-l5-s7/environment/instance.json b/tasks/construct-nppc-clique-l5-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f8c1248a595dfe162a4a31825e968c8d19ef8293 --- /dev/null +++ b/tasks/construct-nppc-clique-l5-s7/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 40, "k": 20, "edges": [[0, 1], [0, 2], [0, 7], [0, 9], [0, 16], [0, 20], [0, 24], [0, 26], [0, 28], [0, 29], [0, 36], [0, 38], [1, 2], [1, 3], [1, 4], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 22], [1, 24], [1, 25], [1, 27], [1, 28], [1, 29], [1, 30], [1, 31], [1, 32], [1, 33], [1, 34], [1, 35], [1, 36], [1, 38], [1, 39], [2, 4], [2, 5], [2, 6], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 16], [2, 17], [2, 18], [2, 19], [2, 21], [2, 22], [2, 24], [2, 26], [2, 28], [2, 29], [2, 30], [2, 31], [2, 32], [2, 33], [2, 34], [2, 35], [2, 36], [2, 37], [2, 38], [2, 39], [3, 4], [3, 6], [3, 10], [3, 11], [3, 14], [3, 15], [3, 16], [3, 18], [3, 19], [3, 21], [3, 22], [3, 23], [3, 24], [3, 25], [3, 28], [3, 30], [3, 33], [3, 35], [3, 36], [3, 37], [3, 39], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 14], [4, 16], [4, 18], [4, 22], [4, 23], [4, 25], [4, 26], [4, 28], [4, 29], [4, 30], [4, 31], [4, 32], [4, 33], [4, 34], [4, 35], [4, 36], [4, 38], [4, 39], [5, 7], [5, 9], [5, 11], [5, 17], [5, 19], [5, 20], [5, 22], [5, 24], [5, 26], [5, 27], [5, 28], [5, 30], [5, 31], [5, 33], [5, 37], [5, 38], [5, 39], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [6, 16], [6, 18], [6, 19], [6, 20], [6, 22], [6, 24], [6, 25], [6, 28], [6, 29], [6, 30], [6, 31], [6, 32], [6, 33], [6, 34], [6, 36], [6, 38], [7, 10], [7, 11], [7, 15], [7, 18], [7, 20], [7, 22], [7, 24], [7, 25], [7, 26], [7, 27], [7, 28], [7, 31], [7, 33], [7, 34], [7, 39], [8, 9], [8, 10], [8, 11], [8, 14], [8, 15], [8, 16], [8, 17], [8, 18], [8, 20], [8, 22], [8, 25], [8, 27], [8, 28], [8, 29], [8, 30], [8, 31], [8, 32], [8, 33], [8, 34], [8, 36], [8, 37], [8, 38], [9, 10], [9, 11], [9, 13], [9, 14], [9, 15], [9, 16], [9, 18], [9, 19], [9, 20], [9, 21], [9, 22], [9, 23], [9, 25], [9, 27], [9, 28], [9, 29], [9, 30], [9, 31], [9, 32], [9, 33], [9, 34], [9, 35], [9, 36], [9, 38], [9, 39], [10, 11], [10, 12], [10, 14], [10, 15], [10, 16], [10, 17], [10, 18], [10, 19], [10, 21], [10, 22], [10, 23], [10, 25], [10, 26], [10, 28], [10, 29], [10, 30], [10, 31], [10, 32], [10, 33], [10, 34], [10, 36], [10, 37], [10, 38], [10, 39], [11, 12], [11, 14], [11, 15], [11, 16], [11, 17], [11, 18], [11, 20], [11, 21], [11, 22], [11, 26], [11, 28], [11, 29], [11, 30], [11, 31], [11, 32], [11, 33], [11, 34], [11, 35], [11, 36], [11, 38], [11, 39], [12, 15], [12, 16], [12, 20], [12, 21], [12, 22], [12, 25], [12, 28], [12, 31], [12, 38], [12, 39], [13, 16], [13, 20], [13, 22], [13, 26], [13, 27], [13, 28], [13, 31], [13, 39], [14, 15], [14, 17], [14, 18], [14, 23], [14, 25], [14, 26], [14, 27], [14, 29], [14, 30], [14, 31], [14, 34], [14, 35], [14, 37], [14, 39], [15, 16], [15, 22], [15, 23], [15, 27], [15, 28], [15, 30], [15, 35], [15, 37], [15, 38], [16, 18], [16, 22], [16, 23], [16, 26], [16, 27], [16, 28], [16, 29], [16, 30], [16, 31], [16, 32], [16, 33], [16, 34], [16, 35], [16, 36], [16, 37], [16, 38], [17, 19], [17, 20], [17, 25], [17, 27], [17, 29], [17, 30], [17, 31], [17, 32], [17, 34], [17, 36], [17, 38], [17, 39], [18, 20], [18, 22], [18, 23], [18, 26], [18, 28], [18, 29], [18, 30], [18, 31], [18, 32], [18, 33], [18, 34], [18, 36], [18, 37], [18, 38], [18, 39], [19, 20], [19, 21], [19, 22], [19, 26], [19, 28], [19, 29], [19, 31], [19, 38], [19, 39], [20, 21], [20, 24], [20, 27], [20, 28], [20, 30], [20, 31], [20, 32], [20, 33], [20, 34], [21, 23], [21, 29], [21, 31], [21, 33], [21, 34], [21, 35], [21, 36], [21, 38], [22, 23], [22, 24], [22, 28], [22, 29], [22, 30], [22, 31], [22, 32], [22, 33], [22, 34], [22, 36], [22, 37], [22, 38], [23, 24], [23, 25], [23, 26], [23, 27], [23, 30], [23, 32], [23, 35], [23, 37], [23, 39], [24, 25], [24, 26], [24, 27], [24, 29], [24, 32], [24, 34], [24, 35], [24, 36], [24, 37], [24, 39], [25, 26], [25, 28], [25, 31], [25, 32], [25, 33], [25, 36], [25, 37], [26, 30], [26, 31], [26, 33], [26, 34], [26, 36], [26, 37], [26, 39], [27, 28], [27, 30], [27, 31], [27, 32], [27, 34], [27, 37], [27, 38], [27, 39], [28, 29], [28, 30], [28, 31], [28, 32], [28, 33], [28, 34], [28, 36], [28, 38], [29, 30], [29, 31], [29, 32], [29, 33], [29, 34], [29, 36], [29, 37], [29, 38], [29, 39], [30, 31], [30, 32], [30, 33], [30, 34], [30, 35], [30, 36], [30, 37], [30, 38], [30, 39], [31, 32], [31, 33], [31, 34], [31, 35], [31, 36], [31, 38], [31, 39], [32, 33], [32, 34], [32, 35], [32, 36], [32, 37], [32, 38], [33, 34], [33, 35], [33, 36], [33, 38], [34, 35], [34, 36], [34, 37], [34, 38], [35, 36], [35, 37], [36, 37], [36, 38], [37, 39], [38, 39]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l5-s7/solution/solve.sh b/tasks/construct-nppc-clique-l5-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9fee0761d61c2151c773da312caab51017f5f2ab --- /dev/null +++ b/tasks/construct-nppc-clique-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' +{"clique": [1, 2, 4, 6, 8, 9, 10, 11, 16, 18, 22, 28, 29, 30, 31, 32, 33, 34, 36, 38]} +RLMATH_EOF diff --git a/tasks/construct-nppc-clique-l5-s7/tests/check.py b/tasks/construct-nppc-clique-l5-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..98eb4fc9097fcfa31988cf0a8b79280cec2b7980 --- /dev/null +++ b/tasks/construct-nppc-clique-l5-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-l5-s7/tests/instance.json b/tasks/construct-nppc-clique-l5-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f8c1248a595dfe162a4a31825e968c8d19ef8293 --- /dev/null +++ b/tasks/construct-nppc-clique-l5-s7/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 40, "k": 20, "edges": [[0, 1], [0, 2], [0, 7], [0, 9], [0, 16], [0, 20], [0, 24], [0, 26], [0, 28], [0, 29], [0, 36], [0, 38], [1, 2], [1, 3], [1, 4], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 22], [1, 24], [1, 25], [1, 27], [1, 28], [1, 29], [1, 30], [1, 31], [1, 32], [1, 33], [1, 34], [1, 35], [1, 36], [1, 38], [1, 39], [2, 4], [2, 5], [2, 6], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 16], [2, 17], [2, 18], [2, 19], [2, 21], [2, 22], [2, 24], [2, 26], [2, 28], [2, 29], [2, 30], [2, 31], [2, 32], [2, 33], [2, 34], [2, 35], [2, 36], [2, 37], [2, 38], [2, 39], [3, 4], [3, 6], [3, 10], [3, 11], [3, 14], [3, 15], [3, 16], [3, 18], [3, 19], [3, 21], [3, 22], [3, 23], [3, 24], [3, 25], [3, 28], [3, 30], [3, 33], [3, 35], [3, 36], [3, 37], [3, 39], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 14], [4, 16], [4, 18], [4, 22], [4, 23], [4, 25], [4, 26], [4, 28], [4, 29], [4, 30], [4, 31], [4, 32], [4, 33], [4, 34], [4, 35], [4, 36], [4, 38], [4, 39], [5, 7], [5, 9], [5, 11], [5, 17], [5, 19], [5, 20], [5, 22], [5, 24], [5, 26], [5, 27], [5, 28], [5, 30], [5, 31], [5, 33], [5, 37], [5, 38], [5, 39], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [6, 16], [6, 18], [6, 19], [6, 20], [6, 22], [6, 24], [6, 25], [6, 28], [6, 29], [6, 30], [6, 31], [6, 32], [6, 33], [6, 34], [6, 36], [6, 38], [7, 10], [7, 11], [7, 15], [7, 18], [7, 20], [7, 22], [7, 24], [7, 25], [7, 26], [7, 27], [7, 28], [7, 31], [7, 33], [7, 34], [7, 39], [8, 9], [8, 10], [8, 11], [8, 14], [8, 15], [8, 16], [8, 17], [8, 18], [8, 20], [8, 22], [8, 25], [8, 27], [8, 28], [8, 29], [8, 30], [8, 31], [8, 32], [8, 33], [8, 34], [8, 36], [8, 37], [8, 38], [9, 10], [9, 11], [9, 13], [9, 14], [9, 15], [9, 16], [9, 18], [9, 19], [9, 20], [9, 21], [9, 22], [9, 23], [9, 25], [9, 27], [9, 28], [9, 29], [9, 30], [9, 31], [9, 32], [9, 33], [9, 34], [9, 35], [9, 36], [9, 38], [9, 39], [10, 11], [10, 12], [10, 14], [10, 15], [10, 16], [10, 17], [10, 18], [10, 19], [10, 21], [10, 22], [10, 23], [10, 25], [10, 26], [10, 28], [10, 29], [10, 30], [10, 31], [10, 32], [10, 33], [10, 34], [10, 36], [10, 37], [10, 38], [10, 39], [11, 12], [11, 14], [11, 15], [11, 16], [11, 17], [11, 18], [11, 20], [11, 21], [11, 22], [11, 26], [11, 28], [11, 29], [11, 30], [11, 31], [11, 32], [11, 33], [11, 34], [11, 35], [11, 36], [11, 38], [11, 39], [12, 15], [12, 16], [12, 20], [12, 21], [12, 22], [12, 25], [12, 28], [12, 31], [12, 38], [12, 39], [13, 16], [13, 20], [13, 22], [13, 26], [13, 27], [13, 28], [13, 31], [13, 39], [14, 15], [14, 17], [14, 18], [14, 23], [14, 25], [14, 26], [14, 27], [14, 29], [14, 30], [14, 31], [14, 34], [14, 35], [14, 37], [14, 39], [15, 16], [15, 22], [15, 23], [15, 27], [15, 28], [15, 30], [15, 35], [15, 37], [15, 38], [16, 18], [16, 22], [16, 23], [16, 26], [16, 27], [16, 28], [16, 29], [16, 30], [16, 31], [16, 32], [16, 33], [16, 34], [16, 35], [16, 36], [16, 37], [16, 38], [17, 19], [17, 20], [17, 25], [17, 27], [17, 29], [17, 30], [17, 31], [17, 32], [17, 34], [17, 36], [17, 38], [17, 39], [18, 20], [18, 22], [18, 23], [18, 26], [18, 28], [18, 29], [18, 30], [18, 31], [18, 32], [18, 33], [18, 34], [18, 36], [18, 37], [18, 38], [18, 39], [19, 20], [19, 21], [19, 22], [19, 26], [19, 28], [19, 29], [19, 31], [19, 38], [19, 39], [20, 21], [20, 24], [20, 27], [20, 28], [20, 30], [20, 31], [20, 32], [20, 33], [20, 34], [21, 23], [21, 29], [21, 31], [21, 33], [21, 34], [21, 35], [21, 36], [21, 38], [22, 23], [22, 24], [22, 28], [22, 29], [22, 30], [22, 31], [22, 32], [22, 33], [22, 34], [22, 36], [22, 37], [22, 38], [23, 24], [23, 25], [23, 26], [23, 27], [23, 30], [23, 32], [23, 35], [23, 37], [23, 39], [24, 25], [24, 26], [24, 27], [24, 29], [24, 32], [24, 34], [24, 35], [24, 36], [24, 37], [24, 39], [25, 26], [25, 28], [25, 31], [25, 32], [25, 33], [25, 36], [25, 37], [26, 30], [26, 31], [26, 33], [26, 34], [26, 36], [26, 37], [26, 39], [27, 28], [27, 30], [27, 31], [27, 32], [27, 34], [27, 37], [27, 38], [27, 39], [28, 29], [28, 30], [28, 31], [28, 32], [28, 33], [28, 34], [28, 36], [28, 38], [29, 30], [29, 31], [29, 32], [29, 33], [29, 34], [29, 36], [29, 37], [29, 38], [29, 39], [30, 31], [30, 32], [30, 33], [30, 34], [30, 35], [30, 36], [30, 37], [30, 38], [30, 39], [31, 32], [31, 33], [31, 34], [31, 35], [31, 36], [31, 38], [31, 39], [32, 33], [32, 34], [32, 35], [32, 36], [32, 37], [32, 38], [33, 34], [33, 35], [33, 36], [33, 38], [34, 35], [34, 36], [34, 37], [34, 38], [35, 36], [35, 37], [36, 37], [36, 38], [37, 39], [38, 39]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l5-s7/tests/run.py b/tasks/construct-nppc-clique-l5-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-clique-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-nppc-clique-l5-s7/tests/test.sh b/tasks/construct-nppc-clique-l5-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-clique-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-nppc-clique-l5-s9/environment/Dockerfile b/tasks/construct-nppc-clique-l5-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-clique-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-nppc-clique-l5-s9/environment/instance.json b/tasks/construct-nppc-clique-l5-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b3e3eb2a2f500bad857e835b322a7292e8c46db9 --- /dev/null +++ b/tasks/construct-nppc-clique-l5-s9/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 40, "k": 20, "edges": [[0, 3], [0, 4], [0, 5], [0, 12], [0, 16], [0, 19], [0, 20], [0, 21], [0, 23], [0, 25], [0, 30], [0, 33], [0, 34], [0, 36], [0, 37], [0, 39], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 8], [1, 9], [1, 11], [1, 12], [1, 13], [1, 15], [1, 16], [1, 19], [1, 20], [1, 21], [1, 23], [1, 26], [1, 28], [1, 30], [1, 33], [1, 35], [1, 36], [1, 37], [1, 39], [2, 3], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [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], [2, 29], [2, 30], [2, 31], [2, 33], [2, 34], [2, 36], [2, 37], [2, 39], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 14], [3, 15], [3, 17], [3, 19], [3, 20], [3, 22], [3, 23], [3, 24], [3, 25], [3, 26], [3, 27], [3, 28], [3, 29], [3, 30], [3, 31], [3, 33], [3, 36], [3, 37], [3, 38], [3, 39], [4, 5], [4, 6], [4, 10], [4, 13], [4, 14], [4, 18], [4, 20], [4, 21], [4, 26], [4, 27], [4, 28], [4, 29], [4, 32], [4, 33], [4, 35], [4, 36], [5, 7], [5, 9], [5, 11], [5, 13], [5, 14], [5, 16], [5, 17], [5, 18], [5, 20], [5, 21], [5, 23], [5, 26], [5, 29], [5, 30], [5, 32], [5, 35], [5, 39], [6, 7], [6, 8], [6, 9], [6, 10], [6, 12], [6, 14], [6, 15], [6, 16], [6, 17], [6, 18], [6, 19], [6, 20], [6, 22], [6, 23], [6, 24], [6, 26], [6, 27], [6, 28], [6, 29], [6, 30], [6, 31], [6, 33], [6, 34], [6, 35], [6, 36], [6, 37], [6, 38], [6, 39], [7, 8], [7, 9], [7, 10], [7, 11], [7, 14], [7, 15], [7, 16], [7, 17], [7, 18], [7, 20], [7, 22], [7, 23], [7, 24], [7, 26], [7, 28], [7, 29], [7, 30], [7, 31], [7, 33], [7, 35], [7, 36], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [8, 14], [8, 15], [8, 17], [8, 19], [8, 20], [8, 21], [8, 22], [8, 23], [8, 24], [8, 26], [8, 27], [8, 29], [8, 30], [8, 31], [8, 33], [8, 35], [8, 36], [9, 10], [9, 14], [9, 15], [9, 17], [9, 19], [9, 20], [9, 21], [9, 22], [9, 23], [9, 24], [9, 26], [9, 29], [9, 30], [9, 31], [9, 32], [9, 33], [9, 34], [9, 35], [9, 36], [9, 38], [9, 39], [10, 11], [10, 12], [10, 14], [10, 15], [10, 16], [10, 17], [10, 19], [10, 20], [10, 21], [10, 22], [10, 23], [10, 24], [10, 26], [10, 29], [10, 30], [10, 31], [10, 33], [10, 35], [10, 36], [10, 39], [11, 12], [11, 13], [11, 15], [11, 16], [11, 17], [11, 20], [11, 24], [11, 25], [11, 28], [11, 30], [11, 31], [11, 32], [11, 35], [11, 36], [11, 37], [11, 38], [12, 15], [12, 16], [12, 19], [12, 23], [12, 25], [12, 26], [12, 27], [12, 28], [12, 31], [12, 36], [12, 37], [12, 39], [13, 14], [13, 19], [13, 21], [13, 22], [13, 23], [13, 24], [13, 25], [13, 28], [13, 30], [13, 31], [13, 32], [13, 34], [13, 37], [13, 39], [14, 15], [14, 16], [14, 17], [14, 18], [14, 20], [14, 22], [14, 23], [14, 24], [14, 26], [14, 27], [14, 29], [14, 30], [14, 31], [14, 32], [14, 33], [14, 35], [14, 36], [14, 38], [14, 39], [15, 17], [15, 20], [15, 22], [15, 23], [15, 24], [15, 25], [15, 26], [15, 29], [15, 30], [15, 31], [15, 33], [15, 34], [15, 35], [15, 36], [15, 38], [16, 17], [16, 18], [16, 19], [16, 24], [16, 25], [16, 26], [16, 28], [16, 32], [16, 34], [16, 36], [16, 37], [17, 19], [17, 20], [17, 22], [17, 23], [17, 24], [17, 25], [17, 26], [17, 28], [17, 29], [17, 30], [17, 31], [17, 32], [17, 33], [17, 36], [17, 38], [17, 39], [18, 19], [18, 20], [18, 21], [18, 22], [18, 29], [18, 32], [18, 33], [18, 36], [18, 37], [19, 20], [19, 21], [19, 23], [19, 24], [19, 25], [19, 27], [19, 28], [19, 29], [19, 30], [19, 33], [19, 34], [19, 36], [20, 21], [20, 22], [20, 23], [20, 24], [20, 25], [20, 26], [20, 27], [20, 29], [20, 30], [20, 31], [20, 33], [20, 34], [20, 36], [20, 37], [20, 38], [20, 39], [21, 22], [21, 24], [21, 26], [21, 29], [21, 30], [21, 32], [21, 34], [21, 37], [22, 23], [22, 24], [22, 26], [22, 29], [22, 30], [22, 31], [22, 33], [22, 34], [22, 36], [22, 37], [22, 38], [23, 24], [23, 26], [23, 27], [23, 28], [23, 29], [23, 30], [23, 31], [23, 33], [23, 35], [23, 36], [23, 37], [24, 25], [24, 26], [24, 27], [24, 29], [24, 30], [24, 31], [24, 32], [24, 33], [24, 35], [24, 36], [25, 26], [25, 28], [25, 30], [25, 31], [25, 32], [25, 35], [25, 36], [25, 37], [26, 28], [26, 29], [26, 30], [26, 31], [26, 32], [26, 33], [26, 35], [26, 36], [26, 37], [26, 38], [27, 33], [27, 37], [27, 39], [28, 29], [28, 30], [28, 32], [28, 33], [28, 35], [28, 36], [28, 38], [29, 30], [29, 31], [29, 32], [29, 33], [29, 34], [29, 36], [30, 31], [30, 33], [30, 34], [30, 35], [30, 36], [30, 38], [30, 39], [31, 32], [31, 33], [31, 34], [31, 36], [32, 33], [32, 35], [32, 37], [32, 38], [33, 34], [33, 36], [33, 37], [33, 38], [33, 39], [34, 35], [34, 38], [35, 36], [35, 37], [35, 38], [36, 39], [37, 38], [37, 39], [38, 39]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l5-s9/solution/solve.sh b/tasks/construct-nppc-clique-l5-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..06bf14b2571de263e9bec86f440f555c0ab00e2d --- /dev/null +++ b/tasks/construct-nppc-clique-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' +{"clique": [2, 3, 6, 7, 8, 9, 10, 14, 15, 17, 20, 22, 23, 24, 26, 29, 30, 31, 33, 36]} +RLMATH_EOF diff --git a/tasks/construct-nppc-clique-l5-s9/tests/check.py b/tasks/construct-nppc-clique-l5-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..98eb4fc9097fcfa31988cf0a8b79280cec2b7980 --- /dev/null +++ b/tasks/construct-nppc-clique-l5-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-l5-s9/tests/instance.json b/tasks/construct-nppc-clique-l5-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b3e3eb2a2f500bad857e835b322a7292e8c46db9 --- /dev/null +++ b/tasks/construct-nppc-clique-l5-s9/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 40, "k": 20, "edges": [[0, 3], [0, 4], [0, 5], [0, 12], [0, 16], [0, 19], [0, 20], [0, 21], [0, 23], [0, 25], [0, 30], [0, 33], [0, 34], [0, 36], [0, 37], [0, 39], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 8], [1, 9], [1, 11], [1, 12], [1, 13], [1, 15], [1, 16], [1, 19], [1, 20], [1, 21], [1, 23], [1, 26], [1, 28], [1, 30], [1, 33], [1, 35], [1, 36], [1, 37], [1, 39], [2, 3], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [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], [2, 29], [2, 30], [2, 31], [2, 33], [2, 34], [2, 36], [2, 37], [2, 39], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 14], [3, 15], [3, 17], [3, 19], [3, 20], [3, 22], [3, 23], [3, 24], [3, 25], [3, 26], [3, 27], [3, 28], [3, 29], [3, 30], [3, 31], [3, 33], [3, 36], [3, 37], [3, 38], [3, 39], [4, 5], [4, 6], [4, 10], [4, 13], [4, 14], [4, 18], [4, 20], [4, 21], [4, 26], [4, 27], [4, 28], [4, 29], [4, 32], [4, 33], [4, 35], [4, 36], [5, 7], [5, 9], [5, 11], [5, 13], [5, 14], [5, 16], [5, 17], [5, 18], [5, 20], [5, 21], [5, 23], [5, 26], [5, 29], [5, 30], [5, 32], [5, 35], [5, 39], [6, 7], [6, 8], [6, 9], [6, 10], [6, 12], [6, 14], [6, 15], [6, 16], [6, 17], [6, 18], [6, 19], [6, 20], [6, 22], [6, 23], [6, 24], [6, 26], [6, 27], [6, 28], [6, 29], [6, 30], [6, 31], [6, 33], [6, 34], [6, 35], [6, 36], [6, 37], [6, 38], [6, 39], [7, 8], [7, 9], [7, 10], [7, 11], [7, 14], [7, 15], [7, 16], [7, 17], [7, 18], [7, 20], [7, 22], [7, 23], [7, 24], [7, 26], [7, 28], [7, 29], [7, 30], [7, 31], [7, 33], [7, 35], [7, 36], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [8, 14], [8, 15], [8, 17], [8, 19], [8, 20], [8, 21], [8, 22], [8, 23], [8, 24], [8, 26], [8, 27], [8, 29], [8, 30], [8, 31], [8, 33], [8, 35], [8, 36], [9, 10], [9, 14], [9, 15], [9, 17], [9, 19], [9, 20], [9, 21], [9, 22], [9, 23], [9, 24], [9, 26], [9, 29], [9, 30], [9, 31], [9, 32], [9, 33], [9, 34], [9, 35], [9, 36], [9, 38], [9, 39], [10, 11], [10, 12], [10, 14], [10, 15], [10, 16], [10, 17], [10, 19], [10, 20], [10, 21], [10, 22], [10, 23], [10, 24], [10, 26], [10, 29], [10, 30], [10, 31], [10, 33], [10, 35], [10, 36], [10, 39], [11, 12], [11, 13], [11, 15], [11, 16], [11, 17], [11, 20], [11, 24], [11, 25], [11, 28], [11, 30], [11, 31], [11, 32], [11, 35], [11, 36], [11, 37], [11, 38], [12, 15], [12, 16], [12, 19], [12, 23], [12, 25], [12, 26], [12, 27], [12, 28], [12, 31], [12, 36], [12, 37], [12, 39], [13, 14], [13, 19], [13, 21], [13, 22], [13, 23], [13, 24], [13, 25], [13, 28], [13, 30], [13, 31], [13, 32], [13, 34], [13, 37], [13, 39], [14, 15], [14, 16], [14, 17], [14, 18], [14, 20], [14, 22], [14, 23], [14, 24], [14, 26], [14, 27], [14, 29], [14, 30], [14, 31], [14, 32], [14, 33], [14, 35], [14, 36], [14, 38], [14, 39], [15, 17], [15, 20], [15, 22], [15, 23], [15, 24], [15, 25], [15, 26], [15, 29], [15, 30], [15, 31], [15, 33], [15, 34], [15, 35], [15, 36], [15, 38], [16, 17], [16, 18], [16, 19], [16, 24], [16, 25], [16, 26], [16, 28], [16, 32], [16, 34], [16, 36], [16, 37], [17, 19], [17, 20], [17, 22], [17, 23], [17, 24], [17, 25], [17, 26], [17, 28], [17, 29], [17, 30], [17, 31], [17, 32], [17, 33], [17, 36], [17, 38], [17, 39], [18, 19], [18, 20], [18, 21], [18, 22], [18, 29], [18, 32], [18, 33], [18, 36], [18, 37], [19, 20], [19, 21], [19, 23], [19, 24], [19, 25], [19, 27], [19, 28], [19, 29], [19, 30], [19, 33], [19, 34], [19, 36], [20, 21], [20, 22], [20, 23], [20, 24], [20, 25], [20, 26], [20, 27], [20, 29], [20, 30], [20, 31], [20, 33], [20, 34], [20, 36], [20, 37], [20, 38], [20, 39], [21, 22], [21, 24], [21, 26], [21, 29], [21, 30], [21, 32], [21, 34], [21, 37], [22, 23], [22, 24], [22, 26], [22, 29], [22, 30], [22, 31], [22, 33], [22, 34], [22, 36], [22, 37], [22, 38], [23, 24], [23, 26], [23, 27], [23, 28], [23, 29], [23, 30], [23, 31], [23, 33], [23, 35], [23, 36], [23, 37], [24, 25], [24, 26], [24, 27], [24, 29], [24, 30], [24, 31], [24, 32], [24, 33], [24, 35], [24, 36], [25, 26], [25, 28], [25, 30], [25, 31], [25, 32], [25, 35], [25, 36], [25, 37], [26, 28], [26, 29], [26, 30], [26, 31], [26, 32], [26, 33], [26, 35], [26, 36], [26, 37], [26, 38], [27, 33], [27, 37], [27, 39], [28, 29], [28, 30], [28, 32], [28, 33], [28, 35], [28, 36], [28, 38], [29, 30], [29, 31], [29, 32], [29, 33], [29, 34], [29, 36], [30, 31], [30, 33], [30, 34], [30, 35], [30, 36], [30, 38], [30, 39], [31, 32], [31, 33], [31, 34], [31, 36], [32, 33], [32, 35], [32, 37], [32, 38], [33, 34], [33, 36], [33, 37], [33, 38], [33, 39], [34, 35], [34, 38], [35, 36], [35, 37], [35, 38], [36, 39], [37, 38], [37, 39], [38, 39]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l5-s9/tests/run.py b/tasks/construct-nppc-clique-l5-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-clique-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-nppc-clique-l5-s9/tests/test.sh b/tasks/construct-nppc-clique-l5-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-clique-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-nppc-dominating-set-l1-s1/environment/Dockerfile b/tasks/construct-nppc-dominating-set-l1-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-dominating-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-nppc-dominating-set-l1-s1/environment/instance.json b/tasks/construct-nppc-dominating-set-l1-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fc00078657bc112297085d2b2f4c18f16aea9cd7 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l1-s1/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 10, "k": 5, "edges": [[0, 2], [0, 3], [0, 5], [1, 4], [1, 6], [1, 9], [2, 3], [2, 5], [2, 6], [2, 7], [2, 9], [3, 5], [3, 7], [3, 9], [4, 6], [5, 6], [5, 7], [5, 9], [6, 8], [8, 9]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l1-s1/solution/solve.sh b/tasks/construct-nppc-dominating-set-l1-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1c1227baf078d7a7dc1e0e4fe982b52951f4747e --- /dev/null +++ b/tasks/construct-nppc-dominating-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' +{"dominating_set": [2, 3, 4, 6, 9]} +RLMATH_EOF diff --git a/tasks/construct-nppc-dominating-set-l1-s1/tests/check.py b/tasks/construct-nppc-dominating-set-l1-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0677a7bcbccb02297d022ffa4b5dd15da6371bff --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l1-s1/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-l1-s1/tests/instance.json b/tasks/construct-nppc-dominating-set-l1-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fc00078657bc112297085d2b2f4c18f16aea9cd7 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l1-s1/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 10, "k": 5, "edges": [[0, 2], [0, 3], [0, 5], [1, 4], [1, 6], [1, 9], [2, 3], [2, 5], [2, 6], [2, 7], [2, 9], [3, 5], [3, 7], [3, 9], [4, 6], [5, 6], [5, 7], [5, 9], [6, 8], [8, 9]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l1-s1/tests/run.py b/tasks/construct-nppc-dominating-set-l1-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-dominating-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-nppc-dominating-set-l1-s1/tests/test.sh b/tasks/construct-nppc-dominating-set-l1-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-dominating-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-nppc-dominating-set-l1-s6/environment/Dockerfile b/tasks/construct-nppc-dominating-set-l1-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-dominating-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-nppc-dominating-set-l1-s6/environment/instance.json b/tasks/construct-nppc-dominating-set-l1-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e2cbefb962f382c42420e04a6b483b4cf61d7faa --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l1-s6/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 10, "k": 5, "edges": [[0, 6], [1, 2], [1, 4], [1, 5], [2, 4], [2, 8], [3, 4], [3, 5], [3, 7], [3, 8], [3, 9], [4, 6], [5, 6], [5, 8], [6, 7], [7, 9], [8, 9]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l1-s6/solution/solve.sh b/tasks/construct-nppc-dominating-set-l1-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d469655283ed1f2dbb0c4fe4d7638dbf5cc5f651 --- /dev/null +++ b/tasks/construct-nppc-dominating-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' +{"dominating_set": [1, 3, 6, 8, 9]} +RLMATH_EOF diff --git a/tasks/construct-nppc-dominating-set-l1-s6/tests/check.py b/tasks/construct-nppc-dominating-set-l1-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0677a7bcbccb02297d022ffa4b5dd15da6371bff --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l1-s6/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-l1-s6/tests/instance.json b/tasks/construct-nppc-dominating-set-l1-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e2cbefb962f382c42420e04a6b483b4cf61d7faa --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l1-s6/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 10, "k": 5, "edges": [[0, 6], [1, 2], [1, 4], [1, 5], [2, 4], [2, 8], [3, 4], [3, 5], [3, 7], [3, 8], [3, 9], [4, 6], [5, 6], [5, 8], [6, 7], [7, 9], [8, 9]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l1-s6/tests/run.py b/tasks/construct-nppc-dominating-set-l1-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-dominating-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-nppc-dominating-set-l1-s6/tests/test.sh b/tasks/construct-nppc-dominating-set-l1-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-dominating-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-nppc-dominating-set-l5-s9/environment/Dockerfile b/tasks/construct-nppc-dominating-set-l5-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-dominating-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-nppc-dominating-set-l5-s9/environment/instance.json b/tasks/construct-nppc-dominating-set-l5-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4b8a5c9e29e87aaa6a261b29e9860898c3ac96d0 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l5-s9/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 180, "k": 15, "edges": [[0, 3], [0, 13], [0, 15], [0, 17], [0, 18], [0, 19], [0, 26], [0, 38], [0, 39], [0, 53], [0, 65], [0, 68], [0, 71], [0, 78], [0, 95], [0, 97], [0, 100], [0, 101], [0, 106], [0, 116], [0, 123], [0, 127], [0, 128], [0, 131], [0, 133], [0, 135], [0, 143], [0, 147], [0, 148], [0, 153], [0, 158], [0, 159], [0, 160], [0, 161], [0, 168], [0, 178], [1, 2], [1, 10], [1, 12], [1, 15], [1, 21], [1, 22], [1, 24], [1, 25], [1, 27], [1, 33], [1, 35], [1, 38], [1, 40], [1, 44], [1, 45], [1, 49], [1, 57], [1, 64], [1, 65], [1, 82], [1, 86], [1, 90], [1, 91], [1, 94], [1, 96], [1, 104], [1, 116], [1, 120], [1, 125], [1, 127], [1, 131], [1, 143], [1, 145], [1, 152], [1, 154], [1, 166], [1, 167], [1, 170], [1, 173], [1, 174], [1, 175], [1, 176], [1, 179], [2, 6], [2, 9], [2, 15], [2, 22], [2, 23], [2, 34], [2, 36], [2, 39], [2, 42], [2, 45], [2, 61], [2, 68], [2, 69], [2, 71], [2, 74], [2, 76], [2, 77], [2, 90], [2, 103], [2, 106], [2, 107], [2, 110], [2, 123], [2, 130], [2, 134], [2, 143], [2, 147], [2, 148], [2, 164], [2, 165], [2, 166], [2, 168], [2, 173], [2, 177], [3, 4], [3, 7], [3, 10], [3, 17], [3, 19], [3, 22], [3, 29], [3, 32], [3, 38], [3, 48], [3, 56], [3, 70], [3, 76], [3, 83], [3, 86], [3, 87], [3, 89], [3, 92], [3, 94], [3, 102], [3, 103], [3, 114], [3, 115], [3, 123], [3, 130], [3, 133], [3, 136], [3, 141], [3, 142], [3, 143], [3, 148], [3, 149], [3, 152], [3, 153], [3, 156], [3, 159], [3, 161], [3, 164], [3, 165], [3, 171], [3, 173], [4, 7], [4, 10], [4, 11], [4, 14], [4, 17], [4, 21], [4, 23], [4, 30], [4, 35], [4, 36], [4, 39], [4, 53], [4, 65], [4, 72], [4, 75], [4, 76], [4, 81], [4, 102], [4, 104], [4, 109], [4, 111], [4, 115], [4, 116], [4, 120], [4, 128], [4, 130], [4, 131], [4, 134], [4, 144], [4, 146], [4, 149], [4, 153], [4, 154], [4, 156], [4, 159], [4, 161], [4, 162], [4, 164], [4, 166], [4, 168], [4, 169], [4, 178], [5, 8], [5, 12], [5, 17], [5, 27], [5, 32], [5, 33], [5, 40], [5, 41], [5, 43], [5, 44], [5, 49], [5, 57], [5, 61], [5, 62], [5, 65], [5, 79], [5, 86], [5, 89], [5, 96], [5, 97], [5, 103], [5, 111], [5, 118], [5, 122], [5, 127], [5, 130], [5, 131], [5, 137], [5, 138], [5, 140], [5, 142], [5, 144], [5, 149], [5, 165], [5, 175], [6, 8], [6, 12], [6, 27], [6, 29], [6, 38], [6, 40], [6, 42], [6, 43], [6, 44], [6, 48], [6, 50], [6, 55], [6, 62], [6, 70], [6, 72], [6, 103], [6, 104], [6, 105], [6, 107], [6, 115], [6, 119], [6, 122], [6, 123], [6, 128], [6, 136], [6, 137], [6, 147], [6, 153], [6, 154], [6, 165], [6, 175], [6, 179], [7, 9], [7, 16], [7, 35], [7, 36], [7, 38], [7, 40], [7, 43], [7, 45], [7, 58], [7, 63], [7, 65], [7, 66], [7, 68], [7, 69], [7, 71], [7, 75], [7, 76], [7, 84], [7, 89], [7, 96], [7, 102], [7, 106], [7, 114], [7, 116], [7, 117], [7, 118], [7, 126], [7, 146], [7, 152], [7, 156], [7, 157], [7, 161], [7, 165], [7, 166], [7, 169], [7, 172], [7, 175], [7, 177], [8, 11], [8, 12], [8, 13], [8, 15], [8, 16], [8, 26], [8, 28], [8, 30], [8, 38], [8, 52], [8, 53], [8, 54], [8, 55], [8, 71], [8, 73], [8, 76], [8, 77], [8, 78], [8, 79], [8, 81], [8, 84], [8, 85], [8, 93], [8, 101], [8, 104], [8, 108], [8, 110], [8, 115], [8, 125], [8, 137], [8, 139], [8, 142], [8, 149], [8, 154], [8, 158], [8, 162], [8, 168], [8, 169], [8, 175], [9, 10], [9, 13], [9, 19], [9, 21], [9, 23], [9, 28], [9, 30], [9, 36], [9, 48], [9, 50], [9, 53], [9, 55], [9, 56], [9, 64], [9, 65], [9, 70], [9, 77], [9, 82], [9, 84], [9, 88], [9, 95], [9, 97], [9, 100], [9, 114], [9, 116], [9, 118], [9, 119], [9, 123], [9, 141], [9, 147], [9, 153], [9, 155], [9, 159], [9, 162], [9, 172], [9, 174], [10, 19], [10, 22], [10, 34], [10, 48], [10, 52], [10, 53], [10, 59], [10, 61], [10, 69], [10, 74], [10, 81], [10, 84], [10, 86], [10, 92], [10, 95], [10, 101], [10, 103], [10, 105], [10, 107], [10, 108], [10, 115], [10, 117], [10, 142], [10, 153], [10, 156], [10, 160], [10, 162], [10, 170], [10, 173], [10, 179], [11, 23], [11, 30], [11, 36], [11, 37], [11, 41], [11, 46], [11, 49], [11, 51], [11, 52], [11, 54], [11, 55], [11, 59], [11, 68], [11, 70], [11, 76], [11, 79], [11, 80], [11, 83], [11, 89], [11, 91], [11, 92], [11, 95], [11, 97], [11, 100], [11, 101], [11, 103], [11, 105], [11, 107], [11, 116], [11, 122], [11, 123], [11, 134], [11, 135], [11, 136], [11, 152], [11, 156], [11, 159], [11, 165], [11, 171], [11, 173], [11, 176], [12, 14], [12, 15], [12, 17], [12, 19], [12, 35], [12, 38], [12, 47], [12, 52], [12, 53], [12, 56], [12, 62], [12, 63], [12, 69], [12, 71], [12, 76], [12, 80], [12, 81], [12, 83], [12, 84], [12, 90], [12, 92], [12, 99], [12, 103], [12, 104], [12, 109], [12, 111], [12, 114], [12, 119], [12, 122], [12, 126], [12, 132], [12, 133], [12, 142], [12, 148], [12, 165], [12, 170], [12, 171], [12, 174], [12, 175], [13, 17], [13, 26], [13, 27], [13, 39], [13, 41], [13, 43], [13, 50], [13, 55], [13, 58], [13, 59], [13, 65], [13, 66], [13, 76], [13, 80], [13, 84], [13, 89], [13, 90], [13, 95], [13, 98], [13, 103], [13, 110], [13, 116], [13, 117], [13, 121], [13, 130], [13, 136], [13, 145], [13, 153], [13, 158], [13, 162], [13, 173], [13, 174], [13, 179], [14, 18], [14, 23], [14, 27], [14, 36], [14, 42], [14, 45], [14, 59], [14, 84], [14, 90], [14, 110], [14, 117], [14, 119], [14, 120], [14, 129], [14, 142], [14, 155], [14, 160], [14, 162], [14, 165], [14, 167], [14, 170], [14, 175], [14, 179], [15, 22], [15, 61], [15, 62], [15, 65], [15, 74], [15, 78], [15, 93], [15, 94], [15, 100], [15, 105], [15, 114], [15, 124], [15, 132], [15, 133], [15, 134], [15, 137], [15, 143], [15, 151], [15, 154], [15, 155], [15, 157], [15, 158], [15, 160], [15, 171], [16, 20], [16, 40], [16, 41], [16, 43], [16, 52], [16, 60], [16, 69], [16, 77], [16, 83], [16, 86], [16, 89], [16, 90], [16, 91], [16, 96], [16, 97], [16, 100], [16, 103], [16, 107], [16, 112], [16, 117], [16, 122], [16, 124], [16, 129], [16, 141], [16, 151], [16, 158], [16, 160], [16, 164], [16, 168], [16, 169], [16, 174], [16, 177], [17, 18], [17, 24], [17, 26], [17, 32], [17, 33], [17, 34], [17, 41], [17, 42], [17, 53], [17, 54], [17, 55], [17, 56], [17, 61], [17, 67], [17, 75], [17, 77], [17, 82], [17, 86], [17, 87], [17, 94], [17, 103], [17, 107], [17, 108], [17, 135], [17, 136], [17, 142], [17, 144], [17, 151], [17, 153], [17, 156], [17, 168], [17, 172], [18, 27], [18, 30], [18, 36], [18, 48], [18, 67], [18, 76], [18, 81], [18, 87], [18, 90], [18, 100], [18, 102], [18, 108], [18, 111], [18, 117], [18, 120], [18, 127], [18, 134], [18, 148], [18, 150], [18, 152], [18, 156], [18, 164], [18, 167], [18, 170], [19, 25], [19, 36], [19, 37], [19, 40], [19, 51], [19, 58], [19, 61], [19, 63], [19, 67], [19, 73], [19, 75], [19, 82], [19, 83], [19, 86], [19, 95], [19, 97], [19, 99], [19, 100], [19, 111], [19, 117], [19, 123], [19, 125], [19, 128], [19, 129], [19, 135], [19, 153], [19, 160], [19, 166], [19, 167], [19, 169], [19, 175], [19, 179], [20, 25], [20, 28], [20, 30], [20, 34], [20, 37], [20, 43], [20, 47], [20, 48], [20, 52], [20, 55], [20, 66], [20, 69], [20, 72], [20, 93], [20, 100], [20, 104], [20, 105], [20, 107], [20, 110], [20, 111], [20, 113], [20, 117], [20, 130], [20, 132], [20, 135], [20, 138], [20, 150], [20, 157], [20, 158], [20, 163], [20, 174], [21, 32], [21, 33], [21, 34], [21, 37], [21, 45], [21, 46], [21, 55], [21, 64], [21, 66], [21, 68], [21, 69], [21, 77], [21, 80], [21, 81], [21, 87], [21, 91], [21, 93], [21, 98], [21, 104], [21, 106], [21, 109], [21, 125], [21, 127], [21, 128], [21, 132], [21, 133], [21, 134], [21, 141], [21, 142], [21, 145], [21, 149], [21, 162], [21, 168], [21, 170], [21, 174], [21, 175], [21, 178], [21, 179], [22, 26], [22, 27], [22, 30], [22, 36], [22, 39], [22, 40], [22, 49], [22, 53], [22, 76], [22, 77], [22, 84], [22, 85], [22, 91], [22, 125], [22, 128], [22, 130], [22, 131], [22, 134], [22, 138], [22, 141], [22, 142], [22, 146], [22, 149], [22, 151], [22, 152], [22, 153], [22, 167], [23, 26], [23, 30], [23, 32], [23, 34], [23, 46], [23, 51], [23, 52], [23, 53], [23, 55], [23, 72], [23, 81], [23, 97], [23, 98], [23, 99], [23, 100], [23, 105], [23, 114], [23, 117], [23, 123], [23, 131], [23, 133], [23, 134], [23, 136], [23, 137], [23, 144], [23, 146], [23, 147], [23, 151], [23, 152], [23, 160], [23, 161], [23, 165], [23, 167], [23, 173], [23, 175], [23, 177], [23, 178], [23, 179], [24, 27], [24, 32], [24, 34], [24, 35], [24, 37], [24, 41], [24, 44], [24, 45], [24, 47], [24, 53], [24, 63], [24, 70], [24, 71], [24, 79], [24, 82], [24, 88], [24, 94], [24, 98], [24, 101], [24, 102], [24, 107], [24, 109], [24, 112], [24, 115], [24, 135], [24, 137], [24, 139], [24, 147], [24, 148], [24, 153], [24, 157], [24, 159], [24, 161], [24, 167], [24, 170], [25, 27], [25, 63], [25, 80], [25, 86], [25, 93], [25, 94], [25, 100], [25, 108], [25, 113], [25, 115], [25, 117], [25, 124], [25, 126], [25, 137], [25, 147], [25, 154], [25, 157], [25, 161], [25, 162], [25, 168], [25, 170], [25, 172], [25, 177], [25, 179], [26, 28], [26, 35], [26, 38], [26, 52], [26, 57], [26, 58], [26, 60], [26, 63], [26, 64], [26, 65], [26, 68], [26, 72], [26, 80], [26, 87], [26, 90], [26, 93], [26, 100], [26, 103], [26, 113], [26, 116], [26, 119], [26, 125], [26, 127], [26, 129], [26, 132], [26, 136], [26, 137], [26, 138], [26, 139], [26, 143], [26, 144], [26, 153], [26, 154], [26, 156], [26, 165], [26, 166], [26, 168], [26, 169], [26, 175], [26, 176], [27, 28], [27, 35], [27, 37], [27, 42], [27, 44], [27, 50], [27, 54], [27, 55], [27, 63], [27, 68], [27, 70], [27, 73], [27, 80], [27, 83], [27, 85], [27, 91], [27, 92], [27, 94], [27, 95], [27, 104], [27, 111], [27, 112], [27, 125], [27, 130], [27, 132], [27, 135], [27, 137], [27, 139], [27, 148], [27, 150], [27, 155], [27, 163], [27, 172], [27, 173], [28, 29], [28, 32], [28, 36], [28, 37], [28, 41], [28, 42], [28, 50], [28, 56], [28, 58], [28, 61], [28, 64], [28, 69], [28, 70], [28, 77], [28, 80], [28, 88], [28, 89], [28, 95], [28, 96], [28, 100], [28, 103], [28, 105], [28, 106], [28, 114], [28, 115], [28, 128], [28, 130], [28, 137], [28, 140], [28, 149], [28, 150], [28, 154], [28, 155], [28, 159], [28, 171], [28, 179], [29, 42], [29, 47], [29, 64], [29, 70], [29, 73], [29, 92], [29, 95], [29, 110], [29, 124], [29, 125], [29, 128], [29, 129], [29, 134], [29, 135], [29, 136], [29, 139], [29, 146], [29, 156], [29, 160], [29, 164], [29, 172], [29, 173], [30, 31], [30, 40], [30, 42], [30, 43], [30, 44], [30, 49], [30, 52], [30, 58], [30, 72], [30, 75], [30, 78], [30, 83], [30, 84], [30, 90], [30, 92], [30, 100], [30, 102], [30, 108], [30, 110], [30, 113], [30, 116], [30, 120], [30, 130], [30, 138], [30, 140], [30, 143], [30, 144], [30, 149], [30, 150], [30, 155], [30, 160], [30, 161], [30, 165], [30, 169], [30, 171], [30, 176], [30, 177], [31, 42], [31, 44], [31, 46], [31, 49], [31, 56], [31, 57], [31, 65], [31, 66], [31, 70], [31, 73], [31, 82], [31, 87], [31, 93], [31, 102], [31, 104], [31, 110], [31, 115], [31, 119], [31, 135], [31, 137], [31, 138], [31, 139], [31, 140], [31, 145], [31, 146], [31, 147], [31, 149], [31, 154], [31, 155], [31, 157], [31, 158], [31, 160], [31, 164], [31, 166], [31, 168], [31, 169], [31, 173], [31, 178], [32, 34], [32, 38], [32, 46], [32, 50], [32, 63], [32, 67], [32, 77], [32, 78], [32, 87], [32, 93], [32, 95], [32, 101], [32, 105], [32, 107], [32, 108], [32, 113], [32, 114], [32, 117], [32, 120], [32, 122], [32, 129], [32, 130], [32, 132], [32, 139], [32, 148], [32, 150], [32, 152], [32, 164], [32, 169], [32, 171], [32, 172], [32, 173], [32, 177], [33, 35], [33, 39], [33, 50], [33, 71], [33, 78], [33, 79], [33, 82], [33, 86], [33, 89], [33, 94], [33, 99], [33, 106], [33, 122], [33, 130], [33, 131], [33, 139], [33, 145], [33, 146], [33, 155], [33, 160], [33, 162], [33, 174], [34, 38], [34, 41], [34, 42], [34, 44], [34, 46], [34, 48], [34, 57], [34, 66], [34, 71], [34, 76], [34, 79], [34, 81], [34, 84], [34, 92], [34, 93], [34, 95], [34, 100], [34, 101], [34, 102], [34, 111], [34, 116], [34, 136], [34, 146], [34, 153], [34, 154], [34, 157], [34, 159], [34, 162], [34, 164], [34, 165], [34, 171], [34, 178], [34, 179], [35, 37], [35, 40], [35, 41], [35, 43], [35, 51], [35, 57], [35, 64], [35, 67], [35, 68], [35, 72], [35, 75], [35, 79], [35, 81], [35, 82], [35, 84], [35, 89], [35, 93], [35, 96], [35, 106], [35, 107], [35, 108], [35, 109], [35, 118], [35, 122], [35, 123], [35, 128], [35, 131], [35, 136], [35, 141], [35, 143], [35, 155], [35, 174], [36, 40], [36, 47], [36, 66], [36, 75], [36, 77], [36, 78], [36, 84], [36, 87], [36, 92], [36, 98], [36, 99], [36, 100], [36, 103], [36, 104], [36, 105], [36, 110], [36, 111], [36, 114], [36, 134], [36, 149], [36, 151], [36, 159], [36, 161], [36, 168], [36, 177], [37, 39], [37, 40], [37, 48], [37, 53], [37, 58], [37, 63], [37, 66], [37, 75], [37, 82], [37, 84], [37, 86], [37, 87], [37, 88], [37, 97], [37, 106], [37, 108], [37, 111], [37, 126], [37, 127], [37, 132], [37, 134], [37, 135], [37, 137], [37, 139], [37, 141], [37, 154], [37, 157], [37, 159], [37, 160], [37, 161], [37, 167], [37, 168], [37, 171], [38, 39], [38, 45], [38, 47], [38, 49], [38, 56], [38, 65], [38, 70], [38, 81], [38, 84], [38, 90], [38, 91], [38, 94], [38, 96], [38, 99], [38, 103], [38, 105], [38, 107], [38, 110], [38, 114], [38, 117], [38, 119], [38, 121], [38, 126], [38, 130], [38, 139], [38, 148], [38, 151], [38, 154], [38, 174], [38, 178], [38, 179], [39, 43], [39, 49], [39, 66], [39, 82], [39, 87], [39, 88], [39, 96], [39, 106], [39, 113], [39, 116], [39, 118], [39, 123], [39, 124], [39, 130], [39, 133], [39, 137], [39, 143], [39, 146], [39, 149], [39, 157], [39, 163], [39, 164], [39, 165], [39, 171], [39, 175], [40, 52], [40, 67], [40, 72], [40, 73], [40, 77], [40, 81], [40, 88], [40, 90], [40, 97], [40, 104], [40, 108], [40, 117], [40, 121], [40, 122], [40, 124], [40, 136], [40, 144], [40, 145], [40, 150], [40, 153], [40, 154], [40, 160], [40, 162], [40, 170], [40, 175], [41, 46], [41, 48], [41, 52], [41, 54], [41, 58], [41, 63], [41, 64], [41, 65], [41, 76], [41, 79], [41, 84], [41, 85], [41, 94], [41, 100], [41, 102], [41, 116], [41, 118], [41, 123], [41, 138], [41, 148], [41, 149], [41, 157], [41, 161], [41, 165], [41, 167], [41, 168], [41, 171], [41, 176], [41, 178], [42, 53], [42, 60], [42, 67], [42, 77], [42, 78], [42, 81], [42, 86], [42, 92], [42, 96], [42, 118], [42, 120], [42, 121], [42, 123], [42, 126], [42, 129], [42, 134], [42, 136], [42, 138], [42, 145], [42, 151], [42, 152], [42, 153], [42, 163], [42, 166], [42, 168], [42, 176], [43, 50], [43, 63], [43, 65], [43, 66], [43, 68], [43, 70], [43, 72], [43, 74], [43, 76], [43, 79], [43, 83], [43, 89], [43, 96], [43, 105], [43, 107], [43, 109], [43, 110], [43, 116], [43, 118], [43, 121], [43, 129], [43, 131], [43, 134], [43, 136], [43, 137], [43, 142], [43, 145], [43, 148], [43, 161], [43, 162], [43, 165], [43, 171], [43, 173], [43, 174], [43, 178], [43, 179], [44, 46], [44, 50], [44, 53], [44, 54], [44, 56], [44, 59], [44, 60], [44, 66], [44, 70], [44, 80], [44, 83], [44, 89], [44, 92], [44, 103], [44, 108], [44, 112], [44, 117], [44, 118], [44, 120], [44, 122], [44, 125], [44, 129], [44, 134], [44, 144], [44, 145], [44, 146], [44, 149], [44, 150], [44, 166], [44, 167], [44, 174], [45, 47], [45, 50], [45, 52], [45, 53], [45, 55], [45, 60], [45, 61], [45, 67], [45, 76], [45, 79], [45, 81], [45, 89], [45, 91], [45, 94], [45, 100], [45, 114], [45, 115], [45, 117], [45, 121], [45, 123], [45, 132], [45, 145], [45, 146], [45, 150], [45, 152], [45, 153], [45, 156], [45, 157], [45, 163], [45, 165], [45, 173], [45, 175], [45, 177], [45, 179], [46, 52], [46, 54], [46, 64], [46, 72], [46, 77], [46, 91], [46, 92], [46, 93], [46, 99], [46, 108], [46, 113], [46, 116], [46, 118], [46, 122], [46, 127], [46, 135], [46, 151], [46, 152], [46, 159], [46, 163], [46, 171], [46, 176], [47, 61], [47, 63], [47, 64], [47, 65], [47, 72], [47, 86], [47, 92], [47, 94], [47, 95], [47, 98], [47, 102], [47, 103], [47, 107], [47, 112], [47, 114], [47, 115], [47, 116], [47, 120], [47, 121], [47, 125], [47, 128], [47, 134], [47, 135], [47, 136], [47, 141], [47, 145], [47, 146], [47, 151], [47, 153], [47, 158], [47, 161], [47, 170], [47, 171], [48, 51], [48, 55], [48, 56], [48, 57], [48, 58], [48, 64], [48, 65], [48, 73], [48, 80], [48, 84], [48, 88], [48, 89], [48, 92], [48, 94], [48, 99], [48, 100], [48, 114], [48, 116], [48, 136], [48, 137], [48, 140], [48, 161], [48, 175], [48, 176], [48, 178], [49, 59], [49, 60], [49, 64], [49, 65], [49, 82], [49, 89], [49, 91], [49, 92], [49, 95], [49, 99], [49, 102], [49, 104], [49, 105], [49, 106], [49, 109], [49, 114], [49, 124], [49, 125], [49, 128], [49, 137], [49, 154], [49, 159], [49, 163], [49, 170], [49, 171], [50, 51], [50, 66], [50, 74], [50, 86], [50, 93], [50, 102], [50, 104], [50, 114], [50, 121], [50, 122], [50, 131], [50, 134], [50, 140], [50, 141], [50, 147], [50, 150], [50, 153], [50, 160], [50, 161], [50, 163], [50, 169], [51, 63], [51, 73], [51, 76], [51, 81], [51, 85], [51, 97], [51, 105], [51, 109], [51, 115], [51, 131], [51, 142], [51, 146], [51, 154], [51, 160], [51, 162], [51, 168], [51, 172], [51, 175], [51, 176], [51, 179], [52, 58], [52, 64], [52, 65], [52, 72], [52, 84], [52, 86], [52, 97], [52, 99], [52, 106], [52, 109], [52, 111], [52, 112], [52, 118], [52, 129], [52, 137], [52, 145], [52, 147], [52, 149], [52, 150], [52, 156], [52, 163], [52, 169], [52, 171], [53, 56], [53, 57], [53, 61], [53, 62], [53, 66], [53, 81], [53, 82], [53, 92], [53, 98], [53, 110], [53, 111], [53, 118], [53, 121], [53, 123], [53, 126], [53, 139], [53, 151], [53, 153], [53, 155], [53, 157], [53, 158], [53, 165], [53, 166], [53, 178], [54, 66], [54, 71], [54, 72], [54, 73], [54, 84], [54, 106], [54, 132], [54, 134], [54, 136], [54, 139], [54, 149], [54, 151], [54, 152], [54, 153], [54, 164], [54, 165], [54, 169], [54, 173], [55, 58], [55, 60], [55, 71], [55, 78], [55, 92], [55, 102], [55, 103], [55, 106], [55, 108], [55, 113], [55, 121], [55, 126], [55, 133], [55, 134], [55, 140], [55, 146], [55, 148], [55, 150], [55, 153], [55, 158], [56, 57], [56, 58], [56, 69], [56, 72], [56, 74], [56, 81], [56, 84], [56, 91], [56, 105], [56, 108], [56, 115], [56, 116], [56, 117], [56, 120], [56, 126], [56, 131], [56, 141], [56, 146], [56, 147], [56, 162], [56, 166], [56, 167], [56, 170], [56, 171], [56, 173], [56, 177], [57, 61], [57, 62], [57, 67], [57, 81], [57, 92], [57, 93], [57, 96], [57, 98], [57, 101], [57, 106], [57, 109], [57, 114], [57, 122], [57, 125], [57, 136], [57, 143], [57, 150], [57, 168], [57, 171], [57, 176], [57, 179], [58, 61], [58, 64], [58, 73], [58, 77], [58, 78], [58, 79], [58, 83], [58, 91], [58, 94], [58, 99], [58, 107], [58, 116], [58, 119], [58, 123], [58, 134], [58, 139], [58, 141], [58, 143], [58, 145], [58, 148], [58, 149], [58, 152], [58, 153], [58, 154], [58, 157], [58, 161], [58, 163], [58, 174], [59, 62], [59, 74], [59, 75], [59, 77], [59, 80], [59, 82], [59, 90], [59, 93], [59, 107], [59, 114], [59, 120], [59, 142], [59, 148], [59, 149], [59, 151], [59, 154], [59, 160], [59, 166], [59, 167], [59, 175], [60, 61], [60, 64], [60, 80], [60, 89], [60, 94], [60, 95], [60, 101], [60, 103], [60, 109], [60, 112], [60, 117], [60, 120], [60, 123], [60, 127], [60, 130], [60, 131], [60, 133], [60, 134], [60, 138], [60, 147], [60, 148], [60, 150], [60, 152], [60, 154], [60, 156], [60, 165], [60, 166], [60, 167], [60, 171], [60, 175], [60, 178], [61, 62], [61, 67], [61, 68], [61, 69], [61, 71], [61, 84], [61, 85], [61, 92], [61, 94], [61, 105], [61, 109], [61, 112], [61, 128], [61, 143], [61, 154], [61, 162], [61, 166], [62, 64], [62, 73], [62, 79], [62, 86], [62, 95], [62, 97], [62, 104], [62, 107], [62, 117], [62, 120], [62, 129], [62, 142], [62, 145], [62, 146], [62, 150], [62, 152], [62, 157], [62, 166], [62, 167], [62, 169], [62, 172], [62, 173], [62, 177], [63, 68], [63, 75], [63, 76], [63, 92], [63, 96], [63, 106], [63, 109], [63, 111], [63, 112], [63, 117], [63, 129], [63, 131], [63, 142], [63, 143], [63, 145], [63, 155], [63, 170], [63, 172], [63, 174], [64, 66], [64, 78], [64, 81], [64, 82], [64, 95], [64, 96], [64, 99], [64, 100], [64, 105], [64, 108], [64, 116], [64, 117], [64, 118], [64, 125], [64, 128], [64, 135], [64, 137], [64, 138], [64, 141], [64, 142], [64, 172], [64, 173], [65, 68], [65, 69], [65, 73], [65, 76], [65, 79], [65, 105], [65, 106], [65, 111], [65, 114], [65, 118], [65, 127], [65, 131], [65, 133], [65, 135], [65, 136], [65, 137], [65, 138], [65, 139], [65, 140], [65, 142], [65, 143], [65, 144], [65, 161], [65, 163], [65, 168], [65, 169], [65, 171], [65, 172], [65, 173], [66, 71], [66, 72], [66, 73], [66, 75], [66, 76], [66, 79], [66, 83], [66, 85], [66, 87], [66, 89], [66, 99], [66, 102], [66, 114], [66, 119], [66, 121], [66, 123], [66, 125], [66, 127], [66, 131], [66, 137], [66, 142], [66, 143], [66, 145], [66, 149], [67, 70], [67, 97], [67, 103], [67, 122], [67, 123], [67, 125], [67, 129], [67, 130], [67, 131], [67, 143], [67, 151], [67, 164], [67, 171], [68, 71], [68, 73], [68, 76], [68, 80], [68, 81], [68, 83], [68, 108], [68, 111], [68, 121], [68, 125], [68, 127], [68, 128], [68, 135], [68, 137], [68, 139], [68, 142], [68, 161], [68, 162], [68, 163], [68, 165], [68, 169], [69, 70], [69, 71], [69, 75], [69, 88], [69, 99], [69, 101], [69, 124], [69, 126], [69, 129], [69, 132], [69, 140], [69, 148], [69, 149], [69, 153], [69, 154], [69, 155], [69, 161], [69, 164], [69, 167], [69, 168], [69, 171], [69, 173], [69, 174], [69, 175], [70, 78], [70, 86], [70, 87], [70, 88], [70, 97], [70, 100], [70, 109], [70, 111], [70, 112], [70, 114], [70, 116], [70, 117], [70, 121], [70, 123], [70, 124], [70, 125], [70, 129], [70, 132], [70, 133], [70, 135], [70, 138], [70, 140], [70, 141], [70, 143], [70, 147], [70, 148], [70, 149], [70, 150], [70, 153], [70, 168], [70, 170], [70, 172], [70, 174], [71, 78], [71, 93], [71, 94], [71, 97], [71, 98], [71, 105], [71, 106], [71, 107], [71, 108], [71, 115], [71, 125], [71, 133], [71, 136], [71, 139], [71, 142], [71, 144], [71, 147], [71, 157], [71, 160], [71, 161], [71, 164], [71, 166], [71, 170], [71, 171], [71, 172], [72, 76], [72, 78], [72, 93], [72, 99], [72, 109], [72, 119], [72, 120], [72, 121], [72, 130], [72, 131], [72, 133], [72, 146], [72, 147], [72, 154], [72, 156], [72, 161], [72, 166], [72, 176], [73, 76], [73, 78], [73, 81], [73, 82], [73, 89], [73, 91], [73, 98], [73, 102], [73, 106], [73, 114], [73, 121], [73, 123], [73, 133], [73, 136], [73, 147], [73, 153], [73, 154], [73, 156], [73, 167], [73, 169], [73, 176], [74, 79], [74, 80], [74, 94], [74, 98], [74, 102], [74, 103], [74, 105], [74, 107], [74, 112], [74, 130], [74, 131], [74, 142], [74, 147], [74, 149], [74, 152], [74, 154], [74, 169], [74, 170], [74, 173], [74, 175], [74, 176], [75, 76], [75, 77], [75, 79], [75, 82], [75, 83], [75, 84], [75, 90], [75, 92], [75, 94], [75, 95], [75, 107], [75, 114], [75, 117], [75, 118], [75, 125], [75, 126], [75, 130], [75, 131], [75, 133], [75, 135], [75, 138], [75, 140], [75, 142], [75, 148], [75, 151], [75, 161], [75, 162], [76, 88], [76, 89], [76, 108], [76, 111], [76, 114], [76, 116], [76, 117], [76, 137], [76, 140], [76, 147], [76, 151], [76, 158], [76, 160], [76, 166], [76, 170], [76, 173], [77, 78], [77, 80], [77, 81], [77, 82], [77, 89], [77, 90], [77, 91], [77, 97], [77, 105], [77, 106], [77, 110], [77, 120], [77, 126], [77, 151], [77, 152], [77, 153], [77, 154], [77, 158], [77, 159], [77, 163], [77, 165], [77, 174], [77, 175], [78, 79], [78, 89], [78, 90], [78, 98], [78, 103], [78, 119], [78, 121], [78, 122], [78, 130], [78, 131], [78, 141], [78, 152], [78, 154], [78, 162], [78, 167], [78, 176], [78, 179], [79, 91], [79, 92], [79, 95], [79, 98], [79, 106], [79, 108], [79, 129], [79, 131], [79, 132], [79, 134], [79, 138], [79, 140], [79, 142], [79, 143], [79, 145], [79, 158], [79, 165], [79, 174], [80, 81], [80, 82], [80, 84], [80, 86], [80, 88], [80, 95], [80, 96], [80, 102], [80, 108], [80, 112], [80, 119], [80, 121], [80, 122], [80, 125], [80, 139], [80, 140], [80, 144], [80, 146], [80, 147], [80, 153], [80, 155], [80, 174], [81, 82], [81, 86], [81, 88], [81, 94], [81, 97], [81, 98], [81, 105], [81, 106], [81, 108], [81, 110], [81, 113], [81, 120], [81, 129], [81, 134], [81, 135], [81, 136], [81, 142], [81, 143], [81, 145], [81, 159], [81, 161], [81, 169], [81, 174], [82, 85], [82, 88], [82, 107], [82, 112], [82, 122], [82, 127], [82, 131], [82, 140], [82, 141], [82, 142], [82, 144], [82, 145], [82, 146], [82, 147], [82, 154], [82, 155], [82, 165], [82, 166], [82, 168], [83, 98], [83, 101], [83, 106], [83, 110], [83, 115], [83, 116], [83, 117], [83, 118], [83, 140], [83, 152], [83, 154], [83, 156], [83, 158], [83, 159], [83, 167], [83, 170], [83, 171], [83, 177], [83, 178], [84, 87], [84, 91], [84, 92], [84, 93], [84, 95], [84, 97], [84, 100], [84, 101], [84, 113], [84, 114], [84, 117], [84, 119], [84, 130], [84, 144], [84, 147], [84, 148], [84, 149], [84, 150], [84, 151], [84, 152], [84, 153], [84, 157], [84, 158], [84, 160], [84, 169], [84, 171], [84, 172], [84, 173], [84, 174], [85, 90], [85, 92], [85, 98], [85, 101], [85, 114], [85, 116], [85, 122], [85, 128], [85, 140], [85, 146], [85, 153], [85, 162], [85, 165], [85, 169], [85, 170], [85, 171], [85, 173], [86, 87], [86, 91], [86, 100], [86, 101], [86, 103], [86, 105], [86, 106], [86, 107], [86, 115], [86, 118], [86, 120], [86, 125], [86, 126], [86, 127], [86, 128], [86, 139], [86, 140], [86, 142], [86, 146], [86, 147], [86, 154], [86, 157], [86, 163], [86, 169], [86, 174], [86, 175], [86, 179], [87, 88], [87, 89], [87, 90], [87, 95], [87, 102], [87, 115], [87, 123], [87, 124], [87, 127], [87, 128], [87, 131], [87, 136], [87, 141], [87, 162], [87, 164], [87, 170], [87, 173], [88, 91], [88, 94], [88, 101], [88, 103], [88, 104], [88, 105], [88, 114], [88, 117], [88, 122], [88, 125], [88, 126], [88, 134], [88, 139], [88, 148], [88, 151], [88, 153], [88, 154], [88, 167], [88, 179], [89, 99], [89, 101], [89, 102], [89, 103], [89, 104], [89, 109], [89, 113], [89, 116], [89, 118], [89, 122], [89, 126], [89, 138], [89, 143], [89, 145], [89, 150], [89, 161], [89, 163], [89, 170], [90, 96], [90, 98], [90, 100], [90, 101], [90, 107], [90, 108], [90, 113], [90, 114], [90, 117], [90, 120], [90, 123], [90, 129], [90, 130], [90, 131], [90, 150], [90, 151], [90, 152], [90, 154], [90, 162], [90, 167], [90, 172], [90, 175], [91, 102], [91, 119], [91, 122], [91, 123], [91, 125], [91, 126], [91, 133], [91, 141], [91, 145], [91, 149], [91, 150], [91, 154], [91, 159], [91, 168], [91, 175], [92, 97], [92, 102], [92, 107], [92, 110], [92, 113], [92, 121], [92, 124], [92, 127], [92, 132], [92, 133], [92, 134], [92, 135], [92, 142], [92, 145], [92, 150], [92, 152], [92, 153], [92, 155], [92, 156], [92, 159], [92, 160], [92, 163], [92, 169], [92, 179], [93, 100], [93, 111], [93, 114], [93, 119], [93, 120], [93, 125], [93, 147], [93, 163], [93, 170], [93, 174], [94, 95], [94, 100], [94, 103], [94, 105], [94, 110], [94, 114], [94, 116], [94, 117], [94, 121], [94, 130], [94, 131], [94, 137], [94, 141], [94, 143], [94, 146], [94, 149], [94, 154], [94, 170], [94, 171], [95, 97], [95, 104], [95, 107], [95, 108], [95, 112], [95, 115], [95, 116], [95, 118], [95, 119], [95, 121], [95, 127], [95, 130], [95, 133], [95, 135], [95, 137], [95, 140], [95, 149], [95, 154], [95, 161], [95, 169], [95, 171], [95, 172], [95, 175], [95, 176], [96, 102], [96, 103], [96, 105], [96, 113], [96, 118], [96, 124], [96, 133], [96, 141], [96, 142], [96, 149], [96, 156], [96, 157], [96, 160], [96, 165], [96, 176], [97, 98], [97, 107], [97, 108], [97, 111], [97, 119], [97, 123], [97, 125], [97, 127], [97, 129], [97, 131], [97, 139], [97, 142], [97, 143], [97, 145], [97, 168], [97, 169], [97, 172], [98, 101], [98, 102], [98, 104], [98, 106], [98, 107], [98, 114], [98, 115], [98, 118], [98, 122], [98, 123], [98, 129], [98, 133], [98, 135], [98, 136], [98, 137], [98, 138], [98, 141], [98, 143], [98, 146], [98, 152], [98, 169], [98, 170], [98, 174], [98, 175], [98, 179], [99, 107], [99, 110], [99, 116], [99, 119], [99, 120], [99, 124], [99, 131], [99, 133], [99, 138], [99, 143], [99, 154], [99, 156], [99, 158], [99, 159], [99, 167], [99, 169], [100, 102], [100, 107], [100, 108], [100, 120], [100, 129], [100, 131], [100, 137], [100, 141], [100, 143], [100, 149], [100, 157], [100, 163], [100, 167], [100, 173], [100, 174], [100, 177], [101, 102], [101, 105], [101, 106], [101, 108], [101, 130], [101, 133], [101, 134], [101, 135], [101, 136], [101, 138], [101, 139], [101, 146], [101, 156], [101, 159], [101, 164], [101, 165], [101, 168], [101, 170], [101, 172], [101, 173], [101, 176], [102, 103], [102, 106], [102, 115], [102, 128], [102, 139], [102, 146], [102, 147], [102, 152], [102, 154], [102, 155], [102, 157], [102, 159], [102, 162], [102, 163], [102, 169], [103, 106], [103, 115], [103, 118], [103, 120], [103, 121], [103, 139], [103, 141], [103, 164], [103, 177], [104, 110], [104, 115], [104, 119], [104, 126], [104, 133], [104, 137], [104, 140], [104, 143], [104, 148], [104, 152], [104, 156], [104, 169], [104, 171], [104, 173], [104, 174], [104, 179], [105, 120], [105, 129], [105, 131], [105, 135], [105, 137], [105, 148], [105, 149], [105, 150], [105, 152], [105, 155], [105, 160], [105, 167], [105, 174], [106, 112], [106, 119], [106, 123], [106, 135], [106, 137], [106, 140], [106, 143], [106, 145], [106, 147], [106, 152], [106, 162], [106, 163], [106, 165], [106, 173], [106, 175], [107, 108], [107, 111], [107, 112], [107, 113], [107, 115], [107, 117], [107, 118], [107, 127], [107, 128], [107, 139], [107, 140], [107, 142], [107, 146], [107, 147], [107, 152], [107, 155], [107, 156], [107, 163], [107, 165], [107, 169], [107, 170], [107, 175], [108, 113], [108, 119], [108, 121], [108, 123], [108, 127], [108, 129], [108, 138], [108, 141], [108, 142], [108, 147], [108, 154], [108, 160], [108, 162], [108, 167], [108, 178], [108, 179], [109, 111], [109, 113], [109, 116], [109, 118], [109, 120], [109, 122], [109, 123], [109, 127], [109, 129], [109, 136], [109, 138], [109, 141], [109, 147], [109, 163], [109, 168], [109, 171], [110, 111], [110, 112], [110, 113], [110, 119], [110, 120], [110, 137], [110, 139], [110, 141], [110, 143], [110, 145], [110, 149], [110, 154], [110, 156], [110, 162], [110, 168], [110, 177], [110, 179], [111, 135], [111, 137], [111, 140], [111, 165], [111, 170], [111, 171], [111, 172], [111, 176], [112, 114], [112, 116], [112, 124], [112, 131], [112, 136], [112, 142], [112, 145], [112, 148], [112, 150], [112, 159], [112, 161], [112, 167], [112, 169], [112, 177], [113, 119], [113, 123], [113, 126], [113, 128], [113, 133], [113, 137], [113, 142], [113, 143], [113, 148], [113, 150], [113, 170], [113, 176], [113, 178], [113, 179], [114, 119], [114, 122], [114, 127], [114, 130], [114, 131], [114, 142], [114, 146], [114, 147], [114, 148], [114, 152], [114, 165], [114, 174], [115, 125], [115, 126], [115, 143], [115, 152], [115, 153], [115, 160], [115, 163], [115, 166], [115, 168], [115, 169], [115, 171], [115, 172], [115, 173], [115, 174], [115, 175], [115, 179], [116, 119], [116, 122], [116, 123], [116, 124], [116, 125], [116, 126], [116, 129], [116, 133], [116, 134], [116, 137], [116, 142], [116, 145], [116, 150], [116, 153], [116, 154], [116, 157], [116, 165], [116, 172], [117, 118], [117, 119], [117, 121], [117, 122], [117, 140], [117, 143], [117, 146], [117, 147], [117, 154], [117, 156], [117, 159], [117, 170], [117, 173], [117, 176], [118, 125], [118, 156], [118, 158], [118, 166], [118, 167], [118, 174], [118, 175], [119, 120], [119, 125], [119, 130], [119, 140], [119, 147], [119, 150], [119, 157], [119, 159], [119, 164], [119, 165], [119, 170], [119, 172], [119, 175], [119, 176], [119, 177], [120, 125], [120, 127], [120, 132], [120, 141], [120, 151], [120, 157], [120, 160], [120, 161], [120, 164], [120, 166], [120, 170], [120, 172], [120, 175], [120, 178], [121, 122], [121, 142], [121, 147], [121, 148], [121, 154], [121, 157], [121, 160], [121, 161], [121, 164], [121, 168], [121, 178], [121, 179], [122, 133], [122, 138], [122, 145], [122, 152], [122, 160], [122, 163], [122, 170], [122, 175], [122, 178], [123, 124], [123, 125], [123, 129], [123, 130], [123, 133], [123, 136], [123, 137], [123, 138], [123, 139], [123, 147], [123, 150], [123, 152], [123, 154], [123, 156], [123, 160], [123, 161], [123, 166], [123, 170], [123, 171], [123, 172], [123, 174], [124, 127], [124, 131], [124, 133], [124, 136], [124, 140], [124, 161], [124, 162], [124, 169], [124, 170], [124, 172], [124, 179], [125, 133], [125, 145], [125, 154], [125, 160], [125, 174], [125, 175], [125, 176], [126, 136], [126, 143], [126, 146], [126, 150], [126, 161], [126, 163], [126, 165], [126, 167], [127, 130], [127, 131], [127, 139], [127, 145], [127, 147], [127, 149], [127, 152], [127, 157], [127, 162], [127, 165], [127, 168], [128, 129], [128, 132], [128, 134], [128, 136], [128, 143], [128, 146], [128, 149], [128, 160], [128, 162], [128, 168], [128, 176], [128, 178], [129, 134], [129, 135], [129, 137], [129, 142], [129, 143], [129, 144], [129, 149], [129, 152], [129, 155], [129, 159], [129, 169], [129, 170], [129, 173], [129, 174], [129, 176], [129, 178], [130, 132], [130, 136], [130, 138], [130, 144], [130, 149], [130, 151], [130, 159], [130, 166], [130, 168], [130, 172], [130, 177], [131, 132], [131, 135], [131, 138], [131, 152], [131, 153], [131, 157], [131, 169], [131, 176], [132, 145], [132, 146], [132, 147], [132, 148], [132, 154], [132, 160], [132, 165], [132, 169], [132, 171], [133, 138], [133, 143], [133, 147], [133, 152], [133, 153], [133, 154], [133, 160], [133, 161], [133, 167], [133, 172], [133, 173], [133, 174], [133, 178], [134, 136], [134, 138], [134, 140], [134, 146], [134, 147], [134, 149], [134, 160], [134, 165], [134, 166], [134, 169], [134, 170], [134, 171], [134, 173], [134, 176], [135, 141], [135, 142], [135, 144], [135, 146], [135, 161], [135, 163], [135, 165], [135, 167], [135, 172], [135, 175], [136, 138], [136, 139], [136, 149], [136, 159], [136, 161], [136, 178], [137, 139], [137, 142], [137, 155], [137, 162], [137, 165], [137, 170], [137, 171], [138, 139], [138, 141], [138, 147], [138, 148], [138, 151], [138, 179], [139, 151], [139, 156], [139, 157], [139, 158], [139, 165], [139, 169], [139, 174], [139, 177], [140, 142], [140, 143], [140, 144], [140, 150], [140, 153], [140, 168], [140, 176], [141, 144], [141, 146], [141, 147], [141, 148], [141, 156], [141, 158], [141, 171], [142, 159], [142, 168], [142, 173], [143, 146], [143, 147], [143, 150], [143, 152], [143, 153], [143, 162], [143, 168], [143, 176], [144, 149], [144, 150], [144, 165], [144, 170], [144, 176], [145, 158], [145, 161], [145, 163], [145, 179], [146, 150], [146, 163], [146, 166], [146, 167], [146, 170], [146, 174], [146, 176], [147, 153], [147, 155], [147, 156], [147, 157], [147, 159], [147, 161], [147, 165], [147, 170], [147, 172], [147, 177], [147, 179], [148, 163], [148, 164], [148, 167], [148, 171], [148, 175], [148, 178], [149, 154], [149, 156], [149, 162], [149, 179], [150, 154], [150, 155], [150, 158], [150, 159], [150, 171], [150, 173], [150, 174], [150, 178], [151, 156], [151, 160], [151, 161], [151, 162], [151, 164], [151, 167], [151, 171], [151, 172], [152, 162], [152, 169], [153, 155], [153, 168], [153, 171], [153, 172], [153, 174], [154, 158], [154, 163], [154, 168], [154, 170], [154, 171], [154, 172], [154, 175], [154, 177], [155, 156], [155, 159], [155, 166], [156, 157], [156, 158], [156, 162], [156, 177], [157, 168], [157, 173], [158, 160], [158, 167], [158, 168], [158, 172], [158, 176], [159, 169], [159, 173], [160, 161], [160, 167], [160, 168], [160, 177], [161, 162], [161, 167], [161, 174], [161, 179], [162, 170], [162, 176], [162, 178], [163, 167], [163, 171], [163, 172], [163, 176], [163, 178], [163, 179], [165, 168], [165, 178], [166, 168], [166, 170], [166, 171], [167, 169], [167, 174], [168, 169], [168, 172], [169, 173], [169, 176], [169, 177], [170, 171], [170, 172], [170, 175], [170, 176], [170, 177], [171, 172], [171, 176], [171, 178], [172, 173], [172, 174], [172, 179], [173, 174], [173, 175], [174, 177], [175, 179], [176, 178], [176, 179], [177, 179], [178, 179]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l5-s9/solution/solve.sh b/tasks/construct-nppc-dominating-set-l5-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ad07c98a0948ecd6b0ef5f9579e6d0ac16547406 --- /dev/null +++ b/tasks/construct-nppc-dominating-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' +{"dominating_set": [4, 26, 42, 43, 45, 84, 92, 106, 122, 128, 131, 141, 154, 167, 170]} +RLMATH_EOF diff --git a/tasks/construct-nppc-dominating-set-l5-s9/tests/check.py b/tasks/construct-nppc-dominating-set-l5-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0677a7bcbccb02297d022ffa4b5dd15da6371bff --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l5-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-l5-s9/tests/instance.json b/tasks/construct-nppc-dominating-set-l5-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4b8a5c9e29e87aaa6a261b29e9860898c3ac96d0 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l5-s9/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 180, "k": 15, "edges": [[0, 3], [0, 13], [0, 15], [0, 17], [0, 18], [0, 19], [0, 26], [0, 38], [0, 39], [0, 53], [0, 65], [0, 68], [0, 71], [0, 78], [0, 95], [0, 97], [0, 100], [0, 101], [0, 106], [0, 116], [0, 123], [0, 127], [0, 128], [0, 131], [0, 133], [0, 135], [0, 143], [0, 147], [0, 148], [0, 153], [0, 158], [0, 159], [0, 160], [0, 161], [0, 168], [0, 178], [1, 2], [1, 10], [1, 12], [1, 15], [1, 21], [1, 22], [1, 24], [1, 25], [1, 27], [1, 33], [1, 35], [1, 38], [1, 40], [1, 44], [1, 45], [1, 49], [1, 57], [1, 64], [1, 65], [1, 82], [1, 86], [1, 90], [1, 91], [1, 94], [1, 96], [1, 104], [1, 116], [1, 120], [1, 125], [1, 127], [1, 131], [1, 143], [1, 145], [1, 152], [1, 154], [1, 166], [1, 167], [1, 170], [1, 173], [1, 174], [1, 175], [1, 176], [1, 179], [2, 6], [2, 9], [2, 15], [2, 22], [2, 23], [2, 34], [2, 36], [2, 39], [2, 42], [2, 45], [2, 61], [2, 68], [2, 69], [2, 71], [2, 74], [2, 76], [2, 77], [2, 90], [2, 103], [2, 106], [2, 107], [2, 110], [2, 123], [2, 130], [2, 134], [2, 143], [2, 147], [2, 148], [2, 164], [2, 165], [2, 166], [2, 168], [2, 173], [2, 177], [3, 4], [3, 7], [3, 10], [3, 17], [3, 19], [3, 22], [3, 29], [3, 32], [3, 38], [3, 48], [3, 56], [3, 70], [3, 76], [3, 83], [3, 86], [3, 87], [3, 89], [3, 92], [3, 94], [3, 102], [3, 103], [3, 114], [3, 115], [3, 123], [3, 130], [3, 133], [3, 136], [3, 141], [3, 142], [3, 143], [3, 148], [3, 149], [3, 152], [3, 153], [3, 156], [3, 159], [3, 161], [3, 164], [3, 165], [3, 171], [3, 173], [4, 7], [4, 10], [4, 11], [4, 14], [4, 17], [4, 21], [4, 23], [4, 30], [4, 35], [4, 36], [4, 39], [4, 53], [4, 65], [4, 72], [4, 75], [4, 76], [4, 81], [4, 102], [4, 104], [4, 109], [4, 111], [4, 115], [4, 116], [4, 120], [4, 128], [4, 130], [4, 131], [4, 134], [4, 144], [4, 146], [4, 149], [4, 153], [4, 154], [4, 156], [4, 159], [4, 161], [4, 162], [4, 164], [4, 166], [4, 168], [4, 169], [4, 178], [5, 8], [5, 12], [5, 17], [5, 27], [5, 32], [5, 33], [5, 40], [5, 41], [5, 43], [5, 44], [5, 49], [5, 57], [5, 61], [5, 62], [5, 65], [5, 79], [5, 86], [5, 89], [5, 96], [5, 97], [5, 103], [5, 111], [5, 118], [5, 122], [5, 127], [5, 130], [5, 131], [5, 137], [5, 138], [5, 140], [5, 142], [5, 144], [5, 149], [5, 165], [5, 175], [6, 8], [6, 12], [6, 27], [6, 29], [6, 38], [6, 40], [6, 42], [6, 43], [6, 44], [6, 48], [6, 50], [6, 55], [6, 62], [6, 70], [6, 72], [6, 103], [6, 104], [6, 105], [6, 107], [6, 115], [6, 119], [6, 122], [6, 123], [6, 128], [6, 136], [6, 137], [6, 147], [6, 153], [6, 154], [6, 165], [6, 175], [6, 179], [7, 9], [7, 16], [7, 35], [7, 36], [7, 38], [7, 40], [7, 43], [7, 45], [7, 58], [7, 63], [7, 65], [7, 66], [7, 68], [7, 69], [7, 71], [7, 75], [7, 76], [7, 84], [7, 89], [7, 96], [7, 102], [7, 106], [7, 114], [7, 116], [7, 117], [7, 118], [7, 126], [7, 146], [7, 152], [7, 156], [7, 157], [7, 161], [7, 165], [7, 166], [7, 169], [7, 172], [7, 175], [7, 177], [8, 11], [8, 12], [8, 13], [8, 15], [8, 16], [8, 26], [8, 28], [8, 30], [8, 38], [8, 52], [8, 53], [8, 54], [8, 55], [8, 71], [8, 73], [8, 76], [8, 77], [8, 78], [8, 79], [8, 81], [8, 84], [8, 85], [8, 93], [8, 101], [8, 104], [8, 108], [8, 110], [8, 115], [8, 125], [8, 137], [8, 139], [8, 142], [8, 149], [8, 154], [8, 158], [8, 162], [8, 168], [8, 169], [8, 175], [9, 10], [9, 13], [9, 19], [9, 21], [9, 23], [9, 28], [9, 30], [9, 36], [9, 48], [9, 50], [9, 53], [9, 55], [9, 56], [9, 64], [9, 65], [9, 70], [9, 77], [9, 82], [9, 84], [9, 88], [9, 95], [9, 97], [9, 100], [9, 114], [9, 116], [9, 118], [9, 119], [9, 123], [9, 141], [9, 147], [9, 153], [9, 155], [9, 159], [9, 162], [9, 172], [9, 174], [10, 19], [10, 22], [10, 34], [10, 48], [10, 52], [10, 53], [10, 59], [10, 61], [10, 69], [10, 74], [10, 81], [10, 84], [10, 86], [10, 92], [10, 95], [10, 101], [10, 103], [10, 105], [10, 107], [10, 108], [10, 115], [10, 117], [10, 142], [10, 153], [10, 156], [10, 160], [10, 162], [10, 170], [10, 173], [10, 179], [11, 23], [11, 30], [11, 36], [11, 37], [11, 41], [11, 46], [11, 49], [11, 51], [11, 52], [11, 54], [11, 55], [11, 59], [11, 68], [11, 70], [11, 76], [11, 79], [11, 80], [11, 83], [11, 89], [11, 91], [11, 92], [11, 95], [11, 97], [11, 100], [11, 101], [11, 103], [11, 105], [11, 107], [11, 116], [11, 122], [11, 123], [11, 134], [11, 135], [11, 136], [11, 152], [11, 156], [11, 159], [11, 165], [11, 171], [11, 173], [11, 176], [12, 14], [12, 15], [12, 17], [12, 19], [12, 35], [12, 38], [12, 47], [12, 52], [12, 53], [12, 56], [12, 62], [12, 63], [12, 69], [12, 71], [12, 76], [12, 80], [12, 81], [12, 83], [12, 84], [12, 90], [12, 92], [12, 99], [12, 103], [12, 104], [12, 109], [12, 111], [12, 114], [12, 119], [12, 122], [12, 126], [12, 132], [12, 133], [12, 142], [12, 148], [12, 165], [12, 170], [12, 171], [12, 174], [12, 175], [13, 17], [13, 26], [13, 27], [13, 39], [13, 41], [13, 43], [13, 50], [13, 55], [13, 58], [13, 59], [13, 65], [13, 66], [13, 76], [13, 80], [13, 84], [13, 89], [13, 90], [13, 95], [13, 98], [13, 103], [13, 110], [13, 116], [13, 117], [13, 121], [13, 130], [13, 136], [13, 145], [13, 153], [13, 158], [13, 162], [13, 173], [13, 174], [13, 179], [14, 18], [14, 23], [14, 27], [14, 36], [14, 42], [14, 45], [14, 59], [14, 84], [14, 90], [14, 110], [14, 117], [14, 119], [14, 120], [14, 129], [14, 142], [14, 155], [14, 160], [14, 162], [14, 165], [14, 167], [14, 170], [14, 175], [14, 179], [15, 22], [15, 61], [15, 62], [15, 65], [15, 74], [15, 78], [15, 93], [15, 94], [15, 100], [15, 105], [15, 114], [15, 124], [15, 132], [15, 133], [15, 134], [15, 137], [15, 143], [15, 151], [15, 154], [15, 155], [15, 157], [15, 158], [15, 160], [15, 171], [16, 20], [16, 40], [16, 41], [16, 43], [16, 52], [16, 60], [16, 69], [16, 77], [16, 83], [16, 86], [16, 89], [16, 90], [16, 91], [16, 96], [16, 97], [16, 100], [16, 103], [16, 107], [16, 112], [16, 117], [16, 122], [16, 124], [16, 129], [16, 141], [16, 151], [16, 158], [16, 160], [16, 164], [16, 168], [16, 169], [16, 174], [16, 177], [17, 18], [17, 24], [17, 26], [17, 32], [17, 33], [17, 34], [17, 41], [17, 42], [17, 53], [17, 54], [17, 55], [17, 56], [17, 61], [17, 67], [17, 75], [17, 77], [17, 82], [17, 86], [17, 87], [17, 94], [17, 103], [17, 107], [17, 108], [17, 135], [17, 136], [17, 142], [17, 144], [17, 151], [17, 153], [17, 156], [17, 168], [17, 172], [18, 27], [18, 30], [18, 36], [18, 48], [18, 67], [18, 76], [18, 81], [18, 87], [18, 90], [18, 100], [18, 102], [18, 108], [18, 111], [18, 117], [18, 120], [18, 127], [18, 134], [18, 148], [18, 150], [18, 152], [18, 156], [18, 164], [18, 167], [18, 170], [19, 25], [19, 36], [19, 37], [19, 40], [19, 51], [19, 58], [19, 61], [19, 63], [19, 67], [19, 73], [19, 75], [19, 82], [19, 83], [19, 86], [19, 95], [19, 97], [19, 99], [19, 100], [19, 111], [19, 117], [19, 123], [19, 125], [19, 128], [19, 129], [19, 135], [19, 153], [19, 160], [19, 166], [19, 167], [19, 169], [19, 175], [19, 179], [20, 25], [20, 28], [20, 30], [20, 34], [20, 37], [20, 43], [20, 47], [20, 48], [20, 52], [20, 55], [20, 66], [20, 69], [20, 72], [20, 93], [20, 100], [20, 104], [20, 105], [20, 107], [20, 110], [20, 111], [20, 113], [20, 117], [20, 130], [20, 132], [20, 135], [20, 138], [20, 150], [20, 157], [20, 158], [20, 163], [20, 174], [21, 32], [21, 33], [21, 34], [21, 37], [21, 45], [21, 46], [21, 55], [21, 64], [21, 66], [21, 68], [21, 69], [21, 77], [21, 80], [21, 81], [21, 87], [21, 91], [21, 93], [21, 98], [21, 104], [21, 106], [21, 109], [21, 125], [21, 127], [21, 128], [21, 132], [21, 133], [21, 134], [21, 141], [21, 142], [21, 145], [21, 149], [21, 162], [21, 168], [21, 170], [21, 174], [21, 175], [21, 178], [21, 179], [22, 26], [22, 27], [22, 30], [22, 36], [22, 39], [22, 40], [22, 49], [22, 53], [22, 76], [22, 77], [22, 84], [22, 85], [22, 91], [22, 125], [22, 128], [22, 130], [22, 131], [22, 134], [22, 138], [22, 141], [22, 142], [22, 146], [22, 149], [22, 151], [22, 152], [22, 153], [22, 167], [23, 26], [23, 30], [23, 32], [23, 34], [23, 46], [23, 51], [23, 52], [23, 53], [23, 55], [23, 72], [23, 81], [23, 97], [23, 98], [23, 99], [23, 100], [23, 105], [23, 114], [23, 117], [23, 123], [23, 131], [23, 133], [23, 134], [23, 136], [23, 137], [23, 144], [23, 146], [23, 147], [23, 151], [23, 152], [23, 160], [23, 161], [23, 165], [23, 167], [23, 173], [23, 175], [23, 177], [23, 178], [23, 179], [24, 27], [24, 32], [24, 34], [24, 35], [24, 37], [24, 41], [24, 44], [24, 45], [24, 47], [24, 53], [24, 63], [24, 70], [24, 71], [24, 79], [24, 82], [24, 88], [24, 94], [24, 98], [24, 101], [24, 102], [24, 107], [24, 109], [24, 112], [24, 115], [24, 135], [24, 137], [24, 139], [24, 147], [24, 148], [24, 153], [24, 157], [24, 159], [24, 161], [24, 167], [24, 170], [25, 27], [25, 63], [25, 80], [25, 86], [25, 93], [25, 94], [25, 100], [25, 108], [25, 113], [25, 115], [25, 117], [25, 124], [25, 126], [25, 137], [25, 147], [25, 154], [25, 157], [25, 161], [25, 162], [25, 168], [25, 170], [25, 172], [25, 177], [25, 179], [26, 28], [26, 35], [26, 38], [26, 52], [26, 57], [26, 58], [26, 60], [26, 63], [26, 64], [26, 65], [26, 68], [26, 72], [26, 80], [26, 87], [26, 90], [26, 93], [26, 100], [26, 103], [26, 113], [26, 116], [26, 119], [26, 125], [26, 127], [26, 129], [26, 132], [26, 136], [26, 137], [26, 138], [26, 139], [26, 143], [26, 144], [26, 153], [26, 154], [26, 156], [26, 165], [26, 166], [26, 168], [26, 169], [26, 175], [26, 176], [27, 28], [27, 35], [27, 37], [27, 42], [27, 44], [27, 50], [27, 54], [27, 55], [27, 63], [27, 68], [27, 70], [27, 73], [27, 80], [27, 83], [27, 85], [27, 91], [27, 92], [27, 94], [27, 95], [27, 104], [27, 111], [27, 112], [27, 125], [27, 130], [27, 132], [27, 135], [27, 137], [27, 139], [27, 148], [27, 150], [27, 155], [27, 163], [27, 172], [27, 173], [28, 29], [28, 32], [28, 36], [28, 37], [28, 41], [28, 42], [28, 50], [28, 56], [28, 58], [28, 61], [28, 64], [28, 69], [28, 70], [28, 77], [28, 80], [28, 88], [28, 89], [28, 95], [28, 96], [28, 100], [28, 103], [28, 105], [28, 106], [28, 114], [28, 115], [28, 128], [28, 130], [28, 137], [28, 140], [28, 149], [28, 150], [28, 154], [28, 155], [28, 159], [28, 171], [28, 179], [29, 42], [29, 47], [29, 64], [29, 70], [29, 73], [29, 92], [29, 95], [29, 110], [29, 124], [29, 125], [29, 128], [29, 129], [29, 134], [29, 135], [29, 136], [29, 139], [29, 146], [29, 156], [29, 160], [29, 164], [29, 172], [29, 173], [30, 31], [30, 40], [30, 42], [30, 43], [30, 44], [30, 49], [30, 52], [30, 58], [30, 72], [30, 75], [30, 78], [30, 83], [30, 84], [30, 90], [30, 92], [30, 100], [30, 102], [30, 108], [30, 110], [30, 113], [30, 116], [30, 120], [30, 130], [30, 138], [30, 140], [30, 143], [30, 144], [30, 149], [30, 150], [30, 155], [30, 160], [30, 161], [30, 165], [30, 169], [30, 171], [30, 176], [30, 177], [31, 42], [31, 44], [31, 46], [31, 49], [31, 56], [31, 57], [31, 65], [31, 66], [31, 70], [31, 73], [31, 82], [31, 87], [31, 93], [31, 102], [31, 104], [31, 110], [31, 115], [31, 119], [31, 135], [31, 137], [31, 138], [31, 139], [31, 140], [31, 145], [31, 146], [31, 147], [31, 149], [31, 154], [31, 155], [31, 157], [31, 158], [31, 160], [31, 164], [31, 166], [31, 168], [31, 169], [31, 173], [31, 178], [32, 34], [32, 38], [32, 46], [32, 50], [32, 63], [32, 67], [32, 77], [32, 78], [32, 87], [32, 93], [32, 95], [32, 101], [32, 105], [32, 107], [32, 108], [32, 113], [32, 114], [32, 117], [32, 120], [32, 122], [32, 129], [32, 130], [32, 132], [32, 139], [32, 148], [32, 150], [32, 152], [32, 164], [32, 169], [32, 171], [32, 172], [32, 173], [32, 177], [33, 35], [33, 39], [33, 50], [33, 71], [33, 78], [33, 79], [33, 82], [33, 86], [33, 89], [33, 94], [33, 99], [33, 106], [33, 122], [33, 130], [33, 131], [33, 139], [33, 145], [33, 146], [33, 155], [33, 160], [33, 162], [33, 174], [34, 38], [34, 41], [34, 42], [34, 44], [34, 46], [34, 48], [34, 57], [34, 66], [34, 71], [34, 76], [34, 79], [34, 81], [34, 84], [34, 92], [34, 93], [34, 95], [34, 100], [34, 101], [34, 102], [34, 111], [34, 116], [34, 136], [34, 146], [34, 153], [34, 154], [34, 157], [34, 159], [34, 162], [34, 164], [34, 165], [34, 171], [34, 178], [34, 179], [35, 37], [35, 40], [35, 41], [35, 43], [35, 51], [35, 57], [35, 64], [35, 67], [35, 68], [35, 72], [35, 75], [35, 79], [35, 81], [35, 82], [35, 84], [35, 89], [35, 93], [35, 96], [35, 106], [35, 107], [35, 108], [35, 109], [35, 118], [35, 122], [35, 123], [35, 128], [35, 131], [35, 136], [35, 141], [35, 143], [35, 155], [35, 174], [36, 40], [36, 47], [36, 66], [36, 75], [36, 77], [36, 78], [36, 84], [36, 87], [36, 92], [36, 98], [36, 99], [36, 100], [36, 103], [36, 104], [36, 105], [36, 110], [36, 111], [36, 114], [36, 134], [36, 149], [36, 151], [36, 159], [36, 161], [36, 168], [36, 177], [37, 39], [37, 40], [37, 48], [37, 53], [37, 58], [37, 63], [37, 66], [37, 75], [37, 82], [37, 84], [37, 86], [37, 87], [37, 88], [37, 97], [37, 106], [37, 108], [37, 111], [37, 126], [37, 127], [37, 132], [37, 134], [37, 135], [37, 137], [37, 139], [37, 141], [37, 154], [37, 157], [37, 159], [37, 160], [37, 161], [37, 167], [37, 168], [37, 171], [38, 39], [38, 45], [38, 47], [38, 49], [38, 56], [38, 65], [38, 70], [38, 81], [38, 84], [38, 90], [38, 91], [38, 94], [38, 96], [38, 99], [38, 103], [38, 105], [38, 107], [38, 110], [38, 114], [38, 117], [38, 119], [38, 121], [38, 126], [38, 130], [38, 139], [38, 148], [38, 151], [38, 154], [38, 174], [38, 178], [38, 179], [39, 43], [39, 49], [39, 66], [39, 82], [39, 87], [39, 88], [39, 96], [39, 106], [39, 113], [39, 116], [39, 118], [39, 123], [39, 124], [39, 130], [39, 133], [39, 137], [39, 143], [39, 146], [39, 149], [39, 157], [39, 163], [39, 164], [39, 165], [39, 171], [39, 175], [40, 52], [40, 67], [40, 72], [40, 73], [40, 77], [40, 81], [40, 88], [40, 90], [40, 97], [40, 104], [40, 108], [40, 117], [40, 121], [40, 122], [40, 124], [40, 136], [40, 144], [40, 145], [40, 150], [40, 153], [40, 154], [40, 160], [40, 162], [40, 170], [40, 175], [41, 46], [41, 48], [41, 52], [41, 54], [41, 58], [41, 63], [41, 64], [41, 65], [41, 76], [41, 79], [41, 84], [41, 85], [41, 94], [41, 100], [41, 102], [41, 116], [41, 118], [41, 123], [41, 138], [41, 148], [41, 149], [41, 157], [41, 161], [41, 165], [41, 167], [41, 168], [41, 171], [41, 176], [41, 178], [42, 53], [42, 60], [42, 67], [42, 77], [42, 78], [42, 81], [42, 86], [42, 92], [42, 96], [42, 118], [42, 120], [42, 121], [42, 123], [42, 126], [42, 129], [42, 134], [42, 136], [42, 138], [42, 145], [42, 151], [42, 152], [42, 153], [42, 163], [42, 166], [42, 168], [42, 176], [43, 50], [43, 63], [43, 65], [43, 66], [43, 68], [43, 70], [43, 72], [43, 74], [43, 76], [43, 79], [43, 83], [43, 89], [43, 96], [43, 105], [43, 107], [43, 109], [43, 110], [43, 116], [43, 118], [43, 121], [43, 129], [43, 131], [43, 134], [43, 136], [43, 137], [43, 142], [43, 145], [43, 148], [43, 161], [43, 162], [43, 165], [43, 171], [43, 173], [43, 174], [43, 178], [43, 179], [44, 46], [44, 50], [44, 53], [44, 54], [44, 56], [44, 59], [44, 60], [44, 66], [44, 70], [44, 80], [44, 83], [44, 89], [44, 92], [44, 103], [44, 108], [44, 112], [44, 117], [44, 118], [44, 120], [44, 122], [44, 125], [44, 129], [44, 134], [44, 144], [44, 145], [44, 146], [44, 149], [44, 150], [44, 166], [44, 167], [44, 174], [45, 47], [45, 50], [45, 52], [45, 53], [45, 55], [45, 60], [45, 61], [45, 67], [45, 76], [45, 79], [45, 81], [45, 89], [45, 91], [45, 94], [45, 100], [45, 114], [45, 115], [45, 117], [45, 121], [45, 123], [45, 132], [45, 145], [45, 146], [45, 150], [45, 152], [45, 153], [45, 156], [45, 157], [45, 163], [45, 165], [45, 173], [45, 175], [45, 177], [45, 179], [46, 52], [46, 54], [46, 64], [46, 72], [46, 77], [46, 91], [46, 92], [46, 93], [46, 99], [46, 108], [46, 113], [46, 116], [46, 118], [46, 122], [46, 127], [46, 135], [46, 151], [46, 152], [46, 159], [46, 163], [46, 171], [46, 176], [47, 61], [47, 63], [47, 64], [47, 65], [47, 72], [47, 86], [47, 92], [47, 94], [47, 95], [47, 98], [47, 102], [47, 103], [47, 107], [47, 112], [47, 114], [47, 115], [47, 116], [47, 120], [47, 121], [47, 125], [47, 128], [47, 134], [47, 135], [47, 136], [47, 141], [47, 145], [47, 146], [47, 151], [47, 153], [47, 158], [47, 161], [47, 170], [47, 171], [48, 51], [48, 55], [48, 56], [48, 57], [48, 58], [48, 64], [48, 65], [48, 73], [48, 80], [48, 84], [48, 88], [48, 89], [48, 92], [48, 94], [48, 99], [48, 100], [48, 114], [48, 116], [48, 136], [48, 137], [48, 140], [48, 161], [48, 175], [48, 176], [48, 178], [49, 59], [49, 60], [49, 64], [49, 65], [49, 82], [49, 89], [49, 91], [49, 92], [49, 95], [49, 99], [49, 102], [49, 104], [49, 105], [49, 106], [49, 109], [49, 114], [49, 124], [49, 125], [49, 128], [49, 137], [49, 154], [49, 159], [49, 163], [49, 170], [49, 171], [50, 51], [50, 66], [50, 74], [50, 86], [50, 93], [50, 102], [50, 104], [50, 114], [50, 121], [50, 122], [50, 131], [50, 134], [50, 140], [50, 141], [50, 147], [50, 150], [50, 153], [50, 160], [50, 161], [50, 163], [50, 169], [51, 63], [51, 73], [51, 76], [51, 81], [51, 85], [51, 97], [51, 105], [51, 109], [51, 115], [51, 131], [51, 142], [51, 146], [51, 154], [51, 160], [51, 162], [51, 168], [51, 172], [51, 175], [51, 176], [51, 179], [52, 58], [52, 64], [52, 65], [52, 72], [52, 84], [52, 86], [52, 97], [52, 99], [52, 106], [52, 109], [52, 111], [52, 112], [52, 118], [52, 129], [52, 137], [52, 145], [52, 147], [52, 149], [52, 150], [52, 156], [52, 163], [52, 169], [52, 171], [53, 56], [53, 57], [53, 61], [53, 62], [53, 66], [53, 81], [53, 82], [53, 92], [53, 98], [53, 110], [53, 111], [53, 118], [53, 121], [53, 123], [53, 126], [53, 139], [53, 151], [53, 153], [53, 155], [53, 157], [53, 158], [53, 165], [53, 166], [53, 178], [54, 66], [54, 71], [54, 72], [54, 73], [54, 84], [54, 106], [54, 132], [54, 134], [54, 136], [54, 139], [54, 149], [54, 151], [54, 152], [54, 153], [54, 164], [54, 165], [54, 169], [54, 173], [55, 58], [55, 60], [55, 71], [55, 78], [55, 92], [55, 102], [55, 103], [55, 106], [55, 108], [55, 113], [55, 121], [55, 126], [55, 133], [55, 134], [55, 140], [55, 146], [55, 148], [55, 150], [55, 153], [55, 158], [56, 57], [56, 58], [56, 69], [56, 72], [56, 74], [56, 81], [56, 84], [56, 91], [56, 105], [56, 108], [56, 115], [56, 116], [56, 117], [56, 120], [56, 126], [56, 131], [56, 141], [56, 146], [56, 147], [56, 162], [56, 166], [56, 167], [56, 170], [56, 171], [56, 173], [56, 177], [57, 61], [57, 62], [57, 67], [57, 81], [57, 92], [57, 93], [57, 96], [57, 98], [57, 101], [57, 106], [57, 109], [57, 114], [57, 122], [57, 125], [57, 136], [57, 143], [57, 150], [57, 168], [57, 171], [57, 176], [57, 179], [58, 61], [58, 64], [58, 73], [58, 77], [58, 78], [58, 79], [58, 83], [58, 91], [58, 94], [58, 99], [58, 107], [58, 116], [58, 119], [58, 123], [58, 134], [58, 139], [58, 141], [58, 143], [58, 145], [58, 148], [58, 149], [58, 152], [58, 153], [58, 154], [58, 157], [58, 161], [58, 163], [58, 174], [59, 62], [59, 74], [59, 75], [59, 77], [59, 80], [59, 82], [59, 90], [59, 93], [59, 107], [59, 114], [59, 120], [59, 142], [59, 148], [59, 149], [59, 151], [59, 154], [59, 160], [59, 166], [59, 167], [59, 175], [60, 61], [60, 64], [60, 80], [60, 89], [60, 94], [60, 95], [60, 101], [60, 103], [60, 109], [60, 112], [60, 117], [60, 120], [60, 123], [60, 127], [60, 130], [60, 131], [60, 133], [60, 134], [60, 138], [60, 147], [60, 148], [60, 150], [60, 152], [60, 154], [60, 156], [60, 165], [60, 166], [60, 167], [60, 171], [60, 175], [60, 178], [61, 62], [61, 67], [61, 68], [61, 69], [61, 71], [61, 84], [61, 85], [61, 92], [61, 94], [61, 105], [61, 109], [61, 112], [61, 128], [61, 143], [61, 154], [61, 162], [61, 166], [62, 64], [62, 73], [62, 79], [62, 86], [62, 95], [62, 97], [62, 104], [62, 107], [62, 117], [62, 120], [62, 129], [62, 142], [62, 145], [62, 146], [62, 150], [62, 152], [62, 157], [62, 166], [62, 167], [62, 169], [62, 172], [62, 173], [62, 177], [63, 68], [63, 75], [63, 76], [63, 92], [63, 96], [63, 106], [63, 109], [63, 111], [63, 112], [63, 117], [63, 129], [63, 131], [63, 142], [63, 143], [63, 145], [63, 155], [63, 170], [63, 172], [63, 174], [64, 66], [64, 78], [64, 81], [64, 82], [64, 95], [64, 96], [64, 99], [64, 100], [64, 105], [64, 108], [64, 116], [64, 117], [64, 118], [64, 125], [64, 128], [64, 135], [64, 137], [64, 138], [64, 141], [64, 142], [64, 172], [64, 173], [65, 68], [65, 69], [65, 73], [65, 76], [65, 79], [65, 105], [65, 106], [65, 111], [65, 114], [65, 118], [65, 127], [65, 131], [65, 133], [65, 135], [65, 136], [65, 137], [65, 138], [65, 139], [65, 140], [65, 142], [65, 143], [65, 144], [65, 161], [65, 163], [65, 168], [65, 169], [65, 171], [65, 172], [65, 173], [66, 71], [66, 72], [66, 73], [66, 75], [66, 76], [66, 79], [66, 83], [66, 85], [66, 87], [66, 89], [66, 99], [66, 102], [66, 114], [66, 119], [66, 121], [66, 123], [66, 125], [66, 127], [66, 131], [66, 137], [66, 142], [66, 143], [66, 145], [66, 149], [67, 70], [67, 97], [67, 103], [67, 122], [67, 123], [67, 125], [67, 129], [67, 130], [67, 131], [67, 143], [67, 151], [67, 164], [67, 171], [68, 71], [68, 73], [68, 76], [68, 80], [68, 81], [68, 83], [68, 108], [68, 111], [68, 121], [68, 125], [68, 127], [68, 128], [68, 135], [68, 137], [68, 139], [68, 142], [68, 161], [68, 162], [68, 163], [68, 165], [68, 169], [69, 70], [69, 71], [69, 75], [69, 88], [69, 99], [69, 101], [69, 124], [69, 126], [69, 129], [69, 132], [69, 140], [69, 148], [69, 149], [69, 153], [69, 154], [69, 155], [69, 161], [69, 164], [69, 167], [69, 168], [69, 171], [69, 173], [69, 174], [69, 175], [70, 78], [70, 86], [70, 87], [70, 88], [70, 97], [70, 100], [70, 109], [70, 111], [70, 112], [70, 114], [70, 116], [70, 117], [70, 121], [70, 123], [70, 124], [70, 125], [70, 129], [70, 132], [70, 133], [70, 135], [70, 138], [70, 140], [70, 141], [70, 143], [70, 147], [70, 148], [70, 149], [70, 150], [70, 153], [70, 168], [70, 170], [70, 172], [70, 174], [71, 78], [71, 93], [71, 94], [71, 97], [71, 98], [71, 105], [71, 106], [71, 107], [71, 108], [71, 115], [71, 125], [71, 133], [71, 136], [71, 139], [71, 142], [71, 144], [71, 147], [71, 157], [71, 160], [71, 161], [71, 164], [71, 166], [71, 170], [71, 171], [71, 172], [72, 76], [72, 78], [72, 93], [72, 99], [72, 109], [72, 119], [72, 120], [72, 121], [72, 130], [72, 131], [72, 133], [72, 146], [72, 147], [72, 154], [72, 156], [72, 161], [72, 166], [72, 176], [73, 76], [73, 78], [73, 81], [73, 82], [73, 89], [73, 91], [73, 98], [73, 102], [73, 106], [73, 114], [73, 121], [73, 123], [73, 133], [73, 136], [73, 147], [73, 153], [73, 154], [73, 156], [73, 167], [73, 169], [73, 176], [74, 79], [74, 80], [74, 94], [74, 98], [74, 102], [74, 103], [74, 105], [74, 107], [74, 112], [74, 130], [74, 131], [74, 142], [74, 147], [74, 149], [74, 152], [74, 154], [74, 169], [74, 170], [74, 173], [74, 175], [74, 176], [75, 76], [75, 77], [75, 79], [75, 82], [75, 83], [75, 84], [75, 90], [75, 92], [75, 94], [75, 95], [75, 107], [75, 114], [75, 117], [75, 118], [75, 125], [75, 126], [75, 130], [75, 131], [75, 133], [75, 135], [75, 138], [75, 140], [75, 142], [75, 148], [75, 151], [75, 161], [75, 162], [76, 88], [76, 89], [76, 108], [76, 111], [76, 114], [76, 116], [76, 117], [76, 137], [76, 140], [76, 147], [76, 151], [76, 158], [76, 160], [76, 166], [76, 170], [76, 173], [77, 78], [77, 80], [77, 81], [77, 82], [77, 89], [77, 90], [77, 91], [77, 97], [77, 105], [77, 106], [77, 110], [77, 120], [77, 126], [77, 151], [77, 152], [77, 153], [77, 154], [77, 158], [77, 159], [77, 163], [77, 165], [77, 174], [77, 175], [78, 79], [78, 89], [78, 90], [78, 98], [78, 103], [78, 119], [78, 121], [78, 122], [78, 130], [78, 131], [78, 141], [78, 152], [78, 154], [78, 162], [78, 167], [78, 176], [78, 179], [79, 91], [79, 92], [79, 95], [79, 98], [79, 106], [79, 108], [79, 129], [79, 131], [79, 132], [79, 134], [79, 138], [79, 140], [79, 142], [79, 143], [79, 145], [79, 158], [79, 165], [79, 174], [80, 81], [80, 82], [80, 84], [80, 86], [80, 88], [80, 95], [80, 96], [80, 102], [80, 108], [80, 112], [80, 119], [80, 121], [80, 122], [80, 125], [80, 139], [80, 140], [80, 144], [80, 146], [80, 147], [80, 153], [80, 155], [80, 174], [81, 82], [81, 86], [81, 88], [81, 94], [81, 97], [81, 98], [81, 105], [81, 106], [81, 108], [81, 110], [81, 113], [81, 120], [81, 129], [81, 134], [81, 135], [81, 136], [81, 142], [81, 143], [81, 145], [81, 159], [81, 161], [81, 169], [81, 174], [82, 85], [82, 88], [82, 107], [82, 112], [82, 122], [82, 127], [82, 131], [82, 140], [82, 141], [82, 142], [82, 144], [82, 145], [82, 146], [82, 147], [82, 154], [82, 155], [82, 165], [82, 166], [82, 168], [83, 98], [83, 101], [83, 106], [83, 110], [83, 115], [83, 116], [83, 117], [83, 118], [83, 140], [83, 152], [83, 154], [83, 156], [83, 158], [83, 159], [83, 167], [83, 170], [83, 171], [83, 177], [83, 178], [84, 87], [84, 91], [84, 92], [84, 93], [84, 95], [84, 97], [84, 100], [84, 101], [84, 113], [84, 114], [84, 117], [84, 119], [84, 130], [84, 144], [84, 147], [84, 148], [84, 149], [84, 150], [84, 151], [84, 152], [84, 153], [84, 157], [84, 158], [84, 160], [84, 169], [84, 171], [84, 172], [84, 173], [84, 174], [85, 90], [85, 92], [85, 98], [85, 101], [85, 114], [85, 116], [85, 122], [85, 128], [85, 140], [85, 146], [85, 153], [85, 162], [85, 165], [85, 169], [85, 170], [85, 171], [85, 173], [86, 87], [86, 91], [86, 100], [86, 101], [86, 103], [86, 105], [86, 106], [86, 107], [86, 115], [86, 118], [86, 120], [86, 125], [86, 126], [86, 127], [86, 128], [86, 139], [86, 140], [86, 142], [86, 146], [86, 147], [86, 154], [86, 157], [86, 163], [86, 169], [86, 174], [86, 175], [86, 179], [87, 88], [87, 89], [87, 90], [87, 95], [87, 102], [87, 115], [87, 123], [87, 124], [87, 127], [87, 128], [87, 131], [87, 136], [87, 141], [87, 162], [87, 164], [87, 170], [87, 173], [88, 91], [88, 94], [88, 101], [88, 103], [88, 104], [88, 105], [88, 114], [88, 117], [88, 122], [88, 125], [88, 126], [88, 134], [88, 139], [88, 148], [88, 151], [88, 153], [88, 154], [88, 167], [88, 179], [89, 99], [89, 101], [89, 102], [89, 103], [89, 104], [89, 109], [89, 113], [89, 116], [89, 118], [89, 122], [89, 126], [89, 138], [89, 143], [89, 145], [89, 150], [89, 161], [89, 163], [89, 170], [90, 96], [90, 98], [90, 100], [90, 101], [90, 107], [90, 108], [90, 113], [90, 114], [90, 117], [90, 120], [90, 123], [90, 129], [90, 130], [90, 131], [90, 150], [90, 151], [90, 152], [90, 154], [90, 162], [90, 167], [90, 172], [90, 175], [91, 102], [91, 119], [91, 122], [91, 123], [91, 125], [91, 126], [91, 133], [91, 141], [91, 145], [91, 149], [91, 150], [91, 154], [91, 159], [91, 168], [91, 175], [92, 97], [92, 102], [92, 107], [92, 110], [92, 113], [92, 121], [92, 124], [92, 127], [92, 132], [92, 133], [92, 134], [92, 135], [92, 142], [92, 145], [92, 150], [92, 152], [92, 153], [92, 155], [92, 156], [92, 159], [92, 160], [92, 163], [92, 169], [92, 179], [93, 100], [93, 111], [93, 114], [93, 119], [93, 120], [93, 125], [93, 147], [93, 163], [93, 170], [93, 174], [94, 95], [94, 100], [94, 103], [94, 105], [94, 110], [94, 114], [94, 116], [94, 117], [94, 121], [94, 130], [94, 131], [94, 137], [94, 141], [94, 143], [94, 146], [94, 149], [94, 154], [94, 170], [94, 171], [95, 97], [95, 104], [95, 107], [95, 108], [95, 112], [95, 115], [95, 116], [95, 118], [95, 119], [95, 121], [95, 127], [95, 130], [95, 133], [95, 135], [95, 137], [95, 140], [95, 149], [95, 154], [95, 161], [95, 169], [95, 171], [95, 172], [95, 175], [95, 176], [96, 102], [96, 103], [96, 105], [96, 113], [96, 118], [96, 124], [96, 133], [96, 141], [96, 142], [96, 149], [96, 156], [96, 157], [96, 160], [96, 165], [96, 176], [97, 98], [97, 107], [97, 108], [97, 111], [97, 119], [97, 123], [97, 125], [97, 127], [97, 129], [97, 131], [97, 139], [97, 142], [97, 143], [97, 145], [97, 168], [97, 169], [97, 172], [98, 101], [98, 102], [98, 104], [98, 106], [98, 107], [98, 114], [98, 115], [98, 118], [98, 122], [98, 123], [98, 129], [98, 133], [98, 135], [98, 136], [98, 137], [98, 138], [98, 141], [98, 143], [98, 146], [98, 152], [98, 169], [98, 170], [98, 174], [98, 175], [98, 179], [99, 107], [99, 110], [99, 116], [99, 119], [99, 120], [99, 124], [99, 131], [99, 133], [99, 138], [99, 143], [99, 154], [99, 156], [99, 158], [99, 159], [99, 167], [99, 169], [100, 102], [100, 107], [100, 108], [100, 120], [100, 129], [100, 131], [100, 137], [100, 141], [100, 143], [100, 149], [100, 157], [100, 163], [100, 167], [100, 173], [100, 174], [100, 177], [101, 102], [101, 105], [101, 106], [101, 108], [101, 130], [101, 133], [101, 134], [101, 135], [101, 136], [101, 138], [101, 139], [101, 146], [101, 156], [101, 159], [101, 164], [101, 165], [101, 168], [101, 170], [101, 172], [101, 173], [101, 176], [102, 103], [102, 106], [102, 115], [102, 128], [102, 139], [102, 146], [102, 147], [102, 152], [102, 154], [102, 155], [102, 157], [102, 159], [102, 162], [102, 163], [102, 169], [103, 106], [103, 115], [103, 118], [103, 120], [103, 121], [103, 139], [103, 141], [103, 164], [103, 177], [104, 110], [104, 115], [104, 119], [104, 126], [104, 133], [104, 137], [104, 140], [104, 143], [104, 148], [104, 152], [104, 156], [104, 169], [104, 171], [104, 173], [104, 174], [104, 179], [105, 120], [105, 129], [105, 131], [105, 135], [105, 137], [105, 148], [105, 149], [105, 150], [105, 152], [105, 155], [105, 160], [105, 167], [105, 174], [106, 112], [106, 119], [106, 123], [106, 135], [106, 137], [106, 140], [106, 143], [106, 145], [106, 147], [106, 152], [106, 162], [106, 163], [106, 165], [106, 173], [106, 175], [107, 108], [107, 111], [107, 112], [107, 113], [107, 115], [107, 117], [107, 118], [107, 127], [107, 128], [107, 139], [107, 140], [107, 142], [107, 146], [107, 147], [107, 152], [107, 155], [107, 156], [107, 163], [107, 165], [107, 169], [107, 170], [107, 175], [108, 113], [108, 119], [108, 121], [108, 123], [108, 127], [108, 129], [108, 138], [108, 141], [108, 142], [108, 147], [108, 154], [108, 160], [108, 162], [108, 167], [108, 178], [108, 179], [109, 111], [109, 113], [109, 116], [109, 118], [109, 120], [109, 122], [109, 123], [109, 127], [109, 129], [109, 136], [109, 138], [109, 141], [109, 147], [109, 163], [109, 168], [109, 171], [110, 111], [110, 112], [110, 113], [110, 119], [110, 120], [110, 137], [110, 139], [110, 141], [110, 143], [110, 145], [110, 149], [110, 154], [110, 156], [110, 162], [110, 168], [110, 177], [110, 179], [111, 135], [111, 137], [111, 140], [111, 165], [111, 170], [111, 171], [111, 172], [111, 176], [112, 114], [112, 116], [112, 124], [112, 131], [112, 136], [112, 142], [112, 145], [112, 148], [112, 150], [112, 159], [112, 161], [112, 167], [112, 169], [112, 177], [113, 119], [113, 123], [113, 126], [113, 128], [113, 133], [113, 137], [113, 142], [113, 143], [113, 148], [113, 150], [113, 170], [113, 176], [113, 178], [113, 179], [114, 119], [114, 122], [114, 127], [114, 130], [114, 131], [114, 142], [114, 146], [114, 147], [114, 148], [114, 152], [114, 165], [114, 174], [115, 125], [115, 126], [115, 143], [115, 152], [115, 153], [115, 160], [115, 163], [115, 166], [115, 168], [115, 169], [115, 171], [115, 172], [115, 173], [115, 174], [115, 175], [115, 179], [116, 119], [116, 122], [116, 123], [116, 124], [116, 125], [116, 126], [116, 129], [116, 133], [116, 134], [116, 137], [116, 142], [116, 145], [116, 150], [116, 153], [116, 154], [116, 157], [116, 165], [116, 172], [117, 118], [117, 119], [117, 121], [117, 122], [117, 140], [117, 143], [117, 146], [117, 147], [117, 154], [117, 156], [117, 159], [117, 170], [117, 173], [117, 176], [118, 125], [118, 156], [118, 158], [118, 166], [118, 167], [118, 174], [118, 175], [119, 120], [119, 125], [119, 130], [119, 140], [119, 147], [119, 150], [119, 157], [119, 159], [119, 164], [119, 165], [119, 170], [119, 172], [119, 175], [119, 176], [119, 177], [120, 125], [120, 127], [120, 132], [120, 141], [120, 151], [120, 157], [120, 160], [120, 161], [120, 164], [120, 166], [120, 170], [120, 172], [120, 175], [120, 178], [121, 122], [121, 142], [121, 147], [121, 148], [121, 154], [121, 157], [121, 160], [121, 161], [121, 164], [121, 168], [121, 178], [121, 179], [122, 133], [122, 138], [122, 145], [122, 152], [122, 160], [122, 163], [122, 170], [122, 175], [122, 178], [123, 124], [123, 125], [123, 129], [123, 130], [123, 133], [123, 136], [123, 137], [123, 138], [123, 139], [123, 147], [123, 150], [123, 152], [123, 154], [123, 156], [123, 160], [123, 161], [123, 166], [123, 170], [123, 171], [123, 172], [123, 174], [124, 127], [124, 131], [124, 133], [124, 136], [124, 140], [124, 161], [124, 162], [124, 169], [124, 170], [124, 172], [124, 179], [125, 133], [125, 145], [125, 154], [125, 160], [125, 174], [125, 175], [125, 176], [126, 136], [126, 143], [126, 146], [126, 150], [126, 161], [126, 163], [126, 165], [126, 167], [127, 130], [127, 131], [127, 139], [127, 145], [127, 147], [127, 149], [127, 152], [127, 157], [127, 162], [127, 165], [127, 168], [128, 129], [128, 132], [128, 134], [128, 136], [128, 143], [128, 146], [128, 149], [128, 160], [128, 162], [128, 168], [128, 176], [128, 178], [129, 134], [129, 135], [129, 137], [129, 142], [129, 143], [129, 144], [129, 149], [129, 152], [129, 155], [129, 159], [129, 169], [129, 170], [129, 173], [129, 174], [129, 176], [129, 178], [130, 132], [130, 136], [130, 138], [130, 144], [130, 149], [130, 151], [130, 159], [130, 166], [130, 168], [130, 172], [130, 177], [131, 132], [131, 135], [131, 138], [131, 152], [131, 153], [131, 157], [131, 169], [131, 176], [132, 145], [132, 146], [132, 147], [132, 148], [132, 154], [132, 160], [132, 165], [132, 169], [132, 171], [133, 138], [133, 143], [133, 147], [133, 152], [133, 153], [133, 154], [133, 160], [133, 161], [133, 167], [133, 172], [133, 173], [133, 174], [133, 178], [134, 136], [134, 138], [134, 140], [134, 146], [134, 147], [134, 149], [134, 160], [134, 165], [134, 166], [134, 169], [134, 170], [134, 171], [134, 173], [134, 176], [135, 141], [135, 142], [135, 144], [135, 146], [135, 161], [135, 163], [135, 165], [135, 167], [135, 172], [135, 175], [136, 138], [136, 139], [136, 149], [136, 159], [136, 161], [136, 178], [137, 139], [137, 142], [137, 155], [137, 162], [137, 165], [137, 170], [137, 171], [138, 139], [138, 141], [138, 147], [138, 148], [138, 151], [138, 179], [139, 151], [139, 156], [139, 157], [139, 158], [139, 165], [139, 169], [139, 174], [139, 177], [140, 142], [140, 143], [140, 144], [140, 150], [140, 153], [140, 168], [140, 176], [141, 144], [141, 146], [141, 147], [141, 148], [141, 156], [141, 158], [141, 171], [142, 159], [142, 168], [142, 173], [143, 146], [143, 147], [143, 150], [143, 152], [143, 153], [143, 162], [143, 168], [143, 176], [144, 149], [144, 150], [144, 165], [144, 170], [144, 176], [145, 158], [145, 161], [145, 163], [145, 179], [146, 150], [146, 163], [146, 166], [146, 167], [146, 170], [146, 174], [146, 176], [147, 153], [147, 155], [147, 156], [147, 157], [147, 159], [147, 161], [147, 165], [147, 170], [147, 172], [147, 177], [147, 179], [148, 163], [148, 164], [148, 167], [148, 171], [148, 175], [148, 178], [149, 154], [149, 156], [149, 162], [149, 179], [150, 154], [150, 155], [150, 158], [150, 159], [150, 171], [150, 173], [150, 174], [150, 178], [151, 156], [151, 160], [151, 161], [151, 162], [151, 164], [151, 167], [151, 171], [151, 172], [152, 162], [152, 169], [153, 155], [153, 168], [153, 171], [153, 172], [153, 174], [154, 158], [154, 163], [154, 168], [154, 170], [154, 171], [154, 172], [154, 175], [154, 177], [155, 156], [155, 159], [155, 166], [156, 157], [156, 158], [156, 162], [156, 177], [157, 168], [157, 173], [158, 160], [158, 167], [158, 168], [158, 172], [158, 176], [159, 169], [159, 173], [160, 161], [160, 167], [160, 168], [160, 177], [161, 162], [161, 167], [161, 174], [161, 179], [162, 170], [162, 176], [162, 178], [163, 167], [163, 171], [163, 172], [163, 176], [163, 178], [163, 179], [165, 168], [165, 178], [166, 168], [166, 170], [166, 171], [167, 169], [167, 174], [168, 169], [168, 172], [169, 173], [169, 176], [169, 177], [170, 171], [170, 172], [170, 175], [170, 176], [170, 177], [171, 172], [171, 176], [171, 178], [172, 173], [172, 174], [172, 179], [173, 174], [173, 175], [174, 177], [175, 179], [176, 178], [176, 179], [177, 179], [178, 179]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l5-s9/tests/run.py b/tasks/construct-nppc-dominating-set-l5-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-dominating-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-nppc-dominating-set-l5-s9/tests/test.sh b/tasks/construct-nppc-dominating-set-l5-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-dominating-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-nppc-independent-set-l4-s7/environment/Dockerfile b/tasks/construct-nppc-independent-set-l4-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-independent-set-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-nppc-independent-set-l4-s7/environment/instance.json b/tasks/construct-nppc-independent-set-l4-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..54ad1d327f262ee0ef13177928f38b7f35e969c8 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l4-s7/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 32, "k": 16, "edges": [[0, 2], [0, 11], [0, 14], [0, 15], [0, 16], [0, 17], [0, 19], [0, 20], [0, 28], [0, 30], [1, 2], [1, 13], [1, 17], [1, 19], [1, 20], [1, 28], [1, 30], [2, 4], [2, 5], [2, 6], [2, 7], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 15], [2, 20], [2, 22], [2, 23], [2, 24], [2, 27], [2, 28], [2, 30], [3, 4], [3, 6], [3, 9], [3, 12], [3, 13], [3, 15], [3, 16], [3, 19], [3, 21], [3, 26], [3, 27], [4, 6], [4, 11], [4, 19], [4, 23], [4, 28], [5, 7], [5, 10], [5, 14], [5, 16], [5, 19], [5, 20], [5, 23], [5, 28], [5, 30], [6, 7], [6, 8], [6, 11], [6, 12], [6, 13], [6, 14], [6, 18], [6, 19], [6, 21], [6, 23], [6, 25], [6, 26], [6, 29], [6, 30], [7, 8], [7, 12], [7, 13], [7, 15], [7, 18], [7, 21], [7, 24], [7, 30], [8, 11], [8, 15], [8, 16], [8, 20], [8, 23], [9, 10], [9, 11], [9, 13], [9, 14], [9, 16], [9, 19], [9, 20], [9, 28], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [10, 18], [10, 19], [10, 20], [10, 21], [10, 22], [10, 23], [10, 24], [10, 25], [10, 27], [10, 28], [10, 29], [10, 30], [11, 14], [11, 16], [11, 20], [11, 28], [11, 29], [12, 14], [12, 15], [12, 17], [12, 20], [12, 23], [12, 30], [13, 14], [13, 16], [13, 18], [13, 19], [13, 22], [13, 23], [13, 24], [13, 28], [13, 29], [14, 15], [14, 17], [14, 18], [14, 19], [14, 23], [14, 25], [14, 26], [14, 28], [15, 16], [15, 25], [15, 26], [15, 28], [15, 30], [15, 31], [16, 17], [16, 18], [16, 19], [16, 21], [16, 22], [16, 27], [16, 28], [17, 18], [17, 20], [17, 21], [17, 23], [17, 24], [17, 27], [18, 20], [18, 23], [19, 20], [19, 22], [19, 24], [19, 25], [19, 27], [19, 28], [19, 29], [19, 31], [20, 21], [20, 23], [20, 25], [20, 28], [20, 29], [20, 30], [21, 23], [21, 30], [22, 23], [22, 28], [22, 30], [23, 25], [23, 26], [23, 27], [23, 28], [23, 31], [26, 30], [27, 28], [28, 31]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l4-s7/solution/solve.sh b/tasks/construct-nppc-independent-set-l4-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..775293c6eb458f180d4f2ba8e63f3e036d0a93b6 --- /dev/null +++ b/tasks/construct-nppc-independent-set-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' +{"independent_set": [0, 1, 4, 5, 8, 9, 12, 18, 21, 22, 24, 25, 26, 27, 29, 31]} +RLMATH_EOF diff --git a/tasks/construct-nppc-independent-set-l4-s7/tests/check.py b/tasks/construct-nppc-independent-set-l4-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..92279a931488c7f39c08a3b11162b3f54a9c662a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l4-s7/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-l4-s7/tests/instance.json b/tasks/construct-nppc-independent-set-l4-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..54ad1d327f262ee0ef13177928f38b7f35e969c8 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l4-s7/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 32, "k": 16, "edges": [[0, 2], [0, 11], [0, 14], [0, 15], [0, 16], [0, 17], [0, 19], [0, 20], [0, 28], [0, 30], [1, 2], [1, 13], [1, 17], [1, 19], [1, 20], [1, 28], [1, 30], [2, 4], [2, 5], [2, 6], [2, 7], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 15], [2, 20], [2, 22], [2, 23], [2, 24], [2, 27], [2, 28], [2, 30], [3, 4], [3, 6], [3, 9], [3, 12], [3, 13], [3, 15], [3, 16], [3, 19], [3, 21], [3, 26], [3, 27], [4, 6], [4, 11], [4, 19], [4, 23], [4, 28], [5, 7], [5, 10], [5, 14], [5, 16], [5, 19], [5, 20], [5, 23], [5, 28], [5, 30], [6, 7], [6, 8], [6, 11], [6, 12], [6, 13], [6, 14], [6, 18], [6, 19], [6, 21], [6, 23], [6, 25], [6, 26], [6, 29], [6, 30], [7, 8], [7, 12], [7, 13], [7, 15], [7, 18], [7, 21], [7, 24], [7, 30], [8, 11], [8, 15], [8, 16], [8, 20], [8, 23], [9, 10], [9, 11], [9, 13], [9, 14], [9, 16], [9, 19], [9, 20], [9, 28], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [10, 18], [10, 19], [10, 20], [10, 21], [10, 22], [10, 23], [10, 24], [10, 25], [10, 27], [10, 28], [10, 29], [10, 30], [11, 14], [11, 16], [11, 20], [11, 28], [11, 29], [12, 14], [12, 15], [12, 17], [12, 20], [12, 23], [12, 30], [13, 14], [13, 16], [13, 18], [13, 19], [13, 22], [13, 23], [13, 24], [13, 28], [13, 29], [14, 15], [14, 17], [14, 18], [14, 19], [14, 23], [14, 25], [14, 26], [14, 28], [15, 16], [15, 25], [15, 26], [15, 28], [15, 30], [15, 31], [16, 17], [16, 18], [16, 19], [16, 21], [16, 22], [16, 27], [16, 28], [17, 18], [17, 20], [17, 21], [17, 23], [17, 24], [17, 27], [18, 20], [18, 23], [19, 20], [19, 22], [19, 24], [19, 25], [19, 27], [19, 28], [19, 29], [19, 31], [20, 21], [20, 23], [20, 25], [20, 28], [20, 29], [20, 30], [21, 23], [21, 30], [22, 23], [22, 28], [22, 30], [23, 25], [23, 26], [23, 27], [23, 28], [23, 31], [26, 30], [27, 28], [28, 31]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l4-s7/tests/run.py b/tasks/construct-nppc-independent-set-l4-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-independent-set-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-nppc-independent-set-l4-s7/tests/test.sh b/tasks/construct-nppc-independent-set-l4-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-independent-set-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-nppc-independent-set-l4-s9/environment/Dockerfile b/tasks/construct-nppc-independent-set-l4-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-independent-set-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-nppc-independent-set-l4-s9/environment/instance.json b/tasks/construct-nppc-independent-set-l4-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d7c06cf17f2d944a1ec0bfb54f0ef1fd5bab411e --- /dev/null +++ b/tasks/construct-nppc-independent-set-l4-s9/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 32, "k": 16, "edges": [[0, 2], [0, 3], [0, 5], [0, 6], [0, 8], [0, 9], [0, 11], [0, 15], [0, 20], [0, 23], [0, 25], [0, 26], [0, 27], [0, 28], [0, 29], [0, 31], [1, 12], [1, 15], [1, 17], [1, 23], [1, 29], [2, 3], [2, 5], [2, 7], [2, 8], [2, 9], [2, 11], [2, 17], [2, 18], [2, 20], [2, 23], [2, 26], [2, 30], [2, 31], [3, 6], [3, 8], [3, 10], [3, 12], [3, 20], [4, 6], [4, 11], [4, 15], [4, 18], [4, 19], [4, 20], [4, 23], [5, 18], [5, 20], [5, 29], [6, 8], [6, 9], [6, 10], [6, 13], [6, 15], [6, 16], [6, 18], [6, 21], [6, 22], [6, 26], [6, 27], [6, 30], [6, 31], [7, 8], [7, 10], [7, 12], [7, 17], [7, 18], [7, 19], [7, 26], [7, 29], [8, 9], [8, 10], [8, 12], [8, 13], [8, 14], [8, 16], [8, 18], [8, 20], [8, 24], [8, 25], [8, 28], [8, 31], [9, 18], [9, 19], [9, 29], [10, 11], [10, 13], [10, 18], [10, 19], [10, 20], [10, 21], [10, 22], [10, 23], [10, 24], [10, 25], [10, 31], [11, 13], [11, 16], [11, 19], [11, 20], [11, 21], [11, 25], [11, 27], [11, 29], [11, 30], [12, 14], [12, 15], [12, 20], [12, 21], [12, 22], [12, 24], [12, 25], [12, 29], [12, 30], [13, 15], [13, 17], [13, 19], [13, 20], [13, 29], [14, 19], [14, 23], [14, 26], [14, 29], [15, 17], [15, 19], [15, 24], [15, 25], [15, 26], [15, 28], [15, 29], [16, 17], [16, 26], [16, 28], [16, 29], [17, 20], [17, 21], [17, 24], [17, 26], [17, 30], [18, 20], [18, 23], [18, 24], [19, 24], [19, 25], [19, 27], [19, 28], [19, 31], [20, 22], [20, 23], [20, 26], [20, 31], [21, 28], [21, 29], [22, 28], [23, 24], [23, 25], [23, 27], [23, 28], [23, 30], [23, 31], [24, 26], [24, 28], [25, 26], [26, 27], [26, 28], [26, 29], [26, 30], [26, 31], [28, 29], [29, 31]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l4-s9/solution/solve.sh b/tasks/construct-nppc-independent-set-l4-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c2266c8e8efe421b1fc0aa891c26206a63a0260d --- /dev/null +++ b/tasks/construct-nppc-independent-set-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' +{"independent_set": [1, 3, 4, 5, 7, 9, 13, 14, 16, 21, 22, 24, 25, 27, 30, 31]} +RLMATH_EOF diff --git a/tasks/construct-nppc-independent-set-l4-s9/tests/check.py b/tasks/construct-nppc-independent-set-l4-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..92279a931488c7f39c08a3b11162b3f54a9c662a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l4-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-l4-s9/tests/instance.json b/tasks/construct-nppc-independent-set-l4-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d7c06cf17f2d944a1ec0bfb54f0ef1fd5bab411e --- /dev/null +++ b/tasks/construct-nppc-independent-set-l4-s9/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 32, "k": 16, "edges": [[0, 2], [0, 3], [0, 5], [0, 6], [0, 8], [0, 9], [0, 11], [0, 15], [0, 20], [0, 23], [0, 25], [0, 26], [0, 27], [0, 28], [0, 29], [0, 31], [1, 12], [1, 15], [1, 17], [1, 23], [1, 29], [2, 3], [2, 5], [2, 7], [2, 8], [2, 9], [2, 11], [2, 17], [2, 18], [2, 20], [2, 23], [2, 26], [2, 30], [2, 31], [3, 6], [3, 8], [3, 10], [3, 12], [3, 20], [4, 6], [4, 11], [4, 15], [4, 18], [4, 19], [4, 20], [4, 23], [5, 18], [5, 20], [5, 29], [6, 8], [6, 9], [6, 10], [6, 13], [6, 15], [6, 16], [6, 18], [6, 21], [6, 22], [6, 26], [6, 27], [6, 30], [6, 31], [7, 8], [7, 10], [7, 12], [7, 17], [7, 18], [7, 19], [7, 26], [7, 29], [8, 9], [8, 10], [8, 12], [8, 13], [8, 14], [8, 16], [8, 18], [8, 20], [8, 24], [8, 25], [8, 28], [8, 31], [9, 18], [9, 19], [9, 29], [10, 11], [10, 13], [10, 18], [10, 19], [10, 20], [10, 21], [10, 22], [10, 23], [10, 24], [10, 25], [10, 31], [11, 13], [11, 16], [11, 19], [11, 20], [11, 21], [11, 25], [11, 27], [11, 29], [11, 30], [12, 14], [12, 15], [12, 20], [12, 21], [12, 22], [12, 24], [12, 25], [12, 29], [12, 30], [13, 15], [13, 17], [13, 19], [13, 20], [13, 29], [14, 19], [14, 23], [14, 26], [14, 29], [15, 17], [15, 19], [15, 24], [15, 25], [15, 26], [15, 28], [15, 29], [16, 17], [16, 26], [16, 28], [16, 29], [17, 20], [17, 21], [17, 24], [17, 26], [17, 30], [18, 20], [18, 23], [18, 24], [19, 24], [19, 25], [19, 27], [19, 28], [19, 31], [20, 22], [20, 23], [20, 26], [20, 31], [21, 28], [21, 29], [22, 28], [23, 24], [23, 25], [23, 27], [23, 28], [23, 30], [23, 31], [24, 26], [24, 28], [25, 26], [26, 27], [26, 28], [26, 29], [26, 30], [26, 31], [28, 29], [29, 31]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l4-s9/tests/run.py b/tasks/construct-nppc-independent-set-l4-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-independent-set-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-nppc-independent-set-l4-s9/tests/test.sh b/tasks/construct-nppc-independent-set-l4-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-independent-set-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-nppc-quad-diophantine-l1-s0/environment/Dockerfile b/tasks/construct-nppc-quad-diophantine-l1-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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-nppc-quad-diophantine-l1-s0/environment/instance.json b/tasks/construct-nppc-quad-diophantine-l1-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6d906c3273b653c3e62cd6fe101130fbbb784266 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l1-s0/environment/instance.json @@ -0,0 +1 @@ +{"a": 31, "b": 49, "c": 75411, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l1-s0/solution/solve.sh b/tasks/construct-nppc-quad-diophantine-l1-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..848682928f8f06b29b6b0b90bd2a18d859c361bc --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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' +{"x": 49, "y": 20} +RLMATH_EOF diff --git a/tasks/construct-nppc-quad-diophantine-l1-s0/tests/check.py b/tasks/construct-nppc-quad-diophantine-l1-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..88989d2a8839b089c9b07dd2d3c26c21bfdca58c --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l1-s0/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-l1-s0/tests/instance.json b/tasks/construct-nppc-quad-diophantine-l1-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6d906c3273b653c3e62cd6fe101130fbbb784266 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l1-s0/tests/instance.json @@ -0,0 +1 @@ +{"a": 31, "b": 49, "c": 75411, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l1-s0/tests/run.py b/tasks/construct-nppc-quad-diophantine-l1-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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-nppc-quad-diophantine-l1-s0/tests/test.sh b/tasks/construct-nppc-quad-diophantine-l1-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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-nppc-quad-diophantine-l1-s7/environment/Dockerfile b/tasks/construct-nppc-quad-diophantine-l1-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l1-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-quad-diophantine-l1-s7/environment/instance.json b/tasks/construct-nppc-quad-diophantine-l1-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..61d9a9ab1f0c897581f867812261e4d27c7e3598 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l1-s7/environment/instance.json @@ -0,0 +1 @@ +{"a": 32, "b": 15, "c": 2168, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l1-s7/solution/solve.sh b/tasks/construct-nppc-quad-diophantine-l1-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e5115863c2e3f17244fa2297befaa5a089ab6b51 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l1-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": 7, "y": 40} +RLMATH_EOF diff --git a/tasks/construct-nppc-quad-diophantine-l1-s7/tests/check.py b/tasks/construct-nppc-quad-diophantine-l1-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..88989d2a8839b089c9b07dd2d3c26c21bfdca58c --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l1-s7/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-l1-s7/tests/instance.json b/tasks/construct-nppc-quad-diophantine-l1-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..61d9a9ab1f0c897581f867812261e4d27c7e3598 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l1-s7/tests/instance.json @@ -0,0 +1 @@ +{"a": 32, "b": 15, "c": 2168, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l1-s7/tests/run.py b/tasks/construct-nppc-quad-diophantine-l1-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l1-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-quad-diophantine-l1-s7/tests/test.sh b/tasks/construct-nppc-quad-diophantine-l1-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l1-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-quad-diophantine-l5-s1/environment/Dockerfile b/tasks/construct-nppc-quad-diophantine-l5-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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-nppc-quad-diophantine-l5-s1/environment/instance.json b/tasks/construct-nppc-quad-diophantine-l5-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5124110ab7f822f4f13c29d017a6c084751ffed0 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l5-s1/environment/instance.json @@ -0,0 +1 @@ +{"a": 9015808, "b": 9542840, "c": 22638661875400552160, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l5-s1/solution/solve.sh b/tasks/construct-nppc-quad-diophantine-l5-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2914b9f43b345539a4dd69b918e9bcdd3617471e --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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' +{"x": 1584610, "y": 7177604} +RLMATH_EOF diff --git a/tasks/construct-nppc-quad-diophantine-l5-s1/tests/check.py b/tasks/construct-nppc-quad-diophantine-l5-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..88989d2a8839b089c9b07dd2d3c26c21bfdca58c --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l5-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-l5-s1/tests/instance.json b/tasks/construct-nppc-quad-diophantine-l5-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5124110ab7f822f4f13c29d017a6c084751ffed0 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l5-s1/tests/instance.json @@ -0,0 +1 @@ +{"a": 9015808, "b": 9542840, "c": 22638661875400552160, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l5-s1/tests/run.py b/tasks/construct-nppc-quad-diophantine-l5-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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-nppc-quad-diophantine-l5-s1/tests/test.sh b/tasks/construct-nppc-quad-diophantine-l5-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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-nppc-quad-diophantine-l5-s8/environment/Dockerfile b/tasks/construct-nppc-quad-diophantine-l5-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l5-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-l5-s8/environment/instance.json b/tasks/construct-nppc-quad-diophantine-l5-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c9c84bbbef8ca8ee746b55fd6f17a7bbc50a3e6e --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l5-s8/environment/instance.json @@ -0,0 +1 @@ +{"a": 5542964, "b": 274398, "c": 81629428952291573792, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l5-s8/solution/solve.sh b/tasks/construct-nppc-quad-diophantine-l5-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..934a683d7e9ebf0eb453feba2d44c1ab4c219aa9 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l5-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": 3837535, "y": 997354} +RLMATH_EOF diff --git a/tasks/construct-nppc-quad-diophantine-l5-s8/tests/check.py b/tasks/construct-nppc-quad-diophantine-l5-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..88989d2a8839b089c9b07dd2d3c26c21bfdca58c --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l5-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-l5-s8/tests/instance.json b/tasks/construct-nppc-quad-diophantine-l5-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c9c84bbbef8ca8ee746b55fd6f17a7bbc50a3e6e --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l5-s8/tests/instance.json @@ -0,0 +1 @@ +{"a": 5542964, "b": 274398, "c": 81629428952291573792, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l5-s8/tests/run.py b/tasks/construct-nppc-quad-diophantine-l5-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l5-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-l5-s8/tests/test.sh b/tasks/construct-nppc-quad-diophantine-l5-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l5-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-l1-s0/environment/Dockerfile b/tasks/construct-nppc-quadratic-congruence-l1-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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-nppc-quadratic-congruence-l1-s0/environment/instance.json b/tasks/construct-nppc-quadratic-congruence-l1-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8983e9da32211d1ba123a94cd49fd463b7bb3dd9 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l1-s0/environment/instance.json @@ -0,0 +1 @@ +{"a": 0, "b": 16, "c": 80, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l1-s0/solution/solve.sh b/tasks/construct-nppc-quadratic-congruence-l1-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ed341d80c6640d9f342e581e9233ac0e15bb817a --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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' +{"x": 36} +RLMATH_EOF diff --git a/tasks/construct-nppc-quadratic-congruence-l1-s0/tests/check.py b/tasks/construct-nppc-quadratic-congruence-l1-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..1a751c071a276ca0aae7fb05bfdcd7b6e0c6d3a6 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l1-s0/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-l1-s0/tests/instance.json b/tasks/construct-nppc-quadratic-congruence-l1-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8983e9da32211d1ba123a94cd49fd463b7bb3dd9 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l1-s0/tests/instance.json @@ -0,0 +1 @@ +{"a": 0, "b": 16, "c": 80, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l1-s0/tests/run.py b/tasks/construct-nppc-quadratic-congruence-l1-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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-nppc-quadratic-congruence-l1-s0/tests/test.sh b/tasks/construct-nppc-quadratic-congruence-l1-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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-nppc-quadratic-congruence-l1-s7/environment/Dockerfile b/tasks/construct-nppc-quadratic-congruence-l1-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l1-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-quadratic-congruence-l1-s7/environment/instance.json b/tasks/construct-nppc-quadratic-congruence-l1-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5d86116a60197fa5ab6e38f1d04d1568bbc6d7c9 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l1-s7/environment/instance.json @@ -0,0 +1 @@ +{"a": 9, "b": 27, "c": 90, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l1-s7/solution/solve.sh b/tasks/construct-nppc-quadratic-congruence-l1-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..98f07ae7b38ab000bb840198b036020792257e9d --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l1-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": 57} +RLMATH_EOF diff --git a/tasks/construct-nppc-quadratic-congruence-l1-s7/tests/check.py b/tasks/construct-nppc-quadratic-congruence-l1-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..1a751c071a276ca0aae7fb05bfdcd7b6e0c6d3a6 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l1-s7/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-l1-s7/tests/instance.json b/tasks/construct-nppc-quadratic-congruence-l1-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5d86116a60197fa5ab6e38f1d04d1568bbc6d7c9 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l1-s7/tests/instance.json @@ -0,0 +1 @@ +{"a": 9, "b": 27, "c": 90, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l1-s7/tests/run.py b/tasks/construct-nppc-quadratic-congruence-l1-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l1-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-quadratic-congruence-l1-s7/tests/test.sh b/tasks/construct-nppc-quadratic-congruence-l1-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l1-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-quadratic-congruence-l1-s9/environment/Dockerfile b/tasks/construct-nppc-quadratic-congruence-l1-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l1-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-quadratic-congruence-l1-s9/environment/instance.json b/tasks/construct-nppc-quadratic-congruence-l1-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5015b21eeb328597ce312da8a889d10499f37a9b --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l1-s9/environment/instance.json @@ -0,0 +1 @@ +{"a": 49, "b": 66, "c": 65, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l1-s9/solution/solve.sh b/tasks/construct-nppc-quadratic-congruence-l1-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1257a45185065e4f882f189a3eb98fad76ef4010 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l1-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": 59} +RLMATH_EOF diff --git a/tasks/construct-nppc-quadratic-congruence-l1-s9/tests/check.py b/tasks/construct-nppc-quadratic-congruence-l1-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..1a751c071a276ca0aae7fb05bfdcd7b6e0c6d3a6 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l1-s9/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-l1-s9/tests/instance.json b/tasks/construct-nppc-quadratic-congruence-l1-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5015b21eeb328597ce312da8a889d10499f37a9b --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l1-s9/tests/instance.json @@ -0,0 +1 @@ +{"a": 49, "b": 66, "c": 65, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l1-s9/tests/run.py b/tasks/construct-nppc-quadratic-congruence-l1-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l1-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-quadratic-congruence-l1-s9/tests/test.sh b/tasks/construct-nppc-quadratic-congruence-l1-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l1-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-quadratic-congruence-l5-s8/environment/Dockerfile b/tasks/construct-nppc-quadratic-congruence-l5-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l5-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-l5-s8/environment/instance.json b/tasks/construct-nppc-quadratic-congruence-l5-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f4d4219abecfdb623191aff3a59535aa18d19be7 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l5-s8/environment/instance.json @@ -0,0 +1 @@ +{"a": 923990027566057814, "b": 4800955208639099207, "c": 4146322722292996339, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l5-s8/solution/solve.sh b/tasks/construct-nppc-quadratic-congruence-l5-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6401df8f3f9bc573d9b63ce690a1733fead9d2c0 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l5-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": 4142201632156378895} +RLMATH_EOF diff --git a/tasks/construct-nppc-quadratic-congruence-l5-s8/tests/check.py b/tasks/construct-nppc-quadratic-congruence-l5-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..1a751c071a276ca0aae7fb05bfdcd7b6e0c6d3a6 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l5-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-l5-s8/tests/instance.json b/tasks/construct-nppc-quadratic-congruence-l5-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f4d4219abecfdb623191aff3a59535aa18d19be7 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l5-s8/tests/instance.json @@ -0,0 +1 @@ +{"a": 923990027566057814, "b": 4800955208639099207, "c": 4146322722292996339, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l5-s8/tests/run.py b/tasks/construct-nppc-quadratic-congruence-l5-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l5-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-l5-s8/tests/test.sh b/tasks/construct-nppc-quadratic-congruence-l5-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l5-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-l3-s2/environment/Dockerfile b/tasks/construct-nppc-vertex-cover-l3-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l3-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-vertex-cover-l3-s2/environment/instance.json b/tasks/construct-nppc-vertex-cover-l3-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c2c169cfa9046fb1ee16f0941e3ac67866d97604 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l3-s2/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 24, "k": 12, "edges": [[0, 1], [0, 3], [0, 6], [0, 7], [0, 9], [0, 12], [0, 13], [0, 14], [0, 17], [0, 18], [0, 20], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 10], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 20], [1, 21], [2, 6], [2, 13], [2, 15], [2, 16], [2, 19], [2, 20], [3, 5], [3, 6], [3, 13], [3, 16], [3, 17], [4, 5], [4, 6], [4, 15], [4, 17], [4, 19], [4, 20], [5, 6], [5, 10], [5, 12], [5, 14], [5, 16], [5, 18], [5, 20], [5, 22], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [6, 16], [6, 17], [6, 23], [7, 15], [7, 16], [7, 19], [7, 20], [7, 23], [8, 16], [8, 17], [8, 19], [8, 23], [9, 19], [9, 20], [9, 23], [10, 15], [10, 17], [10, 18], [10, 19], [11, 13], [11, 15], [11, 16], [11, 18], [12, 13], [12, 15], [12, 17], [12, 18], [12, 19], [12, 20], [13, 14], [13, 16], [13, 18], [13, 19], [13, 20], [13, 22], [13, 23], [14, 15], [14, 17], [14, 19], [14, 23], [15, 16], [15, 17], [15, 18], [15, 19], [16, 17], [16, 18], [16, 19], [16, 20], [16, 21], [16, 22], [16, 23], [17, 18], [17, 19], [17, 20], [17, 21], [17, 23], [18, 19], [18, 23], [19, 20], [19, 21], [19, 22], [20, 21], [20, 22], [21, 23]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l3-s2/solution/solve.sh b/tasks/construct-nppc-vertex-cover-l3-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..36b364840fa4b2d599b91ae88eb8e25b0da3b66d --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l3-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, 5, 6, 13, 15, 16, 17, 18, 19, 20, 23]} +RLMATH_EOF diff --git a/tasks/construct-nppc-vertex-cover-l3-s2/tests/check.py b/tasks/construct-nppc-vertex-cover-l3-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d8ed740cc660c4837d941a8d70ea394c3bc9f69e --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l3-s2/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-l3-s2/tests/instance.json b/tasks/construct-nppc-vertex-cover-l3-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c2c169cfa9046fb1ee16f0941e3ac67866d97604 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l3-s2/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 24, "k": 12, "edges": [[0, 1], [0, 3], [0, 6], [0, 7], [0, 9], [0, 12], [0, 13], [0, 14], [0, 17], [0, 18], [0, 20], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 10], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 20], [1, 21], [2, 6], [2, 13], [2, 15], [2, 16], [2, 19], [2, 20], [3, 5], [3, 6], [3, 13], [3, 16], [3, 17], [4, 5], [4, 6], [4, 15], [4, 17], [4, 19], [4, 20], [5, 6], [5, 10], [5, 12], [5, 14], [5, 16], [5, 18], [5, 20], [5, 22], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [6, 16], [6, 17], [6, 23], [7, 15], [7, 16], [7, 19], [7, 20], [7, 23], [8, 16], [8, 17], [8, 19], [8, 23], [9, 19], [9, 20], [9, 23], [10, 15], [10, 17], [10, 18], [10, 19], [11, 13], [11, 15], [11, 16], [11, 18], [12, 13], [12, 15], [12, 17], [12, 18], [12, 19], [12, 20], [13, 14], [13, 16], [13, 18], [13, 19], [13, 20], [13, 22], [13, 23], [14, 15], [14, 17], [14, 19], [14, 23], [15, 16], [15, 17], [15, 18], [15, 19], [16, 17], [16, 18], [16, 19], [16, 20], [16, 21], [16, 22], [16, 23], [17, 18], [17, 19], [17, 20], [17, 21], [17, 23], [18, 19], [18, 23], [19, 20], [19, 21], [19, 22], [20, 21], [20, 22], [21, 23]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l3-s2/tests/run.py b/tasks/construct-nppc-vertex-cover-l3-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l3-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-nppc-vertex-cover-l3-s2/tests/test.sh b/tasks/construct-nppc-vertex-cover-l3-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l3-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-graph-color-l4-s8/environment/Dockerfile b/tasks/construct-rg-graph-color-l4-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-graph-color-l4-s8/environment/instance.json b/tasks/construct-rg-graph-color-l4-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ad4fb9b83aa0dc7bd6b6725cc0755f4a040e9bbc --- /dev/null +++ b/tasks/construct-rg-graph-color-l4-s8/environment/instance.json @@ -0,0 +1 @@ +{"num_vertices": 20, "num_colors": 3, "edges": [[0, 1], [0, 3], [0, 8], [1, 3], [1, 7], [2, 6], [2, 12], [2, 13], [3, 16], [4, 6], [4, 8], [4, 16], [5, 12], [5, 13], [5, 15], [6, 19], [7, 11], [7, 16], [8, 9], [9, 10], [9, 11], [9, 18], [11, 12], [12, 14], [13, 19], [14, 15], [18, 19]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l4-s8/solution/solve.sh b/tasks/construct-rg-graph-color-l4-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8b364dc73e8931b8156f3ea69640852cae2c8217 --- /dev/null +++ b/tasks/construct-rg-graph-color-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' +{"coloring": [1, 2, 1, 3, 1, 1, 2, 1, 2, 1, 2, 2, 3, 2, 1, 2, 2, 1, 2, 1]} +RLMATH_EOF diff --git a/tasks/construct-rg-graph-color-l4-s8/tests/check.py b/tasks/construct-rg-graph-color-l4-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e9328912405d1c894970c90415be62bf9556ed36 --- /dev/null +++ b/tasks/construct-rg-graph-color-l4-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-l4-s8/tests/instance.json b/tasks/construct-rg-graph-color-l4-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ad4fb9b83aa0dc7bd6b6725cc0755f4a040e9bbc --- /dev/null +++ b/tasks/construct-rg-graph-color-l4-s8/tests/instance.json @@ -0,0 +1 @@ +{"num_vertices": 20, "num_colors": 3, "edges": [[0, 1], [0, 3], [0, 8], [1, 3], [1, 7], [2, 6], [2, 12], [2, 13], [3, 16], [4, 6], [4, 8], [4, 16], [5, 12], [5, 13], [5, 15], [6, 19], [7, 11], [7, 16], [8, 9], [9, 10], [9, 11], [9, 18], [11, 12], [12, 14], [13, 19], [14, 15], [18, 19]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l4-s8/tests/run.py b/tasks/construct-rg-graph-color-l4-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-graph-color-l4-s8/tests/test.sh b/tasks/construct-rg-graph-color-l4-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-intermediate-integration-l6-s3/environment/Dockerfile b/tasks/construct-rg-intermediate-integration-l6-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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-rg-intermediate-integration-l6-s3/environment/instance.json b/tasks/construct-rg-intermediate-integration-l6-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a5abf01afaa6fd8fce5a040e46cbaea7be4b1a7a --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l6-s3/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "3*x**4*cos(x)", "problem_type": "repeated_parts", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l6-s3/solution/solve.sh b/tasks/construct-rg-intermediate-integration-l6-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a7f060471dd7742615ad321ab5ec21486fb4f479 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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' +{"antiderivative": "3*x**4*sin(x) + 12*x**3*cos(x) - 36*x**2*sin(x) - 72*x*cos(x) + 72*sin(x) + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-intermediate-integration-l6-s3/tests/check.py b/tasks/construct-rg-intermediate-integration-l6-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l6-s3/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-l6-s3/tests/instance.json b/tasks/construct-rg-intermediate-integration-l6-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a5abf01afaa6fd8fce5a040e46cbaea7be4b1a7a --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l6-s3/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "3*x**4*cos(x)", "problem_type": "repeated_parts", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l6-s3/tests/run.py b/tasks/construct-rg-intermediate-integration-l6-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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-rg-intermediate-integration-l6-s3/tests/test.sh b/tasks/construct-rg-intermediate-integration-l6-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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-rg-intermediate-integration-l6-s4/environment/Dockerfile b/tasks/construct-rg-intermediate-integration-l6-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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-rg-intermediate-integration-l6-s4/environment/instance.json b/tasks/construct-rg-intermediate-integration-l6-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d25fd3231829270005cc8b7db2108addc064ac66 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l6-s4/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "x**5*exp(x)", "problem_type": "repeated_parts", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l6-s4/solution/solve.sh b/tasks/construct-rg-intermediate-integration-l6-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d1fb86ca431181807f31af64326a8298e150fe43 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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' +{"antiderivative": "(x**5 - 5*x**4 + 20*x**3 - 60*x**2 + 120*x - 120)*exp(x) + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-intermediate-integration-l6-s4/tests/check.py b/tasks/construct-rg-intermediate-integration-l6-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l6-s4/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-l6-s4/tests/instance.json b/tasks/construct-rg-intermediate-integration-l6-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d25fd3231829270005cc8b7db2108addc064ac66 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l6-s4/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "x**5*exp(x)", "problem_type": "repeated_parts", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l6-s4/tests/run.py b/tasks/construct-rg-intermediate-integration-l6-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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-rg-intermediate-integration-l6-s4/tests/test.sh b/tasks/construct-rg-intermediate-integration-l6-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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-rg-simple-integration-l4-s7/environment/Dockerfile b/tasks/construct-rg-simple-integration-l4-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l4-s7/solution/solve.sh b/tasks/construct-rg-simple-integration-l4-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9751da5624c40358627a8ae57414ddc5344e2d9d --- /dev/null +++ b/tasks/construct-rg-simple-integration-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' +{"antiderivative": "5*x**9/2 - x**8 - 4*x**7 - x**5/3 - 9*x**2 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-simple-integration-l4-s7/tests/check.py b/tasks/construct-rg-simple-integration-l4-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l4-s7/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-l4-s7/tests/instance.json b/tasks/construct-rg-simple-integration-l4-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..08001f34f7d6f4f17df17614a3564fcba6589e07 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l4-s7/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "45*x**8/2 - 8*x**7 - 28*x**6 - 5*x**4/3 - 18*x", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l4-s7/tests/run.py b/tasks/construct-rg-simple-integration-l4-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l4-s7/tests/test.sh b/tasks/construct-rg-simple-integration-l4-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l4-s9/environment/Dockerfile b/tasks/construct-rg-simple-integration-l4-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l4-s9/environment/instance.json b/tasks/construct-rg-simple-integration-l4-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..98d3b6a99381f39176bbc69d49092a45dce40ec8 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l4-s9/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "7*x**6 + 15*x**4 - 78*x**2/5", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l4-s9/solution/solve.sh b/tasks/construct-rg-simple-integration-l4-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..11c9d4ae7771d5cf35e4181d3c2f1d641bcf7784 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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' +{"antiderivative": "x**7 + 3*x**5 - 26*x**3/5 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-simple-integration-l4-s9/tests/check.py b/tasks/construct-rg-simple-integration-l4-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l4-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-l4-s9/tests/instance.json b/tasks/construct-rg-simple-integration-l4-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..98d3b6a99381f39176bbc69d49092a45dce40ec8 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l4-s9/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "7*x**6 + 15*x**4 - 78*x**2/5", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l4-s9/tests/run.py b/tasks/construct-rg-simple-integration-l4-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l4-s9/tests/test.sh b/tasks/construct-rg-simple-integration-l4-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-antiderivative-l1-s8/environment/Dockerfile b/tasks/construct-rlve-antiderivative-l1-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l1-s8/environment/instance.json b/tasks/construct-rlve-antiderivative-l1-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cb9cae285ca6910c9a9f3a48625e1fccecbfd4ef --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l1-s8/environment/instance.json @@ -0,0 +1 @@ +{"f_prime": "cos(x)/(4*sin(x)**(3/4))", "max_ops": 32, "max_len": 660, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l1-s8/solution/solve.sh b/tasks/construct-rlve-antiderivative-l1-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7c3a1853041665d9676d8a44cf293d84771c0ca6 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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' +{"F": "sin(x)**(1/4)"} +RLMATH_EOF diff --git a/tasks/construct-rlve-antiderivative-l1-s8/tests/check.py b/tasks/construct-rlve-antiderivative-l1-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c6b30b93bbbb7795b54d973e43f25b23c82cb7fc --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l1-s8/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-l1-s8/tests/instance.json b/tasks/construct-rlve-antiderivative-l1-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cb9cae285ca6910c9a9f3a48625e1fccecbfd4ef --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l1-s8/tests/instance.json @@ -0,0 +1 @@ +{"f_prime": "cos(x)/(4*sin(x)**(3/4))", "max_ops": 32, "max_len": 660, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l1-s8/tests/run.py b/tasks/construct-rlve-antiderivative-l1-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l1-s8/tests/test.sh b/tasks/construct-rlve-antiderivative-l1-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l5-s0/environment/Dockerfile b/tasks/construct-rlve-antiderivative-l5-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l5-s0/environment/instance.json b/tasks/construct-rlve-antiderivative-l5-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c6f2d7440783094bc3c2e290d6af36c998d6de98 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l5-s0/environment/instance.json @@ -0,0 +1 @@ +{"f_prime": "x*cos(x)/(2*sin(x)) + x**sin(x)*(log(x)*cos(x) + sin(x)/x)/2 + log(sin(x))/2", "max_ops": 52, "max_len": 980, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l5-s0/solution/solve.sh b/tasks/construct-rlve-antiderivative-l5-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0008714cefd8fbfbdf1dee7870193f89b9fc8124 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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' +{"F": "x*log(sin(x))/2 + x**sin(x)/2"} +RLMATH_EOF diff --git a/tasks/construct-rlve-antiderivative-l5-s0/tests/check.py b/tasks/construct-rlve-antiderivative-l5-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c6b30b93bbbb7795b54d973e43f25b23c82cb7fc --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l5-s0/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-l5-s0/tests/instance.json b/tasks/construct-rlve-antiderivative-l5-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c6f2d7440783094bc3c2e290d6af36c998d6de98 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l5-s0/tests/instance.json @@ -0,0 +1 @@ +{"f_prime": "x*cos(x)/(2*sin(x)) + x**sin(x)*(log(x)*cos(x) + sin(x)/x)/2 + log(sin(x))/2", "max_ops": 52, "max_len": 980, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l5-s0/tests/run.py b/tasks/construct-rlve-antiderivative-l5-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l5-s0/tests/test.sh b/tasks/construct-rlve-antiderivative-l5-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l5-s7/environment/Dockerfile b/tasks/construct-rlve-antiderivative-l5-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-rlve-antiderivative-l5-s7/environment/instance.json b/tasks/construct-rlve-antiderivative-l5-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..66dd89b4e95bb832842d7ee454354bdbd60b89f9 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l5-s7/environment/instance.json @@ -0,0 +1 @@ +{"f_prime": "-3*x*(4*x*cos(x)/3 + 4*sin(x)/3)*sin(4*x*sin(x)/3)*cos(4*x*sin(x)/3)**2 + cos(4*x*sin(x)/3)**3", "max_ops": 48, "max_len": 840, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l5-s7/solution/solve.sh b/tasks/construct-rlve-antiderivative-l5-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..10de89aa7fd2a2ee892cd87f6502057f7f3ba40c --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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' +{"F": "x*cos(4*x*sin(x)/3)**3"} +RLMATH_EOF diff --git a/tasks/construct-rlve-antiderivative-l5-s7/tests/check.py b/tasks/construct-rlve-antiderivative-l5-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c6b30b93bbbb7795b54d973e43f25b23c82cb7fc --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l5-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-l5-s7/tests/instance.json b/tasks/construct-rlve-antiderivative-l5-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..66dd89b4e95bb832842d7ee454354bdbd60b89f9 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l5-s7/tests/instance.json @@ -0,0 +1 @@ +{"f_prime": "-3*x*(4*x*cos(x)/3 + 4*sin(x)/3)*sin(4*x*sin(x)/3)*cos(4*x*sin(x)/3)**2 + cos(4*x*sin(x)/3)**3", "max_ops": 48, "max_len": 840, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l5-s7/tests/run.py b/tasks/construct-rlve-antiderivative-l5-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-rlve-antiderivative-l5-s7/tests/test.sh b/tasks/construct-rlve-antiderivative-l5-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-rlve-construct-hack-interval-l2-s1/environment/Dockerfile b/tasks/construct-rlve-construct-hack-interval-l2-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-construct-hack-interval-l2-s1/environment/instance.json b/tasks/construct-rlve-construct-hack-interval-l2-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..390844f9e681077d3c6837faefa767613049164c --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l2-s1/environment/instance.json @@ -0,0 +1 @@ +{"mod": 799, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l2-s1/solution/solve.sh b/tasks/construct-rlve-construct-hack-interval-l2-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..36b5682c4bb83ecc40089d8d9e77ad8403e66b83 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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' +{"L": 7, "R": 94} +RLMATH_EOF diff --git a/tasks/construct-rlve-construct-hack-interval-l2-s1/tests/check.py b/tasks/construct-rlve-construct-hack-interval-l2-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..34b46e9758e3a50ed16c9c2a29cfc0abe663926b --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l2-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-l2-s1/tests/instance.json b/tasks/construct-rlve-construct-hack-interval-l2-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..390844f9e681077d3c6837faefa767613049164c --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l2-s1/tests/instance.json @@ -0,0 +1 @@ +{"mod": 799, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l2-s1/tests/run.py b/tasks/construct-rlve-construct-hack-interval-l2-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-construct-hack-interval-l2-s1/tests/test.sh b/tasks/construct-rlve-construct-hack-interval-l2-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-construct-hack-interval-l2-s6/environment/Dockerfile b/tasks/construct-rlve-construct-hack-interval-l2-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-rlve-construct-hack-interval-l2-s6/environment/instance.json b/tasks/construct-rlve-construct-hack-interval-l2-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..524cd98db6a14e556dfdc4f9b15bc01d66eafe9b --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l2-s6/environment/instance.json @@ -0,0 +1 @@ +{"mod": 4557, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l2-s6/solution/solve.sh b/tasks/construct-rlve-construct-hack-interval-l2-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..18a2dd2eb4386ebd95bae446a40c5c231c0d8b81 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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' +{"L": 13, "R": 440} +RLMATH_EOF diff --git a/tasks/construct-rlve-construct-hack-interval-l2-s6/tests/check.py b/tasks/construct-rlve-construct-hack-interval-l2-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..34b46e9758e3a50ed16c9c2a29cfc0abe663926b --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l2-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-l2-s6/tests/instance.json b/tasks/construct-rlve-construct-hack-interval-l2-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..524cd98db6a14e556dfdc4f9b15bc01d66eafe9b --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l2-s6/tests/instance.json @@ -0,0 +1 @@ +{"mod": 4557, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l2-s6/tests/run.py b/tasks/construct-rlve-construct-hack-interval-l2-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-rlve-construct-hack-interval-l2-s6/tests/test.sh b/tasks/construct-rlve-construct-hack-interval-l2-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-rlve-construct-hack-interval-l6-s9/environment/Dockerfile b/tasks/construct-rlve-construct-hack-interval-l6-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l6-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-construct-hack-interval-l6-s9/environment/instance.json b/tasks/construct-rlve-construct-hack-interval-l6-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..dcb5ac3bf4fc4ab2413a41f0d9eb25d01ad8e8cb --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l6-s9/environment/instance.json @@ -0,0 +1 @@ +{"mod": 989253892299807826, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l6-s9/solution/solve.sh b/tasks/construct-rlve-construct-hack-interval-l6-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a5e960b7d2bf264dc670e98dc7c511a06766a6fa --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l6-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' +{"L": 264031138398462608, "R": 364031138398462607} +RLMATH_EOF diff --git a/tasks/construct-rlve-construct-hack-interval-l6-s9/tests/check.py b/tasks/construct-rlve-construct-hack-interval-l6-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..34b46e9758e3a50ed16c9c2a29cfc0abe663926b --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l6-s9/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-l6-s9/tests/instance.json b/tasks/construct-rlve-construct-hack-interval-l6-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..dcb5ac3bf4fc4ab2413a41f0d9eb25d01ad8e8cb --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l6-s9/tests/instance.json @@ -0,0 +1 @@ +{"mod": 989253892299807826, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l6-s9/tests/run.py b/tasks/construct-rlve-construct-hack-interval-l6-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l6-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-construct-hack-interval-l6-s9/tests/test.sh b/tasks/construct-rlve-construct-hack-interval-l6-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l6-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-crt-l3-s9/environment/Dockerfile b/tasks/construct-rlve-crt-l3-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-crt-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-rlve-crt-l3-s9/environment/instance.json b/tasks/construct-rlve-crt-l3-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7ab9eaea99b705cbdc4234bb43d5a64f3d995d85 --- /dev/null +++ b/tasks/construct-rlve-crt-l3-s9/environment/instance.json @@ -0,0 +1 @@ +{"moduli": [40, 179, 131, 120], "residues": [34, 15, 63, 74], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l3-s9/solution/solve.sh b/tasks/construct-rlve-crt-l3-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a06c0568525b42c4c0296cee1c8af77d63469178 --- /dev/null +++ b/tasks/construct-rlve-crt-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' +{"x": 194} +RLMATH_EOF diff --git a/tasks/construct-rlve-crt-l3-s9/tests/check.py b/tasks/construct-rlve-crt-l3-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..886d95606ef325930b24794c0959c2ba7b254ebd --- /dev/null +++ b/tasks/construct-rlve-crt-l3-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-l3-s9/tests/instance.json b/tasks/construct-rlve-crt-l3-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7ab9eaea99b705cbdc4234bb43d5a64f3d995d85 --- /dev/null +++ b/tasks/construct-rlve-crt-l3-s9/tests/instance.json @@ -0,0 +1 @@ +{"moduli": [40, 179, 131, 120], "residues": [34, 15, 63, 74], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l3-s9/tests/run.py b/tasks/construct-rlve-crt-l3-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-crt-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-rlve-crt-l3-s9/tests/test.sh b/tasks/construct-rlve-crt-l3-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-crt-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-rlve-distinct-subset-sum-permutation-l2-s9/environment/Dockerfile b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-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-distinct-subset-sum-permutation-l2-s9/environment/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2a788d71a1cc20f23277f451d8179f2ab98ffd2a --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s9/environment/instance.json @@ -0,0 +1 @@ +{"A": [7, 13, 2, 6, 1, 3, 10], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s9/solution/solve.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f0cfe555522939fdbac03d87bc6c0eec2948f8fe --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-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' +{"B": [10, 1, 3, 7, 2, 6, 13]} +RLMATH_EOF diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s9/tests/check.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..06bbbcf872c2fca05785f40fdfdcf85a5e5a0e7c --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-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-l2-s9/tests/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2a788d71a1cc20f23277f451d8179f2ab98ffd2a --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s9/tests/instance.json @@ -0,0 +1 @@ +{"A": [7, 13, 2, 6, 1, 3, 10], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s9/tests/run.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-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-distinct-subset-sum-permutation-l2-s9/tests/test.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-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-distinct-subset-sum-permutation-l6-s1/environment/Dockerfile b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-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-distinct-subset-sum-permutation-l6-s1/environment/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b92e30dc195477e84bc9e92a5d1c49fe2300439c --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s1/environment/instance.json @@ -0,0 +1 @@ +{"A": [33, 0, 9, 12, 20, 25, 41, 31, 5, 7, 42, 13, 3, 22, 35, 26, 17, 4, 15, 1, 30, 38], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s1/solution/solve.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f7f488eface576c1296fcedd7d52f1d59f178d45 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-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' +{"B": [35, 1, 12, 13, 22, 26, 42, 33, 7, 9, 0, 15, 4, 25, 38, 30, 20, 5, 17, 3, 31, 41]} +RLMATH_EOF diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s1/tests/check.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..06bbbcf872c2fca05785f40fdfdcf85a5e5a0e7c --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s1/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-l6-s1/tests/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b92e30dc195477e84bc9e92a5d1c49fe2300439c --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s1/tests/instance.json @@ -0,0 +1 @@ +{"A": [33, 0, 9, 12, 20, 25, 41, 31, 5, 7, 42, 13, 3, 22, 35, 26, 17, 4, 15, 1, 30, 38], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s1/tests/run.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-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-distinct-subset-sum-permutation-l6-s1/tests/test.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-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-distinct-subset-sum-permutation-l6-s6/environment/Dockerfile b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-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-distinct-subset-sum-permutation-l6-s6/environment/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b203cb716f7e239ae6a59580071a31aa1509578e --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s6/environment/instance.json @@ -0,0 +1 @@ +{"A": [34, 30, 3, 25, 35, 14, 39, 11, 15, 9, 1, 16, 17, 5, 0, 21, 23, 32, 43, 36, 40, 7], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s6/solution/solve.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..33f8f9b4549c798bfccd8e2c36cb7327df23835a --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-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' +{"B": [35, 32, 5, 30, 36, 15, 40, 14, 16, 11, 3, 17, 21, 7, 1, 23, 25, 34, 0, 39, 43, 9]} +RLMATH_EOF diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s6/tests/check.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..06bbbcf872c2fca05785f40fdfdcf85a5e5a0e7c --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s6/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-l6-s6/tests/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b203cb716f7e239ae6a59580071a31aa1509578e --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s6/tests/instance.json @@ -0,0 +1 @@ +{"A": [34, 30, 3, 25, 35, 14, 39, 11, 15, 9, 1, 16, 17, 5, 0, 21, 23, 32, 43, 36, 40, 7], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s6/tests/run.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-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-distinct-subset-sum-permutation-l6-s6/tests/test.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-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-even-degree-partition-l3-s0/environment/Dockerfile b/tasks/construct-rlve-even-degree-partition-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-rlve-even-degree-partition-l3-s0/environment/instance.json b/tasks/construct-rlve-even-degree-partition-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f7c3f2491a3bae8af26f16c59f41eda7d9a75b90 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 12, "edges": [[0, 1], [0, 5], [0, 6], [0, 8], [0, 9], [0, 11], [1, 2], [1, 3], [1, 5], [1, 6], [1, 10], [2, 5], [2, 7], [2, 8], [2, 9], [3, 4], [3, 5], [3, 7], [3, 9], [4, 10], [5, 6], [5, 9], [6, 7], [6, 9], [7, 8], [7, 9], [8, 9]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l3-s0/solution/solve.sh b/tasks/construct-rlve-even-degree-partition-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..04d013ea2bc103e2a3192b82f72c53755edb555f --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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' +{"groups": [1, 2, 1, 2, 2, 1, 1, 1, 1, 1, 2, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-even-degree-partition-l3-s0/tests/check.py b/tasks/construct-rlve-even-degree-partition-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9c7f0f71ea6d10264ececcc933b97a4a0e6eaf8e --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l3-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-l3-s0/tests/instance.json b/tasks/construct-rlve-even-degree-partition-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f7c3f2491a3bae8af26f16c59f41eda7d9a75b90 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 12, "edges": [[0, 1], [0, 5], [0, 6], [0, 8], [0, 9], [0, 11], [1, 2], [1, 3], [1, 5], [1, 6], [1, 10], [2, 5], [2, 7], [2, 8], [2, 9], [3, 4], [3, 5], [3, 7], [3, 9], [4, 10], [5, 6], [5, 9], [6, 7], [6, 9], [7, 8], [7, 9], [8, 9]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l3-s0/tests/run.py b/tasks/construct-rlve-even-degree-partition-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-rlve-even-degree-partition-l3-s0/tests/test.sh b/tasks/construct-rlve-even-degree-partition-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-rlve-even-degree-partition-l3-s7/environment/Dockerfile b/tasks/construct-rlve-even-degree-partition-l3-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-even-degree-partition-l3-s7/environment/instance.json b/tasks/construct-rlve-even-degree-partition-l3-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..720e8fe5b464da5de8eda1c0d4fce1700f6e1937 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l3-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 12, "edges": [[0, 1], [0, 2], [0, 4], [0, 6], [0, 7], [0, 10], [1, 2], [1, 6], [1, 7], [1, 10], [1, 11], [2, 3], [2, 4], [2, 7], [2, 10], [3, 4], [3, 6], [3, 10], [4, 9], [4, 10], [4, 11], [6, 10], [7, 9], [8, 10], [9, 10], [9, 11], [10, 11]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l3-s7/solution/solve.sh b/tasks/construct-rlve-even-degree-partition-l3-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8f02deff20c5839bf9b4a569ebf2b0752d097421 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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' +{"groups": [1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-even-degree-partition-l3-s7/tests/check.py b/tasks/construct-rlve-even-degree-partition-l3-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9c7f0f71ea6d10264ececcc933b97a4a0e6eaf8e --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l3-s7/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-l3-s7/tests/instance.json b/tasks/construct-rlve-even-degree-partition-l3-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..720e8fe5b464da5de8eda1c0d4fce1700f6e1937 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l3-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 12, "edges": [[0, 1], [0, 2], [0, 4], [0, 6], [0, 7], [0, 10], [1, 2], [1, 6], [1, 7], [1, 10], [1, 11], [2, 3], [2, 4], [2, 7], [2, 10], [3, 4], [3, 6], [3, 10], [4, 9], [4, 10], [4, 11], [6, 10], [7, 9], [8, 10], [9, 10], [9, 11], [10, 11]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l3-s7/tests/run.py b/tasks/construct-rlve-even-degree-partition-l3-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-even-degree-partition-l3-s7/tests/test.sh b/tasks/construct-rlve-even-degree-partition-l3-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-graph-isomorphism-l1-s2/environment/Dockerfile b/tasks/construct-rlve-graph-isomorphism-l1-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l1-s2/environment/instance.json b/tasks/construct-rlve-graph-isomorphism-l1-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3d5b045b992f3bf5da3ff080b230337d104f29aa --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l1-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 5, "edges1": [[2, 3], [0, 1], [0, 4], [1, 4], [0, 2]], "edges2": [[1, 3], [2, 3], [2, 4], [0, 2], [0, 4]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l1-s2/solution/solve.sh b/tasks/construct-rlve-graph-isomorphism-l1-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2f6cd755cada0c237cd078ac4190e481948d195 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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' +{"p": [2, 0, 3, 1, 4]} +RLMATH_EOF diff --git a/tasks/construct-rlve-graph-isomorphism-l1-s2/tests/check.py b/tasks/construct-rlve-graph-isomorphism-l1-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..64b755f5ab12e7270811ccfc2f02d104715517b7 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l1-s2/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-l1-s2/tests/instance.json b/tasks/construct-rlve-graph-isomorphism-l1-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3d5b045b992f3bf5da3ff080b230337d104f29aa --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l1-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 5, "edges1": [[2, 3], [0, 1], [0, 4], [1, 4], [0, 2]], "edges2": [[1, 3], [2, 3], [2, 4], [0, 2], [0, 4]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l1-s2/tests/run.py b/tasks/construct-rlve-graph-isomorphism-l1-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l1-s2/tests/test.sh b/tasks/construct-rlve-graph-isomorphism-l1-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l1-s5/environment/Dockerfile b/tasks/construct-rlve-graph-isomorphism-l1-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l1-s5/environment/instance.json b/tasks/construct-rlve-graph-isomorphism-l1-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..33e84a3cc81dd2c867a80d609259f2e89343a943 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l1-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 5, "edges1": [[1, 2], [0, 2], [0, 1], [3, 4], [1, 4], [0, 4], [1, 3]], "edges2": [[1, 2], [0, 3], [2, 3], [0, 4], [1, 4], [1, 3], [0, 1]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l1-s5/solution/solve.sh b/tasks/construct-rlve-graph-isomorphism-l1-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..73416db4e7a7f0718be117d1f09d3d0420c7814d --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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' +{"p": [0, 1, 4, 2, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-graph-isomorphism-l1-s5/tests/check.py b/tasks/construct-rlve-graph-isomorphism-l1-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..64b755f5ab12e7270811ccfc2f02d104715517b7 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l1-s5/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-l1-s5/tests/instance.json b/tasks/construct-rlve-graph-isomorphism-l1-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..33e84a3cc81dd2c867a80d609259f2e89343a943 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l1-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 5, "edges1": [[1, 2], [0, 2], [0, 1], [3, 4], [1, 4], [0, 4], [1, 3]], "edges2": [[1, 2], [0, 3], [2, 3], [0, 4], [1, 4], [1, 3], [0, 1]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l1-s5/tests/run.py b/tasks/construct-rlve-graph-isomorphism-l1-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l1-s5/tests/test.sh b/tasks/construct-rlve-graph-isomorphism-l1-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-grid-parity-construction-l1-s2/environment/Dockerfile b/tasks/construct-rlve-grid-parity-construction-l1-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l1-s2/environment/instance.json b/tasks/construct-rlve-grid-parity-construction-l1-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b5481519c8fd7e5bb0a41c660657e79daab6ec57 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l1-s2/environment/instance.json @@ -0,0 +1 @@ +{"parity": ["00", "00"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l1-s2/solution/solve.sh b/tasks/construct-rlve-grid-parity-construction-l1-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9e7e9b1b64561ddc6e4ead3502eb29e07a67c2a6 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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' +{"grid": ["00", "00"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-grid-parity-construction-l1-s2/tests/check.py b/tasks/construct-rlve-grid-parity-construction-l1-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..89d5d286593348d0000ac10db74e1c6242be6c97 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l1-s2/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-l1-s2/tests/instance.json b/tasks/construct-rlve-grid-parity-construction-l1-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b5481519c8fd7e5bb0a41c660657e79daab6ec57 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l1-s2/tests/instance.json @@ -0,0 +1 @@ +{"parity": ["00", "00"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l1-s2/tests/run.py b/tasks/construct-rlve-grid-parity-construction-l1-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l1-s2/tests/test.sh b/tasks/construct-rlve-grid-parity-construction-l1-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l1-s5/environment/Dockerfile b/tasks/construct-rlve-grid-parity-construction-l1-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l1-s5/environment/instance.json b/tasks/construct-rlve-grid-parity-construction-l1-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3f8e340ef2b1cc3be0395fe07dba9cc2df394126 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l1-s5/environment/instance.json @@ -0,0 +1 @@ +{"parity": ["010", "001", "010"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l1-s5/solution/solve.sh b/tasks/construct-rlve-grid-parity-construction-l1-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..619c9fb1181f15547703cf875671741136421d47 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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' +{"grid": ["011", "110", "011"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-grid-parity-construction-l1-s5/tests/check.py b/tasks/construct-rlve-grid-parity-construction-l1-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..89d5d286593348d0000ac10db74e1c6242be6c97 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l1-s5/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-l1-s5/tests/instance.json b/tasks/construct-rlve-grid-parity-construction-l1-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3f8e340ef2b1cc3be0395fe07dba9cc2df394126 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l1-s5/tests/instance.json @@ -0,0 +1 @@ +{"parity": ["010", "001", "010"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l1-s5/tests/run.py b/tasks/construct-rlve-grid-parity-construction-l1-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l1-s5/tests/test.sh b/tasks/construct-rlve-grid-parity-construction-l1-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-l3-s3/environment/Dockerfile b/tasks/construct-rlve-imp-party-l3-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l3-s3/environment/instance.json b/tasks/construct-rlve-imp-party-l3-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9f23cc3098e92c64acddc9381ec1b90eee4da451 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l3-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "edges": [[0, 1], [0, 2], [0, 5], [0, 7], [0, 8], [0, 13], [0, 14], [0, 16], [0, 17], [0, 18], [0, 20], [0, 21], [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, 23], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 10], [2, 11], [2, 13], [2, 14], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [2, 21], [2, 23], [3, 4], [3, 5], [3, 7], [3, 8], [3, 10], [3, 13], [3, 14], [3, 17], [3, 19], [3, 20], [3, 23], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 12], [4, 13], [4, 14], [4, 16], [4, 17], [4, 18], [4, 19], [4, 20], [4, 21], [4, 23], [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], [5, 21], [5, 22], [5, 23], [6, 7], [6, 8], [6, 10], [6, 13], [6, 14], [6, 16], [6, 18], [6, 19], [6, 20], [6, 21], [7, 8], [7, 9], [7, 10], [7, 12], [7, 13], [7, 14], [7, 16], [7, 17], [7, 18], [7, 19], [7, 20], [7, 21], [7, 23], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [8, 14], [8, 15], [8, 16], [8, 17], [8, 18], [8, 19], [8, 20], [8, 21], [8, 22], [8, 23], [9, 10], [9, 14], [9, 20], [9, 21], [9, 23], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [10, 16], [10, 17], [10, 18], [10, 19], [10, 20], [10, 21], [10, 22], [10, 23], [11, 13], [11, 14], [11, 17], [11, 18], [12, 14], [12, 16], [12, 17], [12, 19], [13, 14], [13, 15], [13, 16], [13, 17], [13, 18], [13, 19], [13, 20], [13, 21], [13, 22], [13, 23], [14, 15], [14, 16], [14, 17], [14, 18], [14, 19], [14, 20], [14, 21], [14, 22], [14, 23], [15, 16], [15, 18], [15, 19], [15, 20], [15, 21], [15, 23], [16, 17], [16, 18], [16, 19], [16, 20], [16, 21], [16, 23], [17, 18], [17, 19], [17, 20], [17, 21], [17, 22], [17, 23], [18, 19], [18, 20], [18, 21], [18, 22], [18, 23], [19, 20], [19, 21], [19, 23], [20, 21], [20, 23], [21, 23]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l3-s3/solution/solve.sh b/tasks/construct-rlve-imp-party-l3-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6232cf94f2e9149d08305d6379b1e2d377528910 --- /dev/null +++ b/tasks/construct-rlve-imp-party-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' +{"clique": [1, 7, 8, 13, 14, 17, 18, 23]} +RLMATH_EOF diff --git a/tasks/construct-rlve-imp-party-l3-s3/tests/check.py b/tasks/construct-rlve-imp-party-l3-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..97b5a037a2ba8bf4495cf87cc074d1c60b11311c --- /dev/null +++ b/tasks/construct-rlve-imp-party-l3-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-l3-s3/tests/instance.json b/tasks/construct-rlve-imp-party-l3-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9f23cc3098e92c64acddc9381ec1b90eee4da451 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l3-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "edges": [[0, 1], [0, 2], [0, 5], [0, 7], [0, 8], [0, 13], [0, 14], [0, 16], [0, 17], [0, 18], [0, 20], [0, 21], [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, 23], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 10], [2, 11], [2, 13], [2, 14], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [2, 21], [2, 23], [3, 4], [3, 5], [3, 7], [3, 8], [3, 10], [3, 13], [3, 14], [3, 17], [3, 19], [3, 20], [3, 23], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 12], [4, 13], [4, 14], [4, 16], [4, 17], [4, 18], [4, 19], [4, 20], [4, 21], [4, 23], [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], [5, 21], [5, 22], [5, 23], [6, 7], [6, 8], [6, 10], [6, 13], [6, 14], [6, 16], [6, 18], [6, 19], [6, 20], [6, 21], [7, 8], [7, 9], [7, 10], [7, 12], [7, 13], [7, 14], [7, 16], [7, 17], [7, 18], [7, 19], [7, 20], [7, 21], [7, 23], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [8, 14], [8, 15], [8, 16], [8, 17], [8, 18], [8, 19], [8, 20], [8, 21], [8, 22], [8, 23], [9, 10], [9, 14], [9, 20], [9, 21], [9, 23], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [10, 16], [10, 17], [10, 18], [10, 19], [10, 20], [10, 21], [10, 22], [10, 23], [11, 13], [11, 14], [11, 17], [11, 18], [12, 14], [12, 16], [12, 17], [12, 19], [13, 14], [13, 15], [13, 16], [13, 17], [13, 18], [13, 19], [13, 20], [13, 21], [13, 22], [13, 23], [14, 15], [14, 16], [14, 17], [14, 18], [14, 19], [14, 20], [14, 21], [14, 22], [14, 23], [15, 16], [15, 18], [15, 19], [15, 20], [15, 21], [15, 23], [16, 17], [16, 18], [16, 19], [16, 20], [16, 21], [16, 23], [17, 18], [17, 19], [17, 20], [17, 21], [17, 22], [17, 23], [18, 19], [18, 20], [18, 21], [18, 22], [18, 23], [19, 20], [19, 21], [19, 23], [20, 21], [20, 23], [21, 23]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l3-s3/tests/run.py b/tasks/construct-rlve-imp-party-l3-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l3-s3/tests/test.sh b/tasks/construct-rlve-imp-party-l3-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l3-s4/environment/Dockerfile b/tasks/construct-rlve-imp-party-l3-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l3-s4/environment/instance.json b/tasks/construct-rlve-imp-party-l3-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d06fae6f1e95c2a7a626d2b735835154f0f2c373 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l3-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "edges": [[0, 6], [1, 2], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 12], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 18], [1, 20], [1, 22], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 12], [2, 13], [2, 14], [2, 15], [2, 16], [2, 17], [2, 18], [2, 20], [2, 22], [3, 5], [3, 17], [4, 8], [4, 16], [4, 20], [5, 6], [5, 7], [5, 8], [5, 9], [5, 12], [5, 13], [5, 14], [5, 15], [5, 16], [5, 17], [5, 18], [5, 20], [5, 22], [5, 23], [6, 7], [6, 8], [6, 9], [6, 12], [6, 13], [6, 14], [6, 15], [6, 16], [6, 17], [6, 18], [6, 20], [6, 22], [7, 8], [7, 9], [7, 12], [7, 13], [7, 14], [7, 15], [7, 16], [7, 17], [7, 18], [7, 19], [7, 20], [7, 22], [7, 23], [8, 9], [8, 12], [8, 13], [8, 14], [8, 15], [8, 16], [8, 17], [8, 18], [8, 20], [8, 21], [8, 22], [9, 12], [9, 13], [9, 14], [9, 15], [9, 16], [9, 17], [9, 18], [9, 20], [9, 22], [10, 15], [10, 17], [11, 13], [11, 15], [11, 22], [12, 13], [12, 14], [12, 15], [12, 16], [12, 17], [12, 18], [12, 20], [12, 22], [13, 14], [13, 15], [13, 16], [13, 17], [13, 18], [13, 19], [13, 20], [13, 22], [14, 15], [14, 16], [14, 17], [14, 18], [14, 20], [14, 22], [14, 23], [15, 16], [15, 17], [15, 18], [15, 19], [15, 20], [15, 21], [15, 22], [16, 17], [16, 18], [16, 20], [16, 22], [17, 18], [17, 20], [17, 22], [17, 23], [18, 20], [18, 22], [19, 22], [20, 21], [20, 22], [22, 23]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l3-s4/solution/solve.sh b/tasks/construct-rlve-imp-party-l3-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..91c37e2e7b1fe401ee927bba0f46643bebd736d5 --- /dev/null +++ b/tasks/construct-rlve-imp-party-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' +{"clique": [1, 2, 5, 6, 7, 9, 12, 16]} +RLMATH_EOF diff --git a/tasks/construct-rlve-imp-party-l3-s4/tests/check.py b/tasks/construct-rlve-imp-party-l3-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..97b5a037a2ba8bf4495cf87cc074d1c60b11311c --- /dev/null +++ b/tasks/construct-rlve-imp-party-l3-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-l3-s4/tests/instance.json b/tasks/construct-rlve-imp-party-l3-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d06fae6f1e95c2a7a626d2b735835154f0f2c373 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l3-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "edges": [[0, 6], [1, 2], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 12], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 18], [1, 20], [1, 22], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 12], [2, 13], [2, 14], [2, 15], [2, 16], [2, 17], [2, 18], [2, 20], [2, 22], [3, 5], [3, 17], [4, 8], [4, 16], [4, 20], [5, 6], [5, 7], [5, 8], [5, 9], [5, 12], [5, 13], [5, 14], [5, 15], [5, 16], [5, 17], [5, 18], [5, 20], [5, 22], [5, 23], [6, 7], [6, 8], [6, 9], [6, 12], [6, 13], [6, 14], [6, 15], [6, 16], [6, 17], [6, 18], [6, 20], [6, 22], [7, 8], [7, 9], [7, 12], [7, 13], [7, 14], [7, 15], [7, 16], [7, 17], [7, 18], [7, 19], [7, 20], [7, 22], [7, 23], [8, 9], [8, 12], [8, 13], [8, 14], [8, 15], [8, 16], [8, 17], [8, 18], [8, 20], [8, 21], [8, 22], [9, 12], [9, 13], [9, 14], [9, 15], [9, 16], [9, 17], [9, 18], [9, 20], [9, 22], [10, 15], [10, 17], [11, 13], [11, 15], [11, 22], [12, 13], [12, 14], [12, 15], [12, 16], [12, 17], [12, 18], [12, 20], [12, 22], [13, 14], [13, 15], [13, 16], [13, 17], [13, 18], [13, 19], [13, 20], [13, 22], [14, 15], [14, 16], [14, 17], [14, 18], [14, 20], [14, 22], [14, 23], [15, 16], [15, 17], [15, 18], [15, 19], [15, 20], [15, 21], [15, 22], [16, 17], [16, 18], [16, 20], [16, 22], [17, 18], [17, 20], [17, 22], [17, 23], [18, 20], [18, 22], [19, 22], [20, 21], [20, 22], [22, 23]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l3-s4/tests/run.py b/tasks/construct-rlve-imp-party-l3-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l3-s4/tests/test.sh b/tasks/construct-rlve-imp-party-l3-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-integer-linear-system-l4-s3/environment/Dockerfile b/tasks/construct-rlve-integer-linear-system-l4-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-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-rlve-integer-linear-system-l4-s3/environment/instance.json b/tasks/construct-rlve-integer-linear-system-l4-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3297bcc0ad0847a184aa8c3a0a0594cde6250e8d --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l4-s3/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [[1, 0, 1, 1, 0, 1, 0, 1, 2, 0, 1, 1], [0, 0, 0, 1, 2, 0, 1, 0, 1, 0, 0, 0], [0, 0, 2, 1, 1, 2, 2, 1, 2, 1, 0, 2], [0, 2, 0, 2, 1, 2, 0, 0, 2, 1, 0, 2], [2, 0, 2, 1, 0, 0, 0, 2, 1, 0, 0, 1], [1, 2, 2, 2, 0, 2, 2, 1, 2, 2, 1, 0], [0, 1, 2, 0, 2, 0, 2, 1, 1, 1, 1, 1], [0, 2, 1, 2, 2, 0, 0, 2, 1, 0, 0, 2], [0, 2, 1, 0, 0, 1, 2, 1, 0, 0, 0, 1], [0, 1, 1, 2, 0, 0, 1, 0, 0, 0, 0, 0], [2, 0, 0, 0, 2, 1, 1, 2, 0, 0, 2, 1], [1, 2, 2, 2, 2, 1, 1, 0, 0, 0, 2, 0], [2, 0, 0, 0, 0, 1, 0, 0, 2, 2, 0, 0], [1, 0, 2, 1, 0, 1, 0, 0, 0, 1, 0, 0], [1, 0, 2, 1, 1, 0, 0, 0, 1, 0, 1, 2], [0, 0, 2, 1, 1, 0, 2, 1, 2, 0, 0, 0], [0, 1, 0, 0, 0, 0, 2, 1, 0, 0, 1, 0], [0, 0, 0, 2, 0, 0, 1, 0, 1, 0, 2, 1], [0, 0, 1, 0, 2, 0, 0, 2, 0, 0, 1, 2], [1, 0, 0, 0, 0, 0, 2, 2, 1, 0, 0, 2], [1, 1, 2, 0, 1, 0, 0, 0, 0, 1, 0, 1], [0, 1, 0, 1, 2, 0, 1, 2, 2, 0, 1, 0], [0, 1, 2, 0, 2, 0, 1, 0, 1, 2, 0, 1], [0, 0, 1, 0, 0, 2, 0, 1, 2, 1, 1, 1], [0, 1, 0, 0, 2, 0, 0, 2, 1, 0, 0, 0], [2, 1, 2, 0, 1, 0, 1, 1, 0, 0, 0, 0], [2, 2, 2, 0, 1, 2, 1, 0, 2, 0, 1, 2], [2, 0, 2, 2, 1, 2, 0, 1, 0, 0, 0, 1], [1, 2, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1], [0, 1, 0, 2, 0, 0, 2, 0, 2, 0, 2, 2], [0, 2, 2, 0, 1, 2, 0, 0, 0, 0, 1, 0], [2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 1, 0], [0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 0, 0]], "rhs": [47, 11, 69, 70, 36, 83, 39, 44, 31, 17, 53, 54, 44, 36, 41, 20, 14, 37, 33, 31, 29, 28, 37, 57, 12, 21, 71, 62, 30, 50, 40, 31, 12], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l4-s3/solution/solve.sh b/tasks/construct-rlve-integer-linear-system-l4-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..fc51876ec28786e4ba423a03e57a5856a860a604 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-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' +{"x": [5, 2, 2, 6, 1, 12, 1, 3, 2, 9, 7, 8]} +RLMATH_EOF diff --git a/tasks/construct-rlve-integer-linear-system-l4-s3/tests/check.py b/tasks/construct-rlve-integer-linear-system-l4-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..ff19002b3fddc9597f84ee31ef5ffbee5d3fac32 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l4-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-l4-s3/tests/instance.json b/tasks/construct-rlve-integer-linear-system-l4-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3297bcc0ad0847a184aa8c3a0a0594cde6250e8d --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l4-s3/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [[1, 0, 1, 1, 0, 1, 0, 1, 2, 0, 1, 1], [0, 0, 0, 1, 2, 0, 1, 0, 1, 0, 0, 0], [0, 0, 2, 1, 1, 2, 2, 1, 2, 1, 0, 2], [0, 2, 0, 2, 1, 2, 0, 0, 2, 1, 0, 2], [2, 0, 2, 1, 0, 0, 0, 2, 1, 0, 0, 1], [1, 2, 2, 2, 0, 2, 2, 1, 2, 2, 1, 0], [0, 1, 2, 0, 2, 0, 2, 1, 1, 1, 1, 1], [0, 2, 1, 2, 2, 0, 0, 2, 1, 0, 0, 2], [0, 2, 1, 0, 0, 1, 2, 1, 0, 0, 0, 1], [0, 1, 1, 2, 0, 0, 1, 0, 0, 0, 0, 0], [2, 0, 0, 0, 2, 1, 1, 2, 0, 0, 2, 1], [1, 2, 2, 2, 2, 1, 1, 0, 0, 0, 2, 0], [2, 0, 0, 0, 0, 1, 0, 0, 2, 2, 0, 0], [1, 0, 2, 1, 0, 1, 0, 0, 0, 1, 0, 0], [1, 0, 2, 1, 1, 0, 0, 0, 1, 0, 1, 2], [0, 0, 2, 1, 1, 0, 2, 1, 2, 0, 0, 0], [0, 1, 0, 0, 0, 0, 2, 1, 0, 0, 1, 0], [0, 0, 0, 2, 0, 0, 1, 0, 1, 0, 2, 1], [0, 0, 1, 0, 2, 0, 0, 2, 0, 0, 1, 2], [1, 0, 0, 0, 0, 0, 2, 2, 1, 0, 0, 2], [1, 1, 2, 0, 1, 0, 0, 0, 0, 1, 0, 1], [0, 1, 0, 1, 2, 0, 1, 2, 2, 0, 1, 0], [0, 1, 2, 0, 2, 0, 1, 0, 1, 2, 0, 1], [0, 0, 1, 0, 0, 2, 0, 1, 2, 1, 1, 1], [0, 1, 0, 0, 2, 0, 0, 2, 1, 0, 0, 0], [2, 1, 2, 0, 1, 0, 1, 1, 0, 0, 0, 0], [2, 2, 2, 0, 1, 2, 1, 0, 2, 0, 1, 2], [2, 0, 2, 2, 1, 2, 0, 1, 0, 0, 0, 1], [1, 2, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1], [0, 1, 0, 2, 0, 0, 2, 0, 2, 0, 2, 2], [0, 2, 2, 0, 1, 2, 0, 0, 0, 0, 1, 0], [2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 1, 0], [0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 0, 0]], "rhs": [47, 11, 69, 70, 36, 83, 39, 44, 31, 17, 53, 54, 44, 36, 41, 20, 14, 37, 33, 31, 29, 28, 37, 57, 12, 21, 71, 62, 30, 50, 40, 31, 12], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l4-s3/tests/run.py b/tasks/construct-rlve-integer-linear-system-l4-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-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-rlve-integer-linear-system-l4-s3/tests/test.sh b/tasks/construct-rlve-integer-linear-system-l4-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-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-rlve-integer-linear-system-l4-s4/environment/Dockerfile b/tasks/construct-rlve-integer-linear-system-l4-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l4-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-l4-s4/environment/instance.json b/tasks/construct-rlve-integer-linear-system-l4-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..db1ede764e1827c5753603394d731f8063cbeaa8 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l4-s4/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [[2, 1, 0, 2, 1, 0, 0, 2, 2, 0, 0, 0], [0, 2, 0, 0, 1, 0, 0, 2, 2, 2, 0, 0], [0, 2, 2, 2, 2, 2, 1, 0, 0, 2, 0, 1], [1, 0, 0, 2, 1, 0, 2, 0, 2, 0, 2, 0], [0, 2, 0, 2, 2, 0, 2, 0, 2, 2, 0, 0], [2, 0, 2, 2, 1, 0, 1, 0, 0, 0, 1, 2], [1, 2, 2, 1, 1, 1, 2, 0, 0, 2, 1, 0], [0, 0, 1, 0, 2, 1, 1, 1, 2, 1, 0, 0], [0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0], [1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 2, 0, 0, 0, 0, 1, 2, 0, 0, 0], [1, 1, 2, 2, 1, 2, 0, 2, 2, 0, 0, 0], [2, 1, 2, 0, 2, 2, 0, 0, 0, 0, 2, 2], [0, 0, 0, 2, 2, 0, 1, 2, 0, 0, 0, 2], [2, 2, 1, 2, 1, 2, 0, 2, 0, 2, 0, 1], [2, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1], [2, 0, 2, 2, 2, 1, 1, 2, 2, 0, 0, 2], [0, 2, 1, 0, 0, 1, 1, 2, 0, 1, 0, 0], [0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 2, 0], [0, 2, 2, 1, 2, 2, 2, 0, 0, 2, 0, 0], [0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0], [0, 1, 1, 1, 2, 2, 1, 1, 0, 0, 0, 2], [1, 2, 0, 0, 2, 2, 1, 2, 0, 2, 1, 2]], "rhs": [39, 42, 72, 33, 46, 47, 58, 50, 13, 13, 44, 72, 73, 35, 71, 31, 30, 81, 42, 18, 67, 27, 63, 74], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l4-s4/solution/solve.sh b/tasks/construct-rlve-integer-linear-system-l4-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d80681f81641266bc247c887a9a376f1b0357f14 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l4-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, 5, 8, 1, 4, 10, 3, 4, 7, 3, 2, 7]} +RLMATH_EOF diff --git a/tasks/construct-rlve-integer-linear-system-l4-s4/tests/check.py b/tasks/construct-rlve-integer-linear-system-l4-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..ff19002b3fddc9597f84ee31ef5ffbee5d3fac32 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l4-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-l4-s4/tests/instance.json b/tasks/construct-rlve-integer-linear-system-l4-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..db1ede764e1827c5753603394d731f8063cbeaa8 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l4-s4/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [[2, 1, 0, 2, 1, 0, 0, 2, 2, 0, 0, 0], [0, 2, 0, 0, 1, 0, 0, 2, 2, 2, 0, 0], [0, 2, 2, 2, 2, 2, 1, 0, 0, 2, 0, 1], [1, 0, 0, 2, 1, 0, 2, 0, 2, 0, 2, 0], [0, 2, 0, 2, 2, 0, 2, 0, 2, 2, 0, 0], [2, 0, 2, 2, 1, 0, 1, 0, 0, 0, 1, 2], [1, 2, 2, 1, 1, 1, 2, 0, 0, 2, 1, 0], [0, 0, 1, 0, 2, 1, 1, 1, 2, 1, 0, 0], [0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0], [1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 2, 0, 0, 0, 0, 1, 2, 0, 0, 0], [1, 1, 2, 2, 1, 2, 0, 2, 2, 0, 0, 0], [2, 1, 2, 0, 2, 2, 0, 0, 0, 0, 2, 2], [0, 0, 0, 2, 2, 0, 1, 2, 0, 0, 0, 2], [2, 2, 1, 2, 1, 2, 0, 2, 0, 2, 0, 1], [2, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1], [2, 0, 2, 2, 2, 1, 1, 2, 2, 0, 0, 2], [0, 2, 1, 0, 0, 1, 1, 2, 0, 1, 0, 0], [0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 2, 0], [0, 2, 2, 1, 2, 2, 2, 0, 0, 2, 0, 0], [0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0], [0, 1, 1, 1, 2, 2, 1, 1, 0, 0, 0, 2], [1, 2, 0, 0, 2, 2, 1, 2, 0, 2, 1, 2]], "rhs": [39, 42, 72, 33, 46, 47, 58, 50, 13, 13, 44, 72, 73, 35, 71, 31, 30, 81, 42, 18, 67, 27, 63, 74], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l4-s4/tests/run.py b/tasks/construct-rlve-integer-linear-system-l4-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l4-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-l4-s4/tests/test.sh b/tasks/construct-rlve-integer-linear-system-l4-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l4-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-largest-convex-polygon-l3-s2/environment/Dockerfile b/tasks/construct-rlve-largest-convex-polygon-l3-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-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-largest-convex-polygon-l3-s2/environment/instance.json b/tasks/construct-rlve-largest-convex-polygon-l3-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3802459eec85108fb596785c1870f1cf6f7f056c --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-s2/environment/instance.json @@ -0,0 +1 @@ +{"points": [[9, 0], [13, 4], [12, 7], [3, 4], [13, 1], [8, 7], [7, 10], [7, 3], [8, 13], [2, 3], [5, 10], [6, 0], [10, 9]], "k": 9, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l3-s2/solution/solve.sh b/tasks/construct-rlve-largest-convex-polygon-l3-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8bba47a04d8f146caf81f9ac2621fc5900939aaa --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-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' +{"indices": [3, 10, 6, 12, 2, 1, 4, 0, 11]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-convex-polygon-l3-s2/tests/check.py b/tasks/construct-rlve-largest-convex-polygon-l3-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3a09cc858f41ce5745e4e491188cd42360c65dae --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-s2/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-l3-s2/tests/instance.json b/tasks/construct-rlve-largest-convex-polygon-l3-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3802459eec85108fb596785c1870f1cf6f7f056c --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-s2/tests/instance.json @@ -0,0 +1 @@ +{"points": [[9, 0], [13, 4], [12, 7], [3, 4], [13, 1], [8, 7], [7, 10], [7, 3], [8, 13], [2, 3], [5, 10], [6, 0], [10, 9]], "k": 9, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l3-s2/tests/run.py b/tasks/construct-rlve-largest-convex-polygon-l3-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-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-largest-convex-polygon-l3-s2/tests/test.sh b/tasks/construct-rlve-largest-convex-polygon-l3-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-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-largest-convex-polygon-l3-s5/environment/Dockerfile b/tasks/construct-rlve-largest-convex-polygon-l3-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-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-l3-s5/environment/instance.json b/tasks/construct-rlve-largest-convex-polygon-l3-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a40d764df727272d51985cddf1da32f17a74db4a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-s5/environment/instance.json @@ -0,0 +1 @@ +{"points": [[6, 12], [6, 2], [8, 4], [3, 7], [4, 12], [12, 3], [4, 2], [3, 9], [9, 8], [12, 5], [13, 5], [1, 9], [11, 11]], "k": 9, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l3-s5/solution/solve.sh b/tasks/construct-rlve-largest-convex-polygon-l3-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..3dbaf964469149b0f7114d56286508a0373c6579 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-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": [3, 7, 4, 0, 12, 9, 5, 1, 6]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-convex-polygon-l3-s5/tests/check.py b/tasks/construct-rlve-largest-convex-polygon-l3-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3a09cc858f41ce5745e4e491188cd42360c65dae --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-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-l3-s5/tests/instance.json b/tasks/construct-rlve-largest-convex-polygon-l3-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a40d764df727272d51985cddf1da32f17a74db4a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-s5/tests/instance.json @@ -0,0 +1 @@ +{"points": [[6, 12], [6, 2], [8, 4], [3, 7], [4, 12], [12, 3], [4, 2], [3, 9], [9, 8], [12, 5], [13, 5], [1, 9], [11, 11]], "k": 9, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l3-s5/tests/run.py b/tasks/construct-rlve-largest-convex-polygon-l3-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-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-l3-s5/tests/test.sh b/tasks/construct-rlve-largest-convex-polygon-l3-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-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-rectangle-l1-s2/environment/Dockerfile b/tasks/construct-rlve-largest-rectangle-l1-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l1-s2/environment/instance.json b/tasks/construct-rlve-largest-rectangle-l1-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c3ac53171abf2089784b4a537cd652c1235588d0 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l1-s2/environment/instance.json @@ -0,0 +1 @@ +{"points": [[-1, 3], [2, 5], [4, 2], [1, 0], [4, -1], [-1, 2]], "area": 13, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l1-s2/solution/solve.sh b/tasks/construct-rlve-largest-rectangle-l1-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..299309dad9518b6087c90ad509788270be7627a3 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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' +{"indices": [0, 1, 2, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-rectangle-l1-s2/tests/check.py b/tasks/construct-rlve-largest-rectangle-l1-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2251b2af23a481e598fa1e48d0a8249f70b6cc44 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l1-s2/tests/check.py @@ -0,0 +1,24 @@ +from run import Invalid, int_list + + +def check(inst, ans): + P = inst["points"] + idx = int_list(ans.get("indices"), 4, 0, len(P) - 1, "indices") + if len(set(idx)) != 4: + raise Invalid("indices must be distinct") + A, *rest = [tuple(P[i]) for i in idx] + if len(set([A] + rest)) != 4: + raise Invalid("points must be distinct") + # the vertex farthest from A is opposite; the other two are A's neighbours + rest.sort(key=lambda X: (X[0] - A[0]) ** 2 + (X[1] - A[1]) ** 2) + B, D, C = rest + u = (B[0] - A[0], B[1] - A[1]) + v = (D[0] - A[0], D[1] - A[1]) + if u[0] * v[0] + u[1] * v[1] != 0: + raise Invalid("not a rectangle (no right angle at the first vertex)") + if (B[0] + D[0] - A[0], B[1] + D[1] - A[1]) != C: + raise Invalid("not a rectangle") + area = abs(u[0] * v[1] - u[1] * v[0]) + if area < inst["area"]: + raise Invalid(f"area {area} < {inst['area']}") + return None, {"area": area} diff --git a/tasks/construct-rlve-largest-rectangle-l1-s2/tests/instance.json b/tasks/construct-rlve-largest-rectangle-l1-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c3ac53171abf2089784b4a537cd652c1235588d0 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l1-s2/tests/instance.json @@ -0,0 +1 @@ +{"points": [[-1, 3], [2, 5], [4, 2], [1, 0], [4, -1], [-1, 2]], "area": 13, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l1-s2/tests/run.py b/tasks/construct-rlve-largest-rectangle-l1-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l1-s2/tests/test.sh b/tasks/construct-rlve-largest-rectangle-l1-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l1-s5/environment/Dockerfile b/tasks/construct-rlve-largest-rectangle-l1-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l1-s5/environment/instance.json b/tasks/construct-rlve-largest-rectangle-l1-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2b8a6ac989c7ede846e34f3879d2a41b1ff375a5 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l1-s5/environment/instance.json @@ -0,0 +1 @@ +{"points": [[-2, -3], [0, -1], [-1, -4], [-2, -1], [-1, 1], [0, -3]], "area": 4, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l1-s5/solution/solve.sh b/tasks/construct-rlve-largest-rectangle-l1-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..468af567af66cf594a78e84063810e7ae20359c0 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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' +{"indices": [0, 3, 1, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-rectangle-l1-s5/tests/check.py b/tasks/construct-rlve-largest-rectangle-l1-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2251b2af23a481e598fa1e48d0a8249f70b6cc44 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l1-s5/tests/check.py @@ -0,0 +1,24 @@ +from run import Invalid, int_list + + +def check(inst, ans): + P = inst["points"] + idx = int_list(ans.get("indices"), 4, 0, len(P) - 1, "indices") + if len(set(idx)) != 4: + raise Invalid("indices must be distinct") + A, *rest = [tuple(P[i]) for i in idx] + if len(set([A] + rest)) != 4: + raise Invalid("points must be distinct") + # the vertex farthest from A is opposite; the other two are A's neighbours + rest.sort(key=lambda X: (X[0] - A[0]) ** 2 + (X[1] - A[1]) ** 2) + B, D, C = rest + u = (B[0] - A[0], B[1] - A[1]) + v = (D[0] - A[0], D[1] - A[1]) + if u[0] * v[0] + u[1] * v[1] != 0: + raise Invalid("not a rectangle (no right angle at the first vertex)") + if (B[0] + D[0] - A[0], B[1] + D[1] - A[1]) != C: + raise Invalid("not a rectangle") + area = abs(u[0] * v[1] - u[1] * v[0]) + if area < inst["area"]: + raise Invalid(f"area {area} < {inst['area']}") + return None, {"area": area} diff --git a/tasks/construct-rlve-largest-rectangle-l1-s5/tests/instance.json b/tasks/construct-rlve-largest-rectangle-l1-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2b8a6ac989c7ede846e34f3879d2a41b1ff375a5 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l1-s5/tests/instance.json @@ -0,0 +1 @@ +{"points": [[-2, -3], [0, -1], [-1, -4], [-2, -1], [-1, 1], [0, -3]], "area": 4, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l1-s5/tests/run.py b/tasks/construct-rlve-largest-rectangle-l1-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l1-s5/tests/test.sh b/tasks/construct-rlve-largest-rectangle-l1-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l5-s3/environment/Dockerfile b/tasks/construct-rlve-largest-rectangle-l5-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l5-s3/environment/instance.json b/tasks/construct-rlve-largest-rectangle-l5-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8caf98eaeb8e5d0a80c202c563721b8988ddf421 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l5-s3/environment/instance.json @@ -0,0 +1 @@ +{"points": [[-20, 37], [36, -19], [-9, -38], [1, 2], [28, -12], [-3, -7], [-7, -18], [-11, 7], [-12, 9], [17, -14], [3, 15], [-31, -14], [35, 20], [0, -6], [0, 36], [-28, 6], [31, 33], [16, 30], [-7, 3], [-30, -12], [2, 4], [11, 1], [-36, 24], [-39, -7], [-12, -16], [-37, -38], [19, -16], [26, -36], [14, 19], [21, 19], [-18, -21], [-11, 26], [-15, 24], [26, 24], [38, 19], [27, 13], [-30, -27], [6, -19], [27, 33], [-2, 19]], "area": 260, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l5-s3/solution/solve.sh b/tasks/construct-rlve-largest-rectangle-l5-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a68b7ec7413413eda72b06be7238ddf676be4020 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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' +{"indices": [5, 7, 10, 21]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-rectangle-l5-s3/tests/check.py b/tasks/construct-rlve-largest-rectangle-l5-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2251b2af23a481e598fa1e48d0a8249f70b6cc44 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l5-s3/tests/check.py @@ -0,0 +1,24 @@ +from run import Invalid, int_list + + +def check(inst, ans): + P = inst["points"] + idx = int_list(ans.get("indices"), 4, 0, len(P) - 1, "indices") + if len(set(idx)) != 4: + raise Invalid("indices must be distinct") + A, *rest = [tuple(P[i]) for i in idx] + if len(set([A] + rest)) != 4: + raise Invalid("points must be distinct") + # the vertex farthest from A is opposite; the other two are A's neighbours + rest.sort(key=lambda X: (X[0] - A[0]) ** 2 + (X[1] - A[1]) ** 2) + B, D, C = rest + u = (B[0] - A[0], B[1] - A[1]) + v = (D[0] - A[0], D[1] - A[1]) + if u[0] * v[0] + u[1] * v[1] != 0: + raise Invalid("not a rectangle (no right angle at the first vertex)") + if (B[0] + D[0] - A[0], B[1] + D[1] - A[1]) != C: + raise Invalid("not a rectangle") + area = abs(u[0] * v[1] - u[1] * v[0]) + if area < inst["area"]: + raise Invalid(f"area {area} < {inst['area']}") + return None, {"area": area} diff --git a/tasks/construct-rlve-largest-rectangle-l5-s3/tests/instance.json b/tasks/construct-rlve-largest-rectangle-l5-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8caf98eaeb8e5d0a80c202c563721b8988ddf421 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l5-s3/tests/instance.json @@ -0,0 +1 @@ +{"points": [[-20, 37], [36, -19], [-9, -38], [1, 2], [28, -12], [-3, -7], [-7, -18], [-11, 7], [-12, 9], [17, -14], [3, 15], [-31, -14], [35, 20], [0, -6], [0, 36], [-28, 6], [31, 33], [16, 30], [-7, 3], [-30, -12], [2, 4], [11, 1], [-36, 24], [-39, -7], [-12, -16], [-37, -38], [19, -16], [26, -36], [14, 19], [21, 19], [-18, -21], [-11, 26], [-15, 24], [26, 24], [38, 19], [27, 13], [-30, -27], [6, -19], [27, 33], [-2, 19]], "area": 260, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l5-s3/tests/run.py b/tasks/construct-rlve-largest-rectangle-l5-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l5-s3/tests/test.sh b/tasks/construct-rlve-largest-rectangle-l5-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-matrix-permutation-equivalence-l2-s1/environment/Dockerfile b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-matrix-permutation-equivalence-l2-s1/environment/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f3d54cae4ed5afee058fefa0bd655e66456e6299 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s1/environment/instance.json @@ -0,0 +1 @@ +{"A": ["00111", "10001", "00101", "01100"], "B": ["01010", "11000", "11100", "10001"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l2-s1/solution/solve.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0851b47857d2daba45a7df8d85776aad29412c7c --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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' +{"a": [1, 2, 0, 3], "b": [2, 4, 3, 0, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l2-s1/tests/check.py b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..310a1d2c8b6afd7a82a35ba2a4c802c1ce289d03 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l2-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-l2-s1/tests/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f3d54cae4ed5afee058fefa0bd655e66456e6299 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s1/tests/instance.json @@ -0,0 +1 @@ +{"A": ["00111", "10001", "00101", "01100"], "B": ["01010", "11000", "11100", "10001"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l2-s1/tests/run.py b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-matrix-permutation-equivalence-l2-s1/tests/test.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-matrix-permutation-equivalence-l2-s6/environment/Dockerfile b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-rlve-matrix-permutation-equivalence-l2-s6/environment/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..04a925271b38a580b83ab20d35750a122498e45b --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s6/environment/instance.json @@ -0,0 +1 @@ +{"A": ["01111", "01111", "01111", "11111"], "B": ["10111", "10111", "10111", "11111"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l2-s6/solution/solve.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5f341309c9df1302772752b6d17ec5e1aa3ed6e1 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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' +{"a": [2, 1, 0, 3], "b": [1, 0, 2, 4, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l2-s6/tests/check.py b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..310a1d2c8b6afd7a82a35ba2a4c802c1ce289d03 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l2-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-l2-s6/tests/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..04a925271b38a580b83ab20d35750a122498e45b --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s6/tests/instance.json @@ -0,0 +1 @@ +{"A": ["01111", "01111", "01111", "11111"], "B": ["10111", "10111", "10111", "11111"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l2-s6/tests/run.py b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-rlve-matrix-permutation-equivalence-l2-s6/tests/test.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-rlve-matrix-permutation-equivalence-l6-s9/environment/Dockerfile b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l6-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-matrix-permutation-equivalence-l6-s9/environment/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..46c02232bea6bf785d39efbd3fa49b4fae1f502e --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s9/environment/instance.json @@ -0,0 +1 @@ +{"A": ["10011110110", "00110001010", "01110111111", "11111101101", "00110010101", "01001111010", "10100011100", "11111111101", "11111110011", "00010111110", "11101100111", "01111110010", "10000110110", "11001100111", "01110011011", "10000111111", "10101101111", "01110110001"], "B": ["10001101110", "01111110111", "11111111001", "11110100011", "11110110110", "01000011110", "10011111111", "11101101010", "11110110011", "10101111001", "10100101101", "11010101110", "00011011010", "10011011101", "11000101010", "10001010100", "01111111111", "00011111001"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l6-s9/solution/solve.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..3932dd4c9610db04c424fea0867ddfd9601ba753 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l6-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' +{"a": [9, 3, 8, 13, 16, 6, 2, 0, 10, 11, 5, 15, 4, 14, 12, 1, 7, 17], "b": [9, 0, 4, 10, 3, 5, 2, 6, 7, 8, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l6-s9/tests/check.py b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..310a1d2c8b6afd7a82a35ba2a4c802c1ce289d03 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s9/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-l6-s9/tests/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..46c02232bea6bf785d39efbd3fa49b4fae1f502e --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s9/tests/instance.json @@ -0,0 +1 @@ +{"A": ["10011110110", "00110001010", "01110111111", "11111101101", "00110010101", "01001111010", "10100011100", "11111111101", "11111110011", "00010111110", "11101100111", "01111110010", "10000110110", "11001100111", "01110011011", "10000111111", "10101101111", "01110110001"], "B": ["10001101110", "01111110111", "11111111001", "11110100011", "11110110110", "01000011110", "10011111111", "11101101010", "11110110011", "10101111001", "10100101101", "11010101110", "00011011010", "10011011101", "11000101010", "10001010100", "01111111111", "00011111001"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l6-s9/tests/run.py b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l6-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-matrix-permutation-equivalence-l6-s9/tests/test.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l6-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-max-achromatic-coloring-l3-s3/environment/Dockerfile b/tasks/construct-rlve-max-achromatic-coloring-l3-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l3-s3/environment/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l3-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6652218d4ff67cb50be4798a43c563eb260ed923 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l3-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 6, "edges": [[0, 2], [0, 3], [0, 4], [0, 6], [0, 8], [1, 2], [1, 3], [1, 5], [1, 7], [1, 9], [2, 4], [2, 5], [2, 6], [2, 7], [3, 5], [3, 7], [3, 8], [4, 6], [4, 7], [4, 8], [4, 9], [5, 7], [5, 8], [5, 9], [6, 7], [6, 8], [8, 9]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l3-s3/solution/solve.sh b/tasks/construct-rlve-max-achromatic-coloring-l3-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..081b1417a8b40319da16f60c017a3d28026ddaec --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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' +{"colors": [0, 0, 1, 1, 2, 2, 3, 4, 5, 4]} +RLMATH_EOF diff --git a/tasks/construct-rlve-max-achromatic-coloring-l3-s3/tests/check.py b/tasks/construct-rlve-max-achromatic-coloring-l3-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bb676a518264e5db4fb0964e27ccffccf6980807 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l3-s3/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-l3-s3/tests/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l3-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6652218d4ff67cb50be4798a43c563eb260ed923 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l3-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 6, "edges": [[0, 2], [0, 3], [0, 4], [0, 6], [0, 8], [1, 2], [1, 3], [1, 5], [1, 7], [1, 9], [2, 4], [2, 5], [2, 6], [2, 7], [3, 5], [3, 7], [3, 8], [4, 6], [4, 7], [4, 8], [4, 9], [5, 7], [5, 8], [5, 9], [6, 7], [6, 8], [8, 9]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l3-s3/tests/run.py b/tasks/construct-rlve-max-achromatic-coloring-l3-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l3-s3/tests/test.sh b/tasks/construct-rlve-max-achromatic-coloring-l3-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l3-s4/environment/Dockerfile b/tasks/construct-rlve-max-achromatic-coloring-l3-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l3-s4/environment/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l3-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9fdf7453133704a899c59aae914ec3e8658c23fd --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l3-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 7, "edges": [[0, 2], [0, 5], [0, 6], [0, 7], [1, 2], [1, 4], [1, 7], [1, 9], [2, 3], [2, 4], [2, 6], [2, 8], [2, 9], [3, 6], [3, 9], [4, 6], [4, 8], [4, 9], [5, 6], [5, 8], [5, 9], [6, 7], [6, 8], [6, 9], [7, 8], [7, 9], [8, 9]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l3-s4/solution/solve.sh b/tasks/construct-rlve-max-achromatic-coloring-l3-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9086eff5a99b33ae80e8de1b06c1b673738306de --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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' +{"colors": [0, 1, 2, 3, 0, 1, 4, 3, 5, 6]} +RLMATH_EOF diff --git a/tasks/construct-rlve-max-achromatic-coloring-l3-s4/tests/check.py b/tasks/construct-rlve-max-achromatic-coloring-l3-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bb676a518264e5db4fb0964e27ccffccf6980807 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l3-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-l3-s4/tests/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l3-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9fdf7453133704a899c59aae914ec3e8658c23fd --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l3-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 7, "edges": [[0, 2], [0, 5], [0, 6], [0, 7], [1, 2], [1, 4], [1, 7], [1, 9], [2, 3], [2, 4], [2, 6], [2, 8], [2, 9], [3, 6], [3, 9], [4, 6], [4, 8], [4, 9], [5, 6], [5, 8], [5, 9], [6, 7], [6, 8], [6, 9], [7, 8], [7, 9], [8, 9]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l3-s4/tests/run.py b/tasks/construct-rlve-max-achromatic-coloring-l3-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l3-s4/tests/test.sh b/tasks/construct-rlve-max-achromatic-coloring-l3-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-maximum-clique-l1-s0/environment/Dockerfile b/tasks/construct-rlve-maximum-clique-l1-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-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-rlve-maximum-clique-l1-s0/environment/instance.json b/tasks/construct-rlve-maximum-clique-l1-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..65cf99060f098dc9b6ae3274e1699c9fe6704c51 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l1-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 5, "edges": [[0, 2], [0, 4], [0, 5], [0, 6], [0, 7], [1, 2], [1, 4], [1, 5], [1, 6], [2, 4], [2, 5], [2, 6], [2, 7], [3, 4], [3, 5], [3, 6], [3, 7], [4, 6], [4, 7], [5, 6], [6, 7]], "family": "rlve_maximum_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-maximum-clique-l1-s0/solution/solve.sh b/tasks/construct-rlve-maximum-clique-l1-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..fa60fd886ee745d3abb4cd0c05865a509a473c0a --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-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' +{"clique": [0, 2, 4, 6, 7]} +RLMATH_EOF diff --git a/tasks/construct-rlve-maximum-clique-l1-s0/tests/check.py b/tasks/construct-rlve-maximum-clique-l1-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..95e00c78f7c986ba3aecbdc8af3cf8ed221abd05 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l1-s0/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-l1-s0/tests/instance.json b/tasks/construct-rlve-maximum-clique-l1-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..65cf99060f098dc9b6ae3274e1699c9fe6704c51 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l1-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 5, "edges": [[0, 2], [0, 4], [0, 5], [0, 6], [0, 7], [1, 2], [1, 4], [1, 5], [1, 6], [2, 4], [2, 5], [2, 6], [2, 7], [3, 4], [3, 5], [3, 6], [3, 7], [4, 6], [4, 7], [5, 6], [6, 7]], "family": "rlve_maximum_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-maximum-clique-l1-s0/tests/run.py b/tasks/construct-rlve-maximum-clique-l1-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-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-rlve-maximum-clique-l1-s0/tests/test.sh b/tasks/construct-rlve-maximum-clique-l1-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-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-rlve-maximum-clique-l1-s7/environment/Dockerfile b/tasks/construct-rlve-maximum-clique-l1-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l1-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-maximum-clique-l1-s7/environment/instance.json b/tasks/construct-rlve-maximum-clique-l1-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a794671ac00b46dbd1e5b72ff7f54a0166d35f57 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l1-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 5, "edges": [[0, 1], [0, 2], [0, 5], [0, 6], [1, 2], [1, 3], [1, 4], [1, 7], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [3, 4], [3, 6], [3, 7], [4, 5], [4, 6], [4, 7], [5, 6], [6, 7]], "family": "rlve_maximum_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-maximum-clique-l1-s7/solution/solve.sh b/tasks/construct-rlve-maximum-clique-l1-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8c576971cab23ddc3184fd3229998f2e5307b94a --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l1-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": [1, 2, 3, 4, 7]} +RLMATH_EOF diff --git a/tasks/construct-rlve-maximum-clique-l1-s7/tests/check.py b/tasks/construct-rlve-maximum-clique-l1-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..95e00c78f7c986ba3aecbdc8af3cf8ed221abd05 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l1-s7/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-l1-s7/tests/instance.json b/tasks/construct-rlve-maximum-clique-l1-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a794671ac00b46dbd1e5b72ff7f54a0166d35f57 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l1-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 5, "edges": [[0, 1], [0, 2], [0, 5], [0, 6], [1, 2], [1, 3], [1, 4], [1, 7], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [3, 4], [3, 6], [3, 7], [4, 5], [4, 6], [4, 7], [5, 6], [6, 7]], "family": "rlve_maximum_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-maximum-clique-l1-s7/tests/run.py b/tasks/construct-rlve-maximum-clique-l1-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l1-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-maximum-clique-l1-s7/tests/test.sh b/tasks/construct-rlve-maximum-clique-l1-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l1-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-maximum-clique-l5-s8/environment/Dockerfile b/tasks/construct-rlve-maximum-clique-l5-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l5-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-l5-s8/environment/instance.json b/tasks/construct-rlve-maximum-clique-l5-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1af3bdcd9f6403d1b8d4f4fcf9eeca095cea22ab --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l5-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 44, "k": 8, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 6], [0, 8], [0, 10], [0, 12], [0, 14], [0, 15], [0, 18], [0, 19], [0, 20], [0, 21], [0, 23], [0, 25], [0, 26], [0, 28], [0, 30], [0, 33], [0, 36], [0, 37], [0, 39], [0, 40], [0, 41], [0, 42], [1, 2], [1, 3], [1, 4], [1, 5], [1, 7], [1, 8], [1, 9], [1, 10], [1, 13], [1, 14], [1, 15], [1, 17], [1, 20], [1, 23], [1, 24], [1, 25], [1, 26], [1, 27], [1, 29], [1, 30], [1, 32], [1, 33], [1, 34], [1, 35], [1, 36], [1, 37], [1, 40], [1, 41], [1, 42], [2, 3], [2, 6], [2, 7], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 17], [2, 19], [2, 23], [2, 25], [2, 26], [2, 29], [2, 30], [2, 32], [2, 33], [2, 34], [2, 37], [2, 38], [2, 40], [2, 41], [2, 42], [3, 4], [3, 5], [3, 6], [3, 12], [3, 13], [3, 14], [3, 15], [3, 17], [3, 18], [3, 19], [3, 20], [3, 24], [3, 25], [3, 26], [3, 28], [3, 29], [3, 30], [3, 31], [3, 32], [3, 33], [3, 34], [3, 36], [3, 39], [3, 40], [3, 41], [4, 5], [4, 8], [4, 11], [4, 12], [4, 13], [4, 14], [4, 16], [4, 18], [4, 19], [4, 20], [4, 21], [4, 23], [4, 24], [4, 26], [4, 27], [4, 28], [4, 29], [4, 30], [4, 31], [4, 33], [4, 34], [4, 35], [4, 37], [4, 40], [4, 41], [4, 42], [4, 43], [5, 7], [5, 8], [5, 10], [5, 13], [5, 14], [5, 16], [5, 18], [5, 19], [5, 20], [5, 21], [5, 22], [5, 25], [5, 26], [5, 29], [5, 30], [5, 31], [5, 32], [5, 33], [5, 34], [5, 35], [5, 39], [5, 42], [6, 7], [6, 9], [6, 10], [6, 14], [6, 15], [6, 18], [6, 19], [6, 20], [6, 21], [6, 22], [6, 23], [6, 24], [6, 25], [6, 27], [6, 28], [6, 31], [6, 33], [6, 35], [6, 36], [6, 37], [6, 38], [6, 39], [6, 40], [6, 41], [7, 8], [7, 9], [7, 11], [7, 14], [7, 16], [7, 20], [7, 21], [7, 27], [7, 30], [7, 32], [7, 33], [7, 34], [7, 36], [7, 39], [7, 40], [7, 43], [8, 9], [8, 10], [8, 12], [8, 14], [8, 17], [8, 18], [8, 22], [8, 26], [8, 27], [8, 28], [8, 29], [8, 31], [8, 32], [8, 35], [8, 36], [8, 38], [8, 43], [9, 10], [9, 12], [9, 13], [9, 15], [9, 17], [9, 21], [9, 22], [9, 23], [9, 25], [9, 26], [9, 30], [9, 31], [9, 32], [9, 33], [9, 34], [9, 35], [9, 37], [9, 39], [9, 40], [9, 41], [9, 43], [10, 11], [10, 13], [10, 17], [10, 18], [10, 21], [10, 23], [10, 26], [10, 27], [10, 28], [10, 30], [10, 31], [10, 32], [10, 34], [10, 35], [10, 36], [10, 37], [10, 39], [10, 42], [10, 43], [11, 12], [11, 14], [11, 17], [11, 19], [11, 21], [11, 24], [11, 26], [11, 28], [11, 30], [11, 32], [11, 35], [11, 39], [11, 41], [11, 42], [12, 13], [12, 16], [12, 18], [12, 19], [12, 21], [12, 23], [12, 24], [12, 25], [12, 28], [12, 31], [12, 32], [12, 33], [12, 34], [12, 36], [12, 37], [12, 38], [12, 40], [12, 41], [13, 15], [13, 16], [13, 18], [13, 21], [13, 25], [13, 27], [13, 28], [13, 29], [13, 34], [13, 37], [13, 41], [13, 42], [14, 18], [14, 20], [14, 21], [14, 22], [14, 26], [14, 27], [14, 28], [14, 29], [14, 30], [14, 32], [14, 33], [14, 35], [14, 36], [14, 38], [14, 39], [14, 40], [14, 41], [14, 42], [14, 43], [15, 16], [15, 17], [15, 18], [15, 21], [15, 22], [15, 24], [15, 26], [15, 27], [15, 28], [15, 31], [15, 33], [15, 34], [15, 35], [15, 37], [15, 38], [15, 39], [15, 43], [16, 18], [16, 20], [16, 22], [16, 23], [16, 24], [16, 25], [16, 26], [16, 31], [16, 32], [16, 34], [16, 35], [16, 40], [16, 42], [16, 43], [17, 18], [17, 21], [17, 23], [17, 24], [17, 25], [17, 27], [17, 30], [17, 33], [17, 41], [17, 42], [17, 43], [18, 19], [18, 21], [18, 23], [18, 25], [18, 26], [18, 27], [18, 30], [18, 31], [18, 33], [18, 41], [18, 43], [19, 20], [19, 22], [19, 24], [19, 25], [19, 27], [19, 31], [19, 33], [19, 34], [19, 35], [19, 41], [19, 42], [20, 21], [20, 22], [20, 25], [20, 26], [20, 35], [20, 37], [20, 38], [20, 39], [20, 42], [20, 43], [21, 23], [21, 25], [21, 26], [21, 27], [21, 28], [21, 29], [21, 30], [21, 31], [21, 33], [21, 34], [21, 35], [21, 36], [21, 37], [21, 39], [21, 40], [21, 43], [22, 25], [22, 26], [22, 28], [22, 30], [22, 32], [22, 33], [22, 36], [22, 37], [22, 39], [22, 40], [22, 42], [22, 43], [23, 25], [23, 30], [23, 31], [23, 32], [23, 33], [23, 34], [23, 35], [23, 36], [23, 37], [23, 38], [23, 39], [23, 42], [24, 26], [24, 27], [24, 28], [24, 32], [24, 33], [24, 34], [24, 35], [24, 36], [24, 38], [24, 40], [24, 41], [25, 27], [25, 28], [25, 29], [25, 31], [25, 32], [25, 33], [25, 34], [25, 35], [25, 36], [25, 37], [26, 27], [26, 29], [26, 32], [26, 36], [26, 40], [26, 41], [27, 28], [27, 29], [27, 34], [27, 36], [27, 38], [27, 39], [28, 31], [28, 36], [28, 37], [28, 38], [28, 39], [28, 40], [28, 42], [29, 31], [29, 32], [29, 35], [29, 36], [29, 38], [29, 43], [30, 33], [30, 34], [30, 37], [30, 38], [30, 39], [31, 32], [31, 33], [31, 34], [31, 35], [31, 38], [31, 40], [31, 42], [31, 43], [32, 33], [32, 35], [32, 37], [32, 38], [32, 39], [32, 42], [33, 34], [33, 35], [33, 36], [33, 37], [33, 38], [33, 42], [34, 37], [34, 40], [34, 42], [34, 43], [35, 36], [35, 37], [35, 39], [35, 40], [36, 38], [36, 40], [36, 42], [37, 39], [37, 41], [37, 42], [37, 43], [38, 41], [38, 42], [38, 43], [39, 42], [40, 41], [40, 43], [41, 42], [41, 43]], "family": "rlve_maximum_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-maximum-clique-l5-s8/solution/solve.sh b/tasks/construct-rlve-maximum-clique-l5-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..00a269b5c58671d33d3c156e2a6fe96ad8534aec --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l5-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, 1, 2, 3, 14, 26, 40, 41]} +RLMATH_EOF diff --git a/tasks/construct-rlve-maximum-clique-l5-s8/tests/check.py b/tasks/construct-rlve-maximum-clique-l5-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..95e00c78f7c986ba3aecbdc8af3cf8ed221abd05 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l5-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-l5-s8/tests/instance.json b/tasks/construct-rlve-maximum-clique-l5-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1af3bdcd9f6403d1b8d4f4fcf9eeca095cea22ab --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l5-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 44, "k": 8, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 6], [0, 8], [0, 10], [0, 12], [0, 14], [0, 15], [0, 18], [0, 19], [0, 20], [0, 21], [0, 23], [0, 25], [0, 26], [0, 28], [0, 30], [0, 33], [0, 36], [0, 37], [0, 39], [0, 40], [0, 41], [0, 42], [1, 2], [1, 3], [1, 4], [1, 5], [1, 7], [1, 8], [1, 9], [1, 10], [1, 13], [1, 14], [1, 15], [1, 17], [1, 20], [1, 23], [1, 24], [1, 25], [1, 26], [1, 27], [1, 29], [1, 30], [1, 32], [1, 33], [1, 34], [1, 35], [1, 36], [1, 37], [1, 40], [1, 41], [1, 42], [2, 3], [2, 6], [2, 7], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 17], [2, 19], [2, 23], [2, 25], [2, 26], [2, 29], [2, 30], [2, 32], [2, 33], [2, 34], [2, 37], [2, 38], [2, 40], [2, 41], [2, 42], [3, 4], [3, 5], [3, 6], [3, 12], [3, 13], [3, 14], [3, 15], [3, 17], [3, 18], [3, 19], [3, 20], [3, 24], [3, 25], [3, 26], [3, 28], [3, 29], [3, 30], [3, 31], [3, 32], [3, 33], [3, 34], [3, 36], [3, 39], [3, 40], [3, 41], [4, 5], [4, 8], [4, 11], [4, 12], [4, 13], [4, 14], [4, 16], [4, 18], [4, 19], [4, 20], [4, 21], [4, 23], [4, 24], [4, 26], [4, 27], [4, 28], [4, 29], [4, 30], [4, 31], [4, 33], [4, 34], [4, 35], [4, 37], [4, 40], [4, 41], [4, 42], [4, 43], [5, 7], [5, 8], [5, 10], [5, 13], [5, 14], [5, 16], [5, 18], [5, 19], [5, 20], [5, 21], [5, 22], [5, 25], [5, 26], [5, 29], [5, 30], [5, 31], [5, 32], [5, 33], [5, 34], [5, 35], [5, 39], [5, 42], [6, 7], [6, 9], [6, 10], [6, 14], [6, 15], [6, 18], [6, 19], [6, 20], [6, 21], [6, 22], [6, 23], [6, 24], [6, 25], [6, 27], [6, 28], [6, 31], [6, 33], [6, 35], [6, 36], [6, 37], [6, 38], [6, 39], [6, 40], [6, 41], [7, 8], [7, 9], [7, 11], [7, 14], [7, 16], [7, 20], [7, 21], [7, 27], [7, 30], [7, 32], [7, 33], [7, 34], [7, 36], [7, 39], [7, 40], [7, 43], [8, 9], [8, 10], [8, 12], [8, 14], [8, 17], [8, 18], [8, 22], [8, 26], [8, 27], [8, 28], [8, 29], [8, 31], [8, 32], [8, 35], [8, 36], [8, 38], [8, 43], [9, 10], [9, 12], [9, 13], [9, 15], [9, 17], [9, 21], [9, 22], [9, 23], [9, 25], [9, 26], [9, 30], [9, 31], [9, 32], [9, 33], [9, 34], [9, 35], [9, 37], [9, 39], [9, 40], [9, 41], [9, 43], [10, 11], [10, 13], [10, 17], [10, 18], [10, 21], [10, 23], [10, 26], [10, 27], [10, 28], [10, 30], [10, 31], [10, 32], [10, 34], [10, 35], [10, 36], [10, 37], [10, 39], [10, 42], [10, 43], [11, 12], [11, 14], [11, 17], [11, 19], [11, 21], [11, 24], [11, 26], [11, 28], [11, 30], [11, 32], [11, 35], [11, 39], [11, 41], [11, 42], [12, 13], [12, 16], [12, 18], [12, 19], [12, 21], [12, 23], [12, 24], [12, 25], [12, 28], [12, 31], [12, 32], [12, 33], [12, 34], [12, 36], [12, 37], [12, 38], [12, 40], [12, 41], [13, 15], [13, 16], [13, 18], [13, 21], [13, 25], [13, 27], [13, 28], [13, 29], [13, 34], [13, 37], [13, 41], [13, 42], [14, 18], [14, 20], [14, 21], [14, 22], [14, 26], [14, 27], [14, 28], [14, 29], [14, 30], [14, 32], [14, 33], [14, 35], [14, 36], [14, 38], [14, 39], [14, 40], [14, 41], [14, 42], [14, 43], [15, 16], [15, 17], [15, 18], [15, 21], [15, 22], [15, 24], [15, 26], [15, 27], [15, 28], [15, 31], [15, 33], [15, 34], [15, 35], [15, 37], [15, 38], [15, 39], [15, 43], [16, 18], [16, 20], [16, 22], [16, 23], [16, 24], [16, 25], [16, 26], [16, 31], [16, 32], [16, 34], [16, 35], [16, 40], [16, 42], [16, 43], [17, 18], [17, 21], [17, 23], [17, 24], [17, 25], [17, 27], [17, 30], [17, 33], [17, 41], [17, 42], [17, 43], [18, 19], [18, 21], [18, 23], [18, 25], [18, 26], [18, 27], [18, 30], [18, 31], [18, 33], [18, 41], [18, 43], [19, 20], [19, 22], [19, 24], [19, 25], [19, 27], [19, 31], [19, 33], [19, 34], [19, 35], [19, 41], [19, 42], [20, 21], [20, 22], [20, 25], [20, 26], [20, 35], [20, 37], [20, 38], [20, 39], [20, 42], [20, 43], [21, 23], [21, 25], [21, 26], [21, 27], [21, 28], [21, 29], [21, 30], [21, 31], [21, 33], [21, 34], [21, 35], [21, 36], [21, 37], [21, 39], [21, 40], [21, 43], [22, 25], [22, 26], [22, 28], [22, 30], [22, 32], [22, 33], [22, 36], [22, 37], [22, 39], [22, 40], [22, 42], [22, 43], [23, 25], [23, 30], [23, 31], [23, 32], [23, 33], [23, 34], [23, 35], [23, 36], [23, 37], [23, 38], [23, 39], [23, 42], [24, 26], [24, 27], [24, 28], [24, 32], [24, 33], [24, 34], [24, 35], [24, 36], [24, 38], [24, 40], [24, 41], [25, 27], [25, 28], [25, 29], [25, 31], [25, 32], [25, 33], [25, 34], [25, 35], [25, 36], [25, 37], [26, 27], [26, 29], [26, 32], [26, 36], [26, 40], [26, 41], [27, 28], [27, 29], [27, 34], [27, 36], [27, 38], [27, 39], [28, 31], [28, 36], [28, 37], [28, 38], [28, 39], [28, 40], [28, 42], [29, 31], [29, 32], [29, 35], [29, 36], [29, 38], [29, 43], [30, 33], [30, 34], [30, 37], [30, 38], [30, 39], [31, 32], [31, 33], [31, 34], [31, 35], [31, 38], [31, 40], [31, 42], [31, 43], [32, 33], [32, 35], [32, 37], [32, 38], [32, 39], [32, 42], [33, 34], [33, 35], [33, 36], [33, 37], [33, 38], [33, 42], [34, 37], [34, 40], [34, 42], [34, 43], [35, 36], [35, 37], [35, 39], [35, 40], [36, 38], [36, 40], [36, 42], [37, 39], [37, 41], [37, 42], [37, 43], [38, 41], [38, 42], [38, 43], [39, 42], [40, 41], [40, 43], [41, 42], [41, 43]], "family": "rlve_maximum_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-maximum-clique-l5-s8/tests/run.py b/tasks/construct-rlve-maximum-clique-l5-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l5-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-l5-s8/tests/test.sh b/tasks/construct-rlve-maximum-clique-l5-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l5-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-chromatic-number-l6-s2/environment/Dockerfile b/tasks/construct-rlve-min-chromatic-number-l6-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l6-s2/environment/instance.json b/tasks/construct-rlve-min-chromatic-number-l6-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..853a332c3a7c2110139bcfca4991aed3ee147325 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l6-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 30, "k": 11, "edges": [[0, 1], [0, 2], [0, 5], [0, 6], [0, 8], [0, 10], [0, 11], [0, 12], [0, 14], [0, 15], [0, 16], [0, 17], [0, 18], [0, 20], [0, 21], [0, 22], [0, 23], [0, 24], [0, 25], [0, 26], [0, 27], [0, 28], [1, 2], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 16], [1, 17], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 23], [1, 24], [1, 25], [1, 26], [1, 27], [1, 29], [2, 5], [2, 6], [2, 7], [2, 10], [2, 11], [2, 12], [2, 13], [2, 16], [2, 17], [2, 18], [2, 20], [2, 23], [2, 25], [2, 26], [2, 27], [2, 29], [3, 4], [3, 5], [3, 6], [3, 7], [3, 10], [3, 11], [3, 12], [3, 13], [3, 14], [3, 16], [3, 17], [3, 18], [3, 19], [3, 20], [3, 21], [3, 22], [3, 24], [3, 25], [3, 26], [3, 27], [3, 28], [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], [4, 21], [4, 22], [4, 23], [4, 24], [4, 25], [4, 26], [4, 27], [4, 28], [4, 29], [5, 7], [5, 9], [5, 10], [5, 12], [5, 13], [5, 14], [5, 16], [5, 17], [5, 18], [5, 19], [5, 20], [5, 21], [5, 22], [5, 23], [5, 26], [5, 27], [5, 28], [5, 29], [6, 7], [6, 8], [6, 10], [6, 11], [6, 12], [6, 13], [6, 14], [6, 15], [6, 16], [6, 17], [6, 20], [6, 23], [6, 25], [6, 26], [6, 27], [6, 28], [6, 29], [7, 10], [7, 12], [7, 14], [7, 15], [7, 16], [7, 19], [7, 20], [7, 21], [7, 22], [7, 23], [7, 24], [7, 25], [7, 27], [7, 28], [7, 29], [8, 9], [8, 10], [8, 11], [8, 13], [8, 14], [8, 15], [8, 16], [8, 20], [8, 21], [8, 22], [8, 23], [8, 24], [8, 25], [8, 26], [8, 27], [8, 28], [8, 29], [9, 11], [9, 12], [9, 14], [9, 15], [9, 16], [9, 18], [9, 19], [9, 20], [9, 21], [9, 24], [9, 25], [9, 27], [9, 29], [10, 11], [10, 12], [10, 13], [10, 16], [10, 17], [10, 18], [10, 19], [10, 20], [10, 21], [10, 22], [10, 23], [10, 25], [10, 28], [11, 12], [11, 13], [11, 14], [11, 15], [11, 16], [11, 17], [11, 19], [11, 20], [11, 21], [11, 23], [11, 24], [11, 25], [11, 26], [11, 27], [11, 28], [11, 29], [12, 13], [12, 14], [12, 15], [12, 16], [12, 17], [12, 18], [12, 19], [12, 20], [12, 21], [12, 22], [12, 24], [12, 28], [12, 29], [13, 14], [13, 16], [13, 17], [13, 18], [13, 19], [13, 20], [13, 21], [13, 22], [13, 23], [13, 25], [13, 26], [13, 27], [13, 28], [13, 29], [14, 15], [14, 16], [14, 17], [14, 18], [14, 19], [14, 20], [14, 21], [14, 22], [14, 23], [14, 27], [14, 28], [14, 29], [15, 16], [15, 19], [15, 20], [15, 21], [15, 23], [15, 24], [15, 26], [15, 27], [15, 28], [16, 17], [16, 19], [16, 20], [16, 21], [16, 22], [16, 23], [16, 25], [16, 26], [16, 29], [17, 18], [17, 20], [17, 21], [17, 23], [17, 24], [17, 28], [17, 29], [18, 20], [18, 21], [18, 23], [18, 25], [18, 27], [18, 28], [18, 29], [19, 20], [19, 21], [19, 23], [19, 25], [19, 27], [19, 28], [19, 29], [20, 21], [20, 23], [20, 24], [20, 25], [20, 26], [20, 27], [21, 23], [21, 24], [21, 26], [21, 27], [21, 28], [22, 25], [22, 27], [22, 28], [22, 29], [23, 24], [23, 25], [23, 29], [24, 25], [24, 27], [24, 28], [24, 29], [25, 26], [25, 27], [25, 28], [25, 29], [26, 27], [26, 28], [26, 29], [27, 29], [28, 29]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l6-s2/solution/solve.sh b/tasks/construct-rlve-min-chromatic-number-l6-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..eaf6e7dcaa3ca8a7b9b5be5482fd05a0a8429d05 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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' +{"colors": [0, 1, 2, 1, 2, 3, 3, 0, 4, 0, 5, 6, 7, 0, 5, 1, 8, 4, 6, 4, 9, 10, 6, 7, 3, 10, 5, 7, 8, 9]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-chromatic-number-l6-s2/tests/check.py b/tasks/construct-rlve-min-chromatic-number-l6-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d2b77793fb15e0d97174b3c28e69a86e2a26996f --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l6-s2/tests/check.py @@ -0,0 +1,10 @@ +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") + 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-rlve-min-chromatic-number-l6-s2/tests/instance.json b/tasks/construct-rlve-min-chromatic-number-l6-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..853a332c3a7c2110139bcfca4991aed3ee147325 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l6-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 30, "k": 11, "edges": [[0, 1], [0, 2], [0, 5], [0, 6], [0, 8], [0, 10], [0, 11], [0, 12], [0, 14], [0, 15], [0, 16], [0, 17], [0, 18], [0, 20], [0, 21], [0, 22], [0, 23], [0, 24], [0, 25], [0, 26], [0, 27], [0, 28], [1, 2], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 16], [1, 17], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 23], [1, 24], [1, 25], [1, 26], [1, 27], [1, 29], [2, 5], [2, 6], [2, 7], [2, 10], [2, 11], [2, 12], [2, 13], [2, 16], [2, 17], [2, 18], [2, 20], [2, 23], [2, 25], [2, 26], [2, 27], [2, 29], [3, 4], [3, 5], [3, 6], [3, 7], [3, 10], [3, 11], [3, 12], [3, 13], [3, 14], [3, 16], [3, 17], [3, 18], [3, 19], [3, 20], [3, 21], [3, 22], [3, 24], [3, 25], [3, 26], [3, 27], [3, 28], [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], [4, 21], [4, 22], [4, 23], [4, 24], [4, 25], [4, 26], [4, 27], [4, 28], [4, 29], [5, 7], [5, 9], [5, 10], [5, 12], [5, 13], [5, 14], [5, 16], [5, 17], [5, 18], [5, 19], [5, 20], [5, 21], [5, 22], [5, 23], [5, 26], [5, 27], [5, 28], [5, 29], [6, 7], [6, 8], [6, 10], [6, 11], [6, 12], [6, 13], [6, 14], [6, 15], [6, 16], [6, 17], [6, 20], [6, 23], [6, 25], [6, 26], [6, 27], [6, 28], [6, 29], [7, 10], [7, 12], [7, 14], [7, 15], [7, 16], [7, 19], [7, 20], [7, 21], [7, 22], [7, 23], [7, 24], [7, 25], [7, 27], [7, 28], [7, 29], [8, 9], [8, 10], [8, 11], [8, 13], [8, 14], [8, 15], [8, 16], [8, 20], [8, 21], [8, 22], [8, 23], [8, 24], [8, 25], [8, 26], [8, 27], [8, 28], [8, 29], [9, 11], [9, 12], [9, 14], [9, 15], [9, 16], [9, 18], [9, 19], [9, 20], [9, 21], [9, 24], [9, 25], [9, 27], [9, 29], [10, 11], [10, 12], [10, 13], [10, 16], [10, 17], [10, 18], [10, 19], [10, 20], [10, 21], [10, 22], [10, 23], [10, 25], [10, 28], [11, 12], [11, 13], [11, 14], [11, 15], [11, 16], [11, 17], [11, 19], [11, 20], [11, 21], [11, 23], [11, 24], [11, 25], [11, 26], [11, 27], [11, 28], [11, 29], [12, 13], [12, 14], [12, 15], [12, 16], [12, 17], [12, 18], [12, 19], [12, 20], [12, 21], [12, 22], [12, 24], [12, 28], [12, 29], [13, 14], [13, 16], [13, 17], [13, 18], [13, 19], [13, 20], [13, 21], [13, 22], [13, 23], [13, 25], [13, 26], [13, 27], [13, 28], [13, 29], [14, 15], [14, 16], [14, 17], [14, 18], [14, 19], [14, 20], [14, 21], [14, 22], [14, 23], [14, 27], [14, 28], [14, 29], [15, 16], [15, 19], [15, 20], [15, 21], [15, 23], [15, 24], [15, 26], [15, 27], [15, 28], [16, 17], [16, 19], [16, 20], [16, 21], [16, 22], [16, 23], [16, 25], [16, 26], [16, 29], [17, 18], [17, 20], [17, 21], [17, 23], [17, 24], [17, 28], [17, 29], [18, 20], [18, 21], [18, 23], [18, 25], [18, 27], [18, 28], [18, 29], [19, 20], [19, 21], [19, 23], [19, 25], [19, 27], [19, 28], [19, 29], [20, 21], [20, 23], [20, 24], [20, 25], [20, 26], [20, 27], [21, 23], [21, 24], [21, 26], [21, 27], [21, 28], [22, 25], [22, 27], [22, 28], [22, 29], [23, 24], [23, 25], [23, 29], [24, 25], [24, 27], [24, 28], [24, 29], [25, 26], [25, 27], [25, 28], [25, 29], [26, 27], [26, 28], [26, 29], [27, 29], [28, 29]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l6-s2/tests/run.py b/tasks/construct-rlve-min-chromatic-number-l6-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l6-s2/tests/test.sh b/tasks/construct-rlve-min-chromatic-number-l6-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l6-s5/environment/Dockerfile b/tasks/construct-rlve-min-chromatic-number-l6-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l6-s5/environment/instance.json b/tasks/construct-rlve-min-chromatic-number-l6-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..259d0938c6c6436962da6c2a87e71b7604494231 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l6-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 30, "k": 4, "edges": [[0, 1], [0, 2], [0, 4], [0, 8], [0, 9], [0, 13], [0, 18], [0, 19], [0, 22], [0, 28], [1, 2], [1, 6], [1, 7], [1, 9], [1, 15], [1, 21], [1, 23], [1, 27], [2, 7], [2, 10], [2, 12], [2, 23], [2, 24], [3, 14], [3, 16], [3, 19], [3, 23], [3, 25], [4, 7], [4, 8], [4, 10], [4, 15], [4, 23], [4, 28], [5, 11], [5, 15], [5, 25], [5, 27], [6, 19], [6, 20], [6, 23], [6, 25], [7, 8], [7, 16], [7, 24], [7, 27], [8, 10], [8, 16], [8, 22], [9, 10], [9, 17], [9, 21], [9, 23], [10, 13], [10, 14], [10, 17], [10, 21], [10, 26], [10, 29], [11, 13], [11, 14], [11, 15], [11, 16], [11, 17], [11, 19], [11, 25], [11, 29], [12, 14], [12, 22], [12, 26], [12, 27], [12, 28], [12, 29], [13, 14], [13, 17], [14, 19], [14, 27], [15, 19], [15, 23], [15, 24], [16, 18], [16, 19], [16, 20], [16, 21], [16, 28], [16, 29], [17, 25], [17, 26], [18, 21], [18, 22], [18, 24], [18, 26], [18, 29], [19, 23], [19, 28], [20, 21], [20, 23], [20, 27], [21, 22], [22, 26], [24, 25], [24, 26], [24, 27], [24, 28], [25, 26], [25, 28], [26, 29], [27, 28]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l6-s5/solution/solve.sh b/tasks/construct-rlve-min-chromatic-number-l6-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0f8091dddf347082287cde53800f6c63430e3647 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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' +{"colors": [0, 1, 2, 2, 1, 1, 2, 3, 2, 2, 3, 0, 3, 2, 1, 2, 1, 1, 3, 3, 3, 0, 1, 0, 1, 3, 0, 0, 2, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-chromatic-number-l6-s5/tests/check.py b/tasks/construct-rlve-min-chromatic-number-l6-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d2b77793fb15e0d97174b3c28e69a86e2a26996f --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l6-s5/tests/check.py @@ -0,0 +1,10 @@ +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") + 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-rlve-min-chromatic-number-l6-s5/tests/instance.json b/tasks/construct-rlve-min-chromatic-number-l6-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..259d0938c6c6436962da6c2a87e71b7604494231 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l6-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 30, "k": 4, "edges": [[0, 1], [0, 2], [0, 4], [0, 8], [0, 9], [0, 13], [0, 18], [0, 19], [0, 22], [0, 28], [1, 2], [1, 6], [1, 7], [1, 9], [1, 15], [1, 21], [1, 23], [1, 27], [2, 7], [2, 10], [2, 12], [2, 23], [2, 24], [3, 14], [3, 16], [3, 19], [3, 23], [3, 25], [4, 7], [4, 8], [4, 10], [4, 15], [4, 23], [4, 28], [5, 11], [5, 15], [5, 25], [5, 27], [6, 19], [6, 20], [6, 23], [6, 25], [7, 8], [7, 16], [7, 24], [7, 27], [8, 10], [8, 16], [8, 22], [9, 10], [9, 17], [9, 21], [9, 23], [10, 13], [10, 14], [10, 17], [10, 21], [10, 26], [10, 29], [11, 13], [11, 14], [11, 15], [11, 16], [11, 17], [11, 19], [11, 25], [11, 29], [12, 14], [12, 22], [12, 26], [12, 27], [12, 28], [12, 29], [13, 14], [13, 17], [14, 19], [14, 27], [15, 19], [15, 23], [15, 24], [16, 18], [16, 19], [16, 20], [16, 21], [16, 28], [16, 29], [17, 25], [17, 26], [18, 21], [18, 22], [18, 24], [18, 26], [18, 29], [19, 23], [19, 28], [20, 21], [20, 23], [20, 27], [21, 22], [22, 26], [24, 25], [24, 26], [24, 27], [24, 28], [25, 26], [25, 28], [26, 29], [27, 28]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l6-s5/tests/run.py b/tasks/construct-rlve-min-chromatic-number-l6-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l6-s5/tests/test.sh b/tasks/construct-rlve-min-chromatic-number-l6-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-harmonious-coloring-l2-s0/environment/Dockerfile b/tasks/construct-rlve-min-harmonious-coloring-l2-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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-min-harmonious-coloring-l2-s0/environment/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l2-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..361ac1ddad72279ee6c53f7c29f97427a7b1ce94 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l2-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 5, "edges": [[0, 4], [1, 4], [1, 5], [1, 6], [2, 7], [4, 6], [4, 7], [6, 7]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l2-s0/solution/solve.sh b/tasks/construct-rlve-min-harmonious-coloring-l2-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..03f6a5b0031a45192bd3f90e2fd7c454ef92be97 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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": [0, 1, 0, 0, 2, 0, 3, 4]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-harmonious-coloring-l2-s0/tests/check.py b/tasks/construct-rlve-min-harmonious-coloring-l2-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..91282a31c765b6103e6575180adb47abddb6a506 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l2-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-l2-s0/tests/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l2-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..361ac1ddad72279ee6c53f7c29f97427a7b1ce94 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l2-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 5, "edges": [[0, 4], [1, 4], [1, 5], [1, 6], [2, 7], [4, 6], [4, 7], [6, 7]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l2-s0/tests/run.py b/tasks/construct-rlve-min-harmonious-coloring-l2-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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-min-harmonious-coloring-l2-s0/tests/test.sh b/tasks/construct-rlve-min-harmonious-coloring-l2-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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-min-harmonious-coloring-l2-s7/environment/Dockerfile b/tasks/construct-rlve-min-harmonious-coloring-l2-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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-min-harmonious-coloring-l2-s7/environment/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l2-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8e1c0f223aadb2819d4973612ce1f2b44089937f --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l2-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 5, "edges": [[0, 4], [0, 6], [1, 3], [1, 7], [2, 4], [2, 5], [3, 7]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l2-s7/solution/solve.sh b/tasks/construct-rlve-min-harmonious-coloring-l2-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e9fa39d0710648755b6e43f6d44925ffc61bc982 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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": [0, 0, 1, 1, 2, 3, 3, 4]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-harmonious-coloring-l2-s7/tests/check.py b/tasks/construct-rlve-min-harmonious-coloring-l2-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..91282a31c765b6103e6575180adb47abddb6a506 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l2-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-l2-s7/tests/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l2-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8e1c0f223aadb2819d4973612ce1f2b44089937f --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l2-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 5, "edges": [[0, 4], [0, 6], [1, 3], [1, 7], [2, 4], [2, 5], [3, 7]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l2-s7/tests/run.py b/tasks/construct-rlve-min-harmonious-coloring-l2-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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-min-harmonious-coloring-l2-s7/tests/test.sh b/tasks/construct-rlve-min-harmonious-coloring-l2-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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-min-harmonious-coloring-l6-s8/environment/Dockerfile b/tasks/construct-rlve-min-harmonious-coloring-l6-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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-min-harmonious-coloring-l6-s8/environment/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l6-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d65b55f37ee3b8ae0534eebde330004a1422824e --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l6-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 18, "k": 9, "edges": [[0, 3], [0, 7], [0, 9], [1, 6], [1, 10], [1, 13], [2, 4], [2, 5], [3, 6], [3, 7], [3, 15], [4, 12], [4, 13], [4, 14], [5, 11], [6, 9], [6, 13], [6, 15], [7, 15], [7, 16], [8, 17], [9, 17], [10, 11], [10, 14], [10, 15], [11, 14], [12, 13], [12, 16], [13, 16], [15, 16]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l6-s8/solution/solve.sh b/tasks/construct-rlve-min-harmonious-coloring-l6-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c12ae822bdd02e44fc34c67849ed1d192cf02831 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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": [0, 0, 0, 1, 2, 3, 4, 5, 1, 6, 7, 8, 1, 8, 5, 3, 6, 7]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-harmonious-coloring-l6-s8/tests/check.py b/tasks/construct-rlve-min-harmonious-coloring-l6-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..91282a31c765b6103e6575180adb47abddb6a506 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l6-s8/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-l6-s8/tests/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l6-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d65b55f37ee3b8ae0534eebde330004a1422824e --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l6-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 18, "k": 9, "edges": [[0, 3], [0, 7], [0, 9], [1, 6], [1, 10], [1, 13], [2, 4], [2, 5], [3, 6], [3, 7], [3, 15], [4, 12], [4, 13], [4, 14], [5, 11], [6, 9], [6, 13], [6, 15], [7, 15], [7, 16], [8, 17], [9, 17], [10, 11], [10, 14], [10, 15], [11, 14], [12, 13], [12, 16], [13, 16], [15, 16]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l6-s8/tests/run.py b/tasks/construct-rlve-min-harmonious-coloring-l6-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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-min-harmonious-coloring-l6-s8/tests/test.sh b/tasks/construct-rlve-min-harmonious-coloring-l6-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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-pairwise-sums-recovery-l4-s8/environment/Dockerfile b/tasks/construct-rlve-pairwise-sums-recovery-l4-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l4-s8/environment/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l4-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a6bc7bde125bc276f844c0573fb8160b5a77cfd4 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l4-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 12, "sums": [38, 33, 32, 26, 27, 13, 19, 21, 29, 34, 43, 19, 25, 25, 25, 26, 27, 34, 20, 32, 39, 41, 20, 29, 26, 26, 17, 45, 24, 15, 21, 13, 30, 20, 33, 21, 35, 18, 28, 12, 46, 40, 39, 40, 24, 31, 31, 25, 32, 28, 19, 22, 12, 11, 27, 33, 28, 37, 42, 38, 27, 30, 14, 35, 7, 14], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l4-s8/solution/solve.sh b/tasks/construct-rlve-pairwise-sums-recovery-l4-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..931281d08275317209c603a288bb702f76946340 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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' +{"numbers": [3, 4, 8, 9, 10, 11, 16, 17, 18, 21, 22, 24]} +RLMATH_EOF diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l4-s8/tests/check.py b/tasks/construct-rlve-pairwise-sums-recovery-l4-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..01b5b475e927688c0209fb93478a95f6dd1d3407 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l4-s8/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-l4-s8/tests/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l4-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a6bc7bde125bc276f844c0573fb8160b5a77cfd4 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l4-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 12, "sums": [38, 33, 32, 26, 27, 13, 19, 21, 29, 34, 43, 19, 25, 25, 25, 26, 27, 34, 20, 32, 39, 41, 20, 29, 26, 26, 17, 45, 24, 15, 21, 13, 30, 20, 33, 21, 35, 18, 28, 12, 46, 40, 39, 40, 24, 31, 31, 25, 32, 28, 19, 22, 12, 11, 27, 33, 28, 37, 42, 38, 27, 30, 14, 35, 7, 14], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l4-s8/tests/run.py b/tasks/construct-rlve-pairwise-sums-recovery-l4-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l4-s8/tests/test.sh b/tasks/construct-rlve-pairwise-sums-recovery-l4-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pan-solar-panels-l1-s2/environment/Dockerfile b/tasks/construct-rlve-pan-solar-panels-l1-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l1-s2/environment/instance.json b/tasks/construct-rlve-pan-solar-panels-l1-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f21c6c3448d85138cbedcb8d477dce90d18724c7 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l1-s2/environment/instance.json @@ -0,0 +1 @@ +{"A": 27, "B": 46, "C": 1, "D": 20, "target": 20, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l1-s2/solution/solve.sh b/tasks/construct-rlve-pan-solar-panels-l1-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a109fd0657d951c864c5cb83daf584b251b55d4a --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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' +{"X": 40, "Y": 20} +RLMATH_EOF diff --git a/tasks/construct-rlve-pan-solar-panels-l1-s2/tests/check.py b/tasks/construct-rlve-pan-solar-panels-l1-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8bb2e7cc0b0280ab877755cc5d97b510680f7aa3 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l1-s2/tests/check.py @@ -0,0 +1,12 @@ +import math + +from run import Invalid, as_int + + +def check(inst, ans): + X = as_int(ans.get("X"), "X", lo=inst["A"], hi=inst["B"]) + Y = as_int(ans.get("Y"), "Y", lo=inst["C"], hi=inst["D"]) + g = math.gcd(X, Y) + if g < inst["target"]: + raise Invalid(f"gcd(X, Y) = {g} < {inst['target']}") + return None, {"gcd": g} diff --git a/tasks/construct-rlve-pan-solar-panels-l1-s2/tests/instance.json b/tasks/construct-rlve-pan-solar-panels-l1-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f21c6c3448d85138cbedcb8d477dce90d18724c7 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l1-s2/tests/instance.json @@ -0,0 +1 @@ +{"A": 27, "B": 46, "C": 1, "D": 20, "target": 20, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l1-s2/tests/run.py b/tasks/construct-rlve-pan-solar-panels-l1-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l1-s2/tests/test.sh b/tasks/construct-rlve-pan-solar-panels-l1-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l1-s5/environment/Dockerfile b/tasks/construct-rlve-pan-solar-panels-l1-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l1-s5/environment/instance.json b/tasks/construct-rlve-pan-solar-panels-l1-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2b11f2895cc0534f3f69c8bce2e973417a4c606c --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l1-s5/environment/instance.json @@ -0,0 +1 @@ +{"A": 36, "B": 37, "C": 40, "D": 49, "target": 12, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l1-s5/solution/solve.sh b/tasks/construct-rlve-pan-solar-panels-l1-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5aa0f800969a37cd8789f67795e5995562ab7c3b --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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' +{"X": 36, "Y": 48} +RLMATH_EOF diff --git a/tasks/construct-rlve-pan-solar-panels-l1-s5/tests/check.py b/tasks/construct-rlve-pan-solar-panels-l1-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8bb2e7cc0b0280ab877755cc5d97b510680f7aa3 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l1-s5/tests/check.py @@ -0,0 +1,12 @@ +import math + +from run import Invalid, as_int + + +def check(inst, ans): + X = as_int(ans.get("X"), "X", lo=inst["A"], hi=inst["B"]) + Y = as_int(ans.get("Y"), "Y", lo=inst["C"], hi=inst["D"]) + g = math.gcd(X, Y) + if g < inst["target"]: + raise Invalid(f"gcd(X, Y) = {g} < {inst['target']}") + return None, {"gcd": g} diff --git a/tasks/construct-rlve-pan-solar-panels-l1-s5/tests/instance.json b/tasks/construct-rlve-pan-solar-panels-l1-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2b11f2895cc0534f3f69c8bce2e973417a4c606c --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l1-s5/tests/instance.json @@ -0,0 +1 @@ +{"A": 36, "B": 37, "C": 40, "D": 49, "target": 12, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l1-s5/tests/run.py b/tasks/construct-rlve-pan-solar-panels-l1-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l1-s5/tests/test.sh b/tasks/construct-rlve-pan-solar-panels-l1-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-polynomial-global-minimum-l4-s0/environment/Dockerfile b/tasks/construct-rlve-polynomial-global-minimum-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l4-s0/environment/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..20b511c0946e2b4767b9fe006c5ac55f127b526c --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [86, -236, 321, -280, 201, -124, 57, -16, 2], "fmin": "10.7964631124392756531309803147488454831222998", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l4-s0/solution/solve.sh b/tasks/construct-rlve-polynomial-global-minimum-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..de48253851c1bb4c87f17e2b78e09df20ca48ae4 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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' +{"x0": 1.1083662058643997} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-global-minimum-l4-s0/tests/check.py b/tasks/construct-rlve-polynomial-global-minimum-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3be068f4391ad0838c29a4f7d521b8072cf39991 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l4-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-l4-s0/tests/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..20b511c0946e2b4767b9fe006c5ac55f127b526c --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [86, -236, 321, -280, 201, -124, 57, -16, 2], "fmin": "10.7964631124392756531309803147488454831222998", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l4-s0/tests/run.py b/tasks/construct-rlve-polynomial-global-minimum-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l4-s0/tests/test.sh b/tasks/construct-rlve-polynomial-global-minimum-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l4-s7/environment/Dockerfile b/tasks/construct-rlve-polynomial-global-minimum-l4-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l4-s7/environment/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l4-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..570287a12d8756e6408babbe6e8c69f62a2f6d5b --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l4-s7/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [387, 1402, 2285, 2104, 1242, 472, 114, 16, 1], "fmin": "31.0969928359091970896203059480734214435088796", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l4-s7/solution/solve.sh b/tasks/construct-rlve-polynomial-global-minimum-l4-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9f1dcbd59c82c02c96dec536aa0a8f98fdfc28f6 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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' +{"x0": -0.8348559318962129} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-global-minimum-l4-s7/tests/check.py b/tasks/construct-rlve-polynomial-global-minimum-l4-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3be068f4391ad0838c29a4f7d521b8072cf39991 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l4-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-l4-s7/tests/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l4-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..570287a12d8756e6408babbe6e8c69f62a2f6d5b --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l4-s7/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [387, 1402, 2285, 2104, 1242, 472, 114, 16, 1], "fmin": "31.0969928359091970896203059480734214435088796", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l4-s7/tests/run.py b/tasks/construct-rlve-polynomial-global-minimum-l4-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l4-s7/tests/test.sh b/tasks/construct-rlve-polynomial-global-minimum-l4-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-integer-roots-l3-s2/environment/Dockerfile b/tasks/construct-rlve-polynomial-integer-roots-l3-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-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-l3-s2/environment/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l3-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0ff752ee248057e038893a28633ee633a728e7ff --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-s2/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [-79380, 165564, -118737, 36180, -2873, -1012, 285, -28, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l3-s2/solution/solve.sh b/tasks/construct-rlve-polynomial-integer-roots-l3-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f8def504f384923362dd19a7d1433f983e1cebf --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-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": [-5, 1, 3, 3, 6, 6, 7, 7]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-integer-roots-l3-s2/tests/check.py b/tasks/construct-rlve-polynomial-integer-roots-l3-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2d30553cb884c5e03c8afe73ef652efc483ab791 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-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-l3-s2/tests/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l3-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0ff752ee248057e038893a28633ee633a728e7ff --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-s2/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [-79380, 165564, -118737, 36180, -2873, -1012, 285, -28, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l3-s2/tests/run.py b/tasks/construct-rlve-polynomial-integer-roots-l3-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-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-l3-s2/tests/test.sh b/tasks/construct-rlve-polynomial-integer-roots-l3-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-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-integer-roots-l3-s5/environment/Dockerfile b/tasks/construct-rlve-polynomial-integer-roots-l3-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-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-polynomial-integer-roots-l3-s5/environment/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l3-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a54bf4d078ab4f7187b24127024c9c8b1b3e61e4 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-s5/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [-105840, 21798, 69009, 18128, -2001, -1058, -49, 12, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l3-s5/solution/solve.sh b/tasks/construct-rlve-polynomial-integer-roots-l3-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ae6d2999d111c6406179b4eb48be59b120367464 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-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' +{"roots": [-7, -7, -6, -3, -3, 1, 5, 8]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-integer-roots-l3-s5/tests/check.py b/tasks/construct-rlve-polynomial-integer-roots-l3-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2d30553cb884c5e03c8afe73ef652efc483ab791 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-s5/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-l3-s5/tests/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l3-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a54bf4d078ab4f7187b24127024c9c8b1b3e61e4 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-s5/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [-105840, 21798, 69009, 18128, -2001, -1058, -49, 12, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l3-s5/tests/run.py b/tasks/construct-rlve-polynomial-integer-roots-l3-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-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-polynomial-integer-roots-l3-s5/tests/test.sh b/tasks/construct-rlve-polynomial-integer-roots-l3-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-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-prefix-product-permutation-l4-s9/environment/Dockerfile b/tasks/construct-rlve-prefix-product-permutation-l4-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-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-prefix-product-permutation-l4-s9/environment/instance.json b/tasks/construct-rlve-prefix-product-permutation-l4-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..dd751c50076ed7a2d104e92b288a4ce1f5fe1694 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l4-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 601, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l4-s9/solution/solve.sh b/tasks/construct-rlve-prefix-product-permutation-l4-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9bd00159a6a0d225b2e1bac628770e5b7b5461b9 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-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' +{"perm": [1, 2, 302, 402, 452, 482, 502, 87, 527, 335, 542, 165, 552, 186, 44, 562, 264, 496, 168, 349, 572, 230, 83, 393, 577, 578, 394, 513, 323, 229, 582, 350, 433, 256, 549, 499, 385, 66, 175, 263, 587, 45, 416, 15, 42, 188, 197, 423, 289, 185, 590, 166, 498, 568, 257, 154, 162, 117, 115, 164, 592, 336, 476, 478, 217, 38, 429, 306, 275, 332, 250, 365, 193, 248, 334, 594, 88, 282, 132, 389, 294, 372, 23, 211, 509, 100, 8, 77, 322, 575, 395, 285, 99, 518, 212, 311, 145, 317, 93, 86, 596, 483, 384, 567, 550, 167, 585, 265, 129, 398, 378, 223, 382, 485, 59, 440, 58, 489, 383, 501, 597, 453, 469, 216, 539, 477, 540, 337, 109, 206, 320, 79, 215, 480, 454, 464, 138, 137, 467, 455, 426, 342, 183, 291, 97, 287, 425, 463, 468, 481, 598, 403, 345, 56, 442, 191, 367, 246, 195, 190, 448, 57, 487, 60, 12, 52, 106, 19, 255, 570, 351, 240, 305, 536, 39, 341, 462, 456, 288, 555, 198, 260, 143, 313, 50, 14, 560, 46, 407, 160, 156, 237, 73, 356, 159, 414, 47, 181, 344, 451, 599, 303, 242, 377, 493, 130, 284, 512, 576, 579, 84, 95, 293, 523, 133, 124, 65, 566, 500, 484, 490, 224, 112, 222, 492, 399, 243, 279, 30, 22, 521, 295, 330, 277, 245, 446, 192, 531, 251, 172, 299, 203, 227, 325, 235, 158, 409, 74, 270, 71, 239, 432, 571, 583, 169, 34, 55, 450, 404, 182, 461, 427, 40, 17, 108, 475, 541, 593, 528, 249, 533, 276, 370, 296, 69, 272, 234, 359, 228, 574, 514, 78, 472, 207, 92, 505, 146, 179, 49, 419, 144, 507, 213, 81, 232, 274, 535, 430, 241, 401, 600, 3, 202, 362, 173, 68, 329, 371, 522, 390, 96, 459, 184, 554, 424, 457, 98, 511, 396, 131, 525, 89, 29, 375, 244, 369, 331, 534, 307, 233, 327, 70, 354, 75, 10, 62, 128, 495, 586, 563, 176, 142, 421, 199, 153, 548, 569, 434, 20, 32, 171, 364, 532, 333, 529, 194, 445, 368, 278, 376, 400, 304, 431, 352, 72, 411, 157, 358, 326, 273, 308, 82, 581, 573, 324, 360, 204, 111, 381, 491, 379, 113, 119, 103, 37, 538, 479, 470, 80, 310, 508, 519, 24, 27, 91, 319, 473, 110, 226, 361, 300, 4, 152, 259, 422, 556, 189, 444, 247, 530, 366, 447, 443, 196, 557, 43, 589, 553, 290, 460, 343, 405, 48, 315, 147, 141, 262, 564, 67, 298, 363, 252, 33, 348, 584, 497, 551, 591, 543, 116, 546, 155, 413, 408, 357, 236, 412, 161, 547, 258, 200, 5, 122, 135, 140, 178, 316, 506, 312, 420, 261, 177, 148, 136, 466, 465, 139, 149, 123, 388, 524, 283, 397, 494, 266, 63, 126, 64, 387, 134, 150, 6, 102, 220, 114, 545, 163, 544, 118, 221, 380, 225, 205, 474, 338, 18, 436, 53, 36, 219, 120, 7, 517, 510, 286, 458, 292, 391, 85, 504, 318, 208, 28, 281, 526, 595, 503, 94, 392, 580, 231, 309, 214, 471, 321, 515, 9, 269, 355, 410, 238, 353, 271, 328, 297, 174, 565, 386, 125, 127, 267, 11, 439, 488, 486, 441, 449, 346, 35, 105, 437, 13, 418, 314, 180, 406, 415, 561, 588, 187, 558, 16, 340, 428, 537, 218, 104, 54, 347, 170, 253, 21, 374, 280, 90, 209, 25, 26, 210, 520, 373, 31, 254, 435, 107, 339, 41, 559, 417, 51, 438, 61, 268, 76, 516, 101, 121, 151, 201, 301, 601]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-product-permutation-l4-s9/tests/check.py b/tasks/construct-rlve-prefix-product-permutation-l4-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3d93850acd79cc0f8fff05cdbb0c63aabc484815 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l4-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-l4-s9/tests/instance.json b/tasks/construct-rlve-prefix-product-permutation-l4-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..dd751c50076ed7a2d104e92b288a4ce1f5fe1694 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l4-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 601, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l4-s9/tests/run.py b/tasks/construct-rlve-prefix-product-permutation-l4-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-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-prefix-product-permutation-l4-s9/tests/test.sh b/tasks/construct-rlve-prefix-product-permutation-l4-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-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-prefix-sum-permutation-l1-s9/environment/Dockerfile b/tasks/construct-rlve-prefix-sum-permutation-l1-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l1-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-sum-permutation-l1-s9/environment/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l1-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f515a746b1db701e25f5e6b22ab825f2a53d9373 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l1-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 28, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l1-s9/solution/solve.sh b/tasks/construct-rlve-prefix-sum-permutation-l1-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a875c8c99c0990ecc7f42f0e6d001b96d0b70ff1 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l1-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": [28, 1, 26, 3, 24, 5, 22, 7, 20, 9, 18, 11, 16, 13, 14, 15, 12, 17, 10, 19, 8, 21, 6, 23, 4, 25, 2, 27]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-sum-permutation-l1-s9/tests/check.py b/tasks/construct-rlve-prefix-sum-permutation-l1-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..60c3e0996cdfa8673fd7f34ad70cccb789b17654 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l1-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(), 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-l1-s9/tests/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l1-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f515a746b1db701e25f5e6b22ab825f2a53d9373 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l1-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 28, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l1-s9/tests/run.py b/tasks/construct-rlve-prefix-sum-permutation-l1-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l1-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-sum-permutation-l1-s9/tests/test.sh b/tasks/construct-rlve-prefix-sum-permutation-l1-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l1-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-sum-permutation-l5-s1/environment/Dockerfile b/tasks/construct-rlve-prefix-sum-permutation-l5-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-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-rlve-prefix-sum-permutation-l5-s1/environment/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l5-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9a0e43c25035f34824f1fa548c47db4b0fc26af9 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l5-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 8170, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l5-s1/solution/solve.sh b/tasks/construct-rlve-prefix-sum-permutation-l5-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..132a40fc7c88aae0f2ff3d6766ec592cdee17828 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-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' +{"perm": [8170, 1, 8168, 3, 8166, 5, 8164, 7, 8162, 9, 8160, 11, 8158, 13, 8156, 15, 8154, 17, 8152, 19, 8150, 21, 8148, 23, 8146, 25, 8144, 27, 8142, 29, 8140, 31, 8138, 33, 8136, 35, 8134, 37, 8132, 39, 8130, 41, 8128, 43, 8126, 45, 8124, 47, 8122, 49, 8120, 51, 8118, 53, 8116, 55, 8114, 57, 8112, 59, 8110, 61, 8108, 63, 8106, 65, 8104, 67, 8102, 69, 8100, 71, 8098, 73, 8096, 75, 8094, 77, 8092, 79, 8090, 81, 8088, 83, 8086, 85, 8084, 87, 8082, 89, 8080, 91, 8078, 93, 8076, 95, 8074, 97, 8072, 99, 8070, 101, 8068, 103, 8066, 105, 8064, 107, 8062, 109, 8060, 111, 8058, 113, 8056, 115, 8054, 117, 8052, 119, 8050, 121, 8048, 123, 8046, 125, 8044, 127, 8042, 129, 8040, 131, 8038, 133, 8036, 135, 8034, 137, 8032, 139, 8030, 141, 8028, 143, 8026, 145, 8024, 147, 8022, 149, 8020, 151, 8018, 153, 8016, 155, 8014, 157, 8012, 159, 8010, 161, 8008, 163, 8006, 165, 8004, 167, 8002, 169, 8000, 171, 7998, 173, 7996, 175, 7994, 177, 7992, 179, 7990, 181, 7988, 183, 7986, 185, 7984, 187, 7982, 189, 7980, 191, 7978, 193, 7976, 195, 7974, 197, 7972, 199, 7970, 201, 7968, 203, 7966, 205, 7964, 207, 7962, 209, 7960, 211, 7958, 213, 7956, 215, 7954, 217, 7952, 219, 7950, 221, 7948, 223, 7946, 225, 7944, 227, 7942, 229, 7940, 231, 7938, 233, 7936, 235, 7934, 237, 7932, 239, 7930, 241, 7928, 243, 7926, 245, 7924, 247, 7922, 249, 7920, 251, 7918, 253, 7916, 255, 7914, 257, 7912, 259, 7910, 261, 7908, 263, 7906, 265, 7904, 267, 7902, 269, 7900, 271, 7898, 273, 7896, 275, 7894, 277, 7892, 279, 7890, 281, 7888, 283, 7886, 285, 7884, 287, 7882, 289, 7880, 291, 7878, 293, 7876, 295, 7874, 297, 7872, 299, 7870, 301, 7868, 303, 7866, 305, 7864, 307, 7862, 309, 7860, 311, 7858, 313, 7856, 315, 7854, 317, 7852, 319, 7850, 321, 7848, 323, 7846, 325, 7844, 327, 7842, 329, 7840, 331, 7838, 333, 7836, 335, 7834, 337, 7832, 339, 7830, 341, 7828, 343, 7826, 345, 7824, 347, 7822, 349, 7820, 351, 7818, 353, 7816, 355, 7814, 357, 7812, 359, 7810, 361, 7808, 363, 7806, 365, 7804, 367, 7802, 369, 7800, 371, 7798, 373, 7796, 375, 7794, 377, 7792, 379, 7790, 381, 7788, 383, 7786, 385, 7784, 387, 7782, 389, 7780, 391, 7778, 393, 7776, 395, 7774, 397, 7772, 399, 7770, 401, 7768, 403, 7766, 405, 7764, 407, 7762, 409, 7760, 411, 7758, 413, 7756, 415, 7754, 417, 7752, 419, 7750, 421, 7748, 423, 7746, 425, 7744, 427, 7742, 429, 7740, 431, 7738, 433, 7736, 435, 7734, 437, 7732, 439, 7730, 441, 7728, 443, 7726, 445, 7724, 447, 7722, 449, 7720, 451, 7718, 453, 7716, 455, 7714, 457, 7712, 459, 7710, 461, 7708, 463, 7706, 465, 7704, 467, 7702, 469, 7700, 471, 7698, 473, 7696, 475, 7694, 477, 7692, 479, 7690, 481, 7688, 483, 7686, 485, 7684, 487, 7682, 489, 7680, 491, 7678, 493, 7676, 495, 7674, 497, 7672, 499, 7670, 501, 7668, 503, 7666, 505, 7664, 507, 7662, 509, 7660, 511, 7658, 513, 7656, 515, 7654, 517, 7652, 519, 7650, 521, 7648, 523, 7646, 525, 7644, 527, 7642, 529, 7640, 531, 7638, 533, 7636, 535, 7634, 537, 7632, 539, 7630, 541, 7628, 543, 7626, 545, 7624, 547, 7622, 549, 7620, 551, 7618, 553, 7616, 555, 7614, 557, 7612, 559, 7610, 561, 7608, 563, 7606, 565, 7604, 567, 7602, 569, 7600, 571, 7598, 573, 7596, 575, 7594, 577, 7592, 579, 7590, 581, 7588, 583, 7586, 585, 7584, 587, 7582, 589, 7580, 591, 7578, 593, 7576, 595, 7574, 597, 7572, 599, 7570, 601, 7568, 603, 7566, 605, 7564, 607, 7562, 609, 7560, 611, 7558, 613, 7556, 615, 7554, 617, 7552, 619, 7550, 621, 7548, 623, 7546, 625, 7544, 627, 7542, 629, 7540, 631, 7538, 633, 7536, 635, 7534, 637, 7532, 639, 7530, 641, 7528, 643, 7526, 645, 7524, 647, 7522, 649, 7520, 651, 7518, 653, 7516, 655, 7514, 657, 7512, 659, 7510, 661, 7508, 663, 7506, 665, 7504, 667, 7502, 669, 7500, 671, 7498, 673, 7496, 675, 7494, 677, 7492, 679, 7490, 681, 7488, 683, 7486, 685, 7484, 687, 7482, 689, 7480, 691, 7478, 693, 7476, 695, 7474, 697, 7472, 699, 7470, 701, 7468, 703, 7466, 705, 7464, 707, 7462, 709, 7460, 711, 7458, 713, 7456, 715, 7454, 717, 7452, 719, 7450, 721, 7448, 723, 7446, 725, 7444, 727, 7442, 729, 7440, 731, 7438, 733, 7436, 735, 7434, 737, 7432, 739, 7430, 741, 7428, 743, 7426, 745, 7424, 747, 7422, 749, 7420, 751, 7418, 753, 7416, 755, 7414, 757, 7412, 759, 7410, 761, 7408, 763, 7406, 765, 7404, 767, 7402, 769, 7400, 771, 7398, 773, 7396, 775, 7394, 777, 7392, 779, 7390, 781, 7388, 783, 7386, 785, 7384, 787, 7382, 789, 7380, 791, 7378, 793, 7376, 795, 7374, 797, 7372, 799, 7370, 801, 7368, 803, 7366, 805, 7364, 807, 7362, 809, 7360, 811, 7358, 813, 7356, 815, 7354, 817, 7352, 819, 7350, 821, 7348, 823, 7346, 825, 7344, 827, 7342, 829, 7340, 831, 7338, 833, 7336, 835, 7334, 837, 7332, 839, 7330, 841, 7328, 843, 7326, 845, 7324, 847, 7322, 849, 7320, 851, 7318, 853, 7316, 855, 7314, 857, 7312, 859, 7310, 861, 7308, 863, 7306, 865, 7304, 867, 7302, 869, 7300, 871, 7298, 873, 7296, 875, 7294, 877, 7292, 879, 7290, 881, 7288, 883, 7286, 885, 7284, 887, 7282, 889, 7280, 891, 7278, 893, 7276, 895, 7274, 897, 7272, 899, 7270, 901, 7268, 903, 7266, 905, 7264, 907, 7262, 909, 7260, 911, 7258, 913, 7256, 915, 7254, 917, 7252, 919, 7250, 921, 7248, 923, 7246, 925, 7244, 927, 7242, 929, 7240, 931, 7238, 933, 7236, 935, 7234, 937, 7232, 939, 7230, 941, 7228, 943, 7226, 945, 7224, 947, 7222, 949, 7220, 951, 7218, 953, 7216, 955, 7214, 957, 7212, 959, 7210, 961, 7208, 963, 7206, 965, 7204, 967, 7202, 969, 7200, 971, 7198, 973, 7196, 975, 7194, 977, 7192, 979, 7190, 981, 7188, 983, 7186, 985, 7184, 987, 7182, 989, 7180, 991, 7178, 993, 7176, 995, 7174, 997, 7172, 999, 7170, 1001, 7168, 1003, 7166, 1005, 7164, 1007, 7162, 1009, 7160, 1011, 7158, 1013, 7156, 1015, 7154, 1017, 7152, 1019, 7150, 1021, 7148, 1023, 7146, 1025, 7144, 1027, 7142, 1029, 7140, 1031, 7138, 1033, 7136, 1035, 7134, 1037, 7132, 1039, 7130, 1041, 7128, 1043, 7126, 1045, 7124, 1047, 7122, 1049, 7120, 1051, 7118, 1053, 7116, 1055, 7114, 1057, 7112, 1059, 7110, 1061, 7108, 1063, 7106, 1065, 7104, 1067, 7102, 1069, 7100, 1071, 7098, 1073, 7096, 1075, 7094, 1077, 7092, 1079, 7090, 1081, 7088, 1083, 7086, 1085, 7084, 1087, 7082, 1089, 7080, 1091, 7078, 1093, 7076, 1095, 7074, 1097, 7072, 1099, 7070, 1101, 7068, 1103, 7066, 1105, 7064, 1107, 7062, 1109, 7060, 1111, 7058, 1113, 7056, 1115, 7054, 1117, 7052, 1119, 7050, 1121, 7048, 1123, 7046, 1125, 7044, 1127, 7042, 1129, 7040, 1131, 7038, 1133, 7036, 1135, 7034, 1137, 7032, 1139, 7030, 1141, 7028, 1143, 7026, 1145, 7024, 1147, 7022, 1149, 7020, 1151, 7018, 1153, 7016, 1155, 7014, 1157, 7012, 1159, 7010, 1161, 7008, 1163, 7006, 1165, 7004, 1167, 7002, 1169, 7000, 1171, 6998, 1173, 6996, 1175, 6994, 1177, 6992, 1179, 6990, 1181, 6988, 1183, 6986, 1185, 6984, 1187, 6982, 1189, 6980, 1191, 6978, 1193, 6976, 1195, 6974, 1197, 6972, 1199, 6970, 1201, 6968, 1203, 6966, 1205, 6964, 1207, 6962, 1209, 6960, 1211, 6958, 1213, 6956, 1215, 6954, 1217, 6952, 1219, 6950, 1221, 6948, 1223, 6946, 1225, 6944, 1227, 6942, 1229, 6940, 1231, 6938, 1233, 6936, 1235, 6934, 1237, 6932, 1239, 6930, 1241, 6928, 1243, 6926, 1245, 6924, 1247, 6922, 1249, 6920, 1251, 6918, 1253, 6916, 1255, 6914, 1257, 6912, 1259, 6910, 1261, 6908, 1263, 6906, 1265, 6904, 1267, 6902, 1269, 6900, 1271, 6898, 1273, 6896, 1275, 6894, 1277, 6892, 1279, 6890, 1281, 6888, 1283, 6886, 1285, 6884, 1287, 6882, 1289, 6880, 1291, 6878, 1293, 6876, 1295, 6874, 1297, 6872, 1299, 6870, 1301, 6868, 1303, 6866, 1305, 6864, 1307, 6862, 1309, 6860, 1311, 6858, 1313, 6856, 1315, 6854, 1317, 6852, 1319, 6850, 1321, 6848, 1323, 6846, 1325, 6844, 1327, 6842, 1329, 6840, 1331, 6838, 1333, 6836, 1335, 6834, 1337, 6832, 1339, 6830, 1341, 6828, 1343, 6826, 1345, 6824, 1347, 6822, 1349, 6820, 1351, 6818, 1353, 6816, 1355, 6814, 1357, 6812, 1359, 6810, 1361, 6808, 1363, 6806, 1365, 6804, 1367, 6802, 1369, 6800, 1371, 6798, 1373, 6796, 1375, 6794, 1377, 6792, 1379, 6790, 1381, 6788, 1383, 6786, 1385, 6784, 1387, 6782, 1389, 6780, 1391, 6778, 1393, 6776, 1395, 6774, 1397, 6772, 1399, 6770, 1401, 6768, 1403, 6766, 1405, 6764, 1407, 6762, 1409, 6760, 1411, 6758, 1413, 6756, 1415, 6754, 1417, 6752, 1419, 6750, 1421, 6748, 1423, 6746, 1425, 6744, 1427, 6742, 1429, 6740, 1431, 6738, 1433, 6736, 1435, 6734, 1437, 6732, 1439, 6730, 1441, 6728, 1443, 6726, 1445, 6724, 1447, 6722, 1449, 6720, 1451, 6718, 1453, 6716, 1455, 6714, 1457, 6712, 1459, 6710, 1461, 6708, 1463, 6706, 1465, 6704, 1467, 6702, 1469, 6700, 1471, 6698, 1473, 6696, 1475, 6694, 1477, 6692, 1479, 6690, 1481, 6688, 1483, 6686, 1485, 6684, 1487, 6682, 1489, 6680, 1491, 6678, 1493, 6676, 1495, 6674, 1497, 6672, 1499, 6670, 1501, 6668, 1503, 6666, 1505, 6664, 1507, 6662, 1509, 6660, 1511, 6658, 1513, 6656, 1515, 6654, 1517, 6652, 1519, 6650, 1521, 6648, 1523, 6646, 1525, 6644, 1527, 6642, 1529, 6640, 1531, 6638, 1533, 6636, 1535, 6634, 1537, 6632, 1539, 6630, 1541, 6628, 1543, 6626, 1545, 6624, 1547, 6622, 1549, 6620, 1551, 6618, 1553, 6616, 1555, 6614, 1557, 6612, 1559, 6610, 1561, 6608, 1563, 6606, 1565, 6604, 1567, 6602, 1569, 6600, 1571, 6598, 1573, 6596, 1575, 6594, 1577, 6592, 1579, 6590, 1581, 6588, 1583, 6586, 1585, 6584, 1587, 6582, 1589, 6580, 1591, 6578, 1593, 6576, 1595, 6574, 1597, 6572, 1599, 6570, 1601, 6568, 1603, 6566, 1605, 6564, 1607, 6562, 1609, 6560, 1611, 6558, 1613, 6556, 1615, 6554, 1617, 6552, 1619, 6550, 1621, 6548, 1623, 6546, 1625, 6544, 1627, 6542, 1629, 6540, 1631, 6538, 1633, 6536, 1635, 6534, 1637, 6532, 1639, 6530, 1641, 6528, 1643, 6526, 1645, 6524, 1647, 6522, 1649, 6520, 1651, 6518, 1653, 6516, 1655, 6514, 1657, 6512, 1659, 6510, 1661, 6508, 1663, 6506, 1665, 6504, 1667, 6502, 1669, 6500, 1671, 6498, 1673, 6496, 1675, 6494, 1677, 6492, 1679, 6490, 1681, 6488, 1683, 6486, 1685, 6484, 1687, 6482, 1689, 6480, 1691, 6478, 1693, 6476, 1695, 6474, 1697, 6472, 1699, 6470, 1701, 6468, 1703, 6466, 1705, 6464, 1707, 6462, 1709, 6460, 1711, 6458, 1713, 6456, 1715, 6454, 1717, 6452, 1719, 6450, 1721, 6448, 1723, 6446, 1725, 6444, 1727, 6442, 1729, 6440, 1731, 6438, 1733, 6436, 1735, 6434, 1737, 6432, 1739, 6430, 1741, 6428, 1743, 6426, 1745, 6424, 1747, 6422, 1749, 6420, 1751, 6418, 1753, 6416, 1755, 6414, 1757, 6412, 1759, 6410, 1761, 6408, 1763, 6406, 1765, 6404, 1767, 6402, 1769, 6400, 1771, 6398, 1773, 6396, 1775, 6394, 1777, 6392, 1779, 6390, 1781, 6388, 1783, 6386, 1785, 6384, 1787, 6382, 1789, 6380, 1791, 6378, 1793, 6376, 1795, 6374, 1797, 6372, 1799, 6370, 1801, 6368, 1803, 6366, 1805, 6364, 1807, 6362, 1809, 6360, 1811, 6358, 1813, 6356, 1815, 6354, 1817, 6352, 1819, 6350, 1821, 6348, 1823, 6346, 1825, 6344, 1827, 6342, 1829, 6340, 1831, 6338, 1833, 6336, 1835, 6334, 1837, 6332, 1839, 6330, 1841, 6328, 1843, 6326, 1845, 6324, 1847, 6322, 1849, 6320, 1851, 6318, 1853, 6316, 1855, 6314, 1857, 6312, 1859, 6310, 1861, 6308, 1863, 6306, 1865, 6304, 1867, 6302, 1869, 6300, 1871, 6298, 1873, 6296, 1875, 6294, 1877, 6292, 1879, 6290, 1881, 6288, 1883, 6286, 1885, 6284, 1887, 6282, 1889, 6280, 1891, 6278, 1893, 6276, 1895, 6274, 1897, 6272, 1899, 6270, 1901, 6268, 1903, 6266, 1905, 6264, 1907, 6262, 1909, 6260, 1911, 6258, 1913, 6256, 1915, 6254, 1917, 6252, 1919, 6250, 1921, 6248, 1923, 6246, 1925, 6244, 1927, 6242, 1929, 6240, 1931, 6238, 1933, 6236, 1935, 6234, 1937, 6232, 1939, 6230, 1941, 6228, 1943, 6226, 1945, 6224, 1947, 6222, 1949, 6220, 1951, 6218, 1953, 6216, 1955, 6214, 1957, 6212, 1959, 6210, 1961, 6208, 1963, 6206, 1965, 6204, 1967, 6202, 1969, 6200, 1971, 6198, 1973, 6196, 1975, 6194, 1977, 6192, 1979, 6190, 1981, 6188, 1983, 6186, 1985, 6184, 1987, 6182, 1989, 6180, 1991, 6178, 1993, 6176, 1995, 6174, 1997, 6172, 1999, 6170, 2001, 6168, 2003, 6166, 2005, 6164, 2007, 6162, 2009, 6160, 2011, 6158, 2013, 6156, 2015, 6154, 2017, 6152, 2019, 6150, 2021, 6148, 2023, 6146, 2025, 6144, 2027, 6142, 2029, 6140, 2031, 6138, 2033, 6136, 2035, 6134, 2037, 6132, 2039, 6130, 2041, 6128, 2043, 6126, 2045, 6124, 2047, 6122, 2049, 6120, 2051, 6118, 2053, 6116, 2055, 6114, 2057, 6112, 2059, 6110, 2061, 6108, 2063, 6106, 2065, 6104, 2067, 6102, 2069, 6100, 2071, 6098, 2073, 6096, 2075, 6094, 2077, 6092, 2079, 6090, 2081, 6088, 2083, 6086, 2085, 6084, 2087, 6082, 2089, 6080, 2091, 6078, 2093, 6076, 2095, 6074, 2097, 6072, 2099, 6070, 2101, 6068, 2103, 6066, 2105, 6064, 2107, 6062, 2109, 6060, 2111, 6058, 2113, 6056, 2115, 6054, 2117, 6052, 2119, 6050, 2121, 6048, 2123, 6046, 2125, 6044, 2127, 6042, 2129, 6040, 2131, 6038, 2133, 6036, 2135, 6034, 2137, 6032, 2139, 6030, 2141, 6028, 2143, 6026, 2145, 6024, 2147, 6022, 2149, 6020, 2151, 6018, 2153, 6016, 2155, 6014, 2157, 6012, 2159, 6010, 2161, 6008, 2163, 6006, 2165, 6004, 2167, 6002, 2169, 6000, 2171, 5998, 2173, 5996, 2175, 5994, 2177, 5992, 2179, 5990, 2181, 5988, 2183, 5986, 2185, 5984, 2187, 5982, 2189, 5980, 2191, 5978, 2193, 5976, 2195, 5974, 2197, 5972, 2199, 5970, 2201, 5968, 2203, 5966, 2205, 5964, 2207, 5962, 2209, 5960, 2211, 5958, 2213, 5956, 2215, 5954, 2217, 5952, 2219, 5950, 2221, 5948, 2223, 5946, 2225, 5944, 2227, 5942, 2229, 5940, 2231, 5938, 2233, 5936, 2235, 5934, 2237, 5932, 2239, 5930, 2241, 5928, 2243, 5926, 2245, 5924, 2247, 5922, 2249, 5920, 2251, 5918, 2253, 5916, 2255, 5914, 2257, 5912, 2259, 5910, 2261, 5908, 2263, 5906, 2265, 5904, 2267, 5902, 2269, 5900, 2271, 5898, 2273, 5896, 2275, 5894, 2277, 5892, 2279, 5890, 2281, 5888, 2283, 5886, 2285, 5884, 2287, 5882, 2289, 5880, 2291, 5878, 2293, 5876, 2295, 5874, 2297, 5872, 2299, 5870, 2301, 5868, 2303, 5866, 2305, 5864, 2307, 5862, 2309, 5860, 2311, 5858, 2313, 5856, 2315, 5854, 2317, 5852, 2319, 5850, 2321, 5848, 2323, 5846, 2325, 5844, 2327, 5842, 2329, 5840, 2331, 5838, 2333, 5836, 2335, 5834, 2337, 5832, 2339, 5830, 2341, 5828, 2343, 5826, 2345, 5824, 2347, 5822, 2349, 5820, 2351, 5818, 2353, 5816, 2355, 5814, 2357, 5812, 2359, 5810, 2361, 5808, 2363, 5806, 2365, 5804, 2367, 5802, 2369, 5800, 2371, 5798, 2373, 5796, 2375, 5794, 2377, 5792, 2379, 5790, 2381, 5788, 2383, 5786, 2385, 5784, 2387, 5782, 2389, 5780, 2391, 5778, 2393, 5776, 2395, 5774, 2397, 5772, 2399, 5770, 2401, 5768, 2403, 5766, 2405, 5764, 2407, 5762, 2409, 5760, 2411, 5758, 2413, 5756, 2415, 5754, 2417, 5752, 2419, 5750, 2421, 5748, 2423, 5746, 2425, 5744, 2427, 5742, 2429, 5740, 2431, 5738, 2433, 5736, 2435, 5734, 2437, 5732, 2439, 5730, 2441, 5728, 2443, 5726, 2445, 5724, 2447, 5722, 2449, 5720, 2451, 5718, 2453, 5716, 2455, 5714, 2457, 5712, 2459, 5710, 2461, 5708, 2463, 5706, 2465, 5704, 2467, 5702, 2469, 5700, 2471, 5698, 2473, 5696, 2475, 5694, 2477, 5692, 2479, 5690, 2481, 5688, 2483, 5686, 2485, 5684, 2487, 5682, 2489, 5680, 2491, 5678, 2493, 5676, 2495, 5674, 2497, 5672, 2499, 5670, 2501, 5668, 2503, 5666, 2505, 5664, 2507, 5662, 2509, 5660, 2511, 5658, 2513, 5656, 2515, 5654, 2517, 5652, 2519, 5650, 2521, 5648, 2523, 5646, 2525, 5644, 2527, 5642, 2529, 5640, 2531, 5638, 2533, 5636, 2535, 5634, 2537, 5632, 2539, 5630, 2541, 5628, 2543, 5626, 2545, 5624, 2547, 5622, 2549, 5620, 2551, 5618, 2553, 5616, 2555, 5614, 2557, 5612, 2559, 5610, 2561, 5608, 2563, 5606, 2565, 5604, 2567, 5602, 2569, 5600, 2571, 5598, 2573, 5596, 2575, 5594, 2577, 5592, 2579, 5590, 2581, 5588, 2583, 5586, 2585, 5584, 2587, 5582, 2589, 5580, 2591, 5578, 2593, 5576, 2595, 5574, 2597, 5572, 2599, 5570, 2601, 5568, 2603, 5566, 2605, 5564, 2607, 5562, 2609, 5560, 2611, 5558, 2613, 5556, 2615, 5554, 2617, 5552, 2619, 5550, 2621, 5548, 2623, 5546, 2625, 5544, 2627, 5542, 2629, 5540, 2631, 5538, 2633, 5536, 2635, 5534, 2637, 5532, 2639, 5530, 2641, 5528, 2643, 5526, 2645, 5524, 2647, 5522, 2649, 5520, 2651, 5518, 2653, 5516, 2655, 5514, 2657, 5512, 2659, 5510, 2661, 5508, 2663, 5506, 2665, 5504, 2667, 5502, 2669, 5500, 2671, 5498, 2673, 5496, 2675, 5494, 2677, 5492, 2679, 5490, 2681, 5488, 2683, 5486, 2685, 5484, 2687, 5482, 2689, 5480, 2691, 5478, 2693, 5476, 2695, 5474, 2697, 5472, 2699, 5470, 2701, 5468, 2703, 5466, 2705, 5464, 2707, 5462, 2709, 5460, 2711, 5458, 2713, 5456, 2715, 5454, 2717, 5452, 2719, 5450, 2721, 5448, 2723, 5446, 2725, 5444, 2727, 5442, 2729, 5440, 2731, 5438, 2733, 5436, 2735, 5434, 2737, 5432, 2739, 5430, 2741, 5428, 2743, 5426, 2745, 5424, 2747, 5422, 2749, 5420, 2751, 5418, 2753, 5416, 2755, 5414, 2757, 5412, 2759, 5410, 2761, 5408, 2763, 5406, 2765, 5404, 2767, 5402, 2769, 5400, 2771, 5398, 2773, 5396, 2775, 5394, 2777, 5392, 2779, 5390, 2781, 5388, 2783, 5386, 2785, 5384, 2787, 5382, 2789, 5380, 2791, 5378, 2793, 5376, 2795, 5374, 2797, 5372, 2799, 5370, 2801, 5368, 2803, 5366, 2805, 5364, 2807, 5362, 2809, 5360, 2811, 5358, 2813, 5356, 2815, 5354, 2817, 5352, 2819, 5350, 2821, 5348, 2823, 5346, 2825, 5344, 2827, 5342, 2829, 5340, 2831, 5338, 2833, 5336, 2835, 5334, 2837, 5332, 2839, 5330, 2841, 5328, 2843, 5326, 2845, 5324, 2847, 5322, 2849, 5320, 2851, 5318, 2853, 5316, 2855, 5314, 2857, 5312, 2859, 5310, 2861, 5308, 2863, 5306, 2865, 5304, 2867, 5302, 2869, 5300, 2871, 5298, 2873, 5296, 2875, 5294, 2877, 5292, 2879, 5290, 2881, 5288, 2883, 5286, 2885, 5284, 2887, 5282, 2889, 5280, 2891, 5278, 2893, 5276, 2895, 5274, 2897, 5272, 2899, 5270, 2901, 5268, 2903, 5266, 2905, 5264, 2907, 5262, 2909, 5260, 2911, 5258, 2913, 5256, 2915, 5254, 2917, 5252, 2919, 5250, 2921, 5248, 2923, 5246, 2925, 5244, 2927, 5242, 2929, 5240, 2931, 5238, 2933, 5236, 2935, 5234, 2937, 5232, 2939, 5230, 2941, 5228, 2943, 5226, 2945, 5224, 2947, 5222, 2949, 5220, 2951, 5218, 2953, 5216, 2955, 5214, 2957, 5212, 2959, 5210, 2961, 5208, 2963, 5206, 2965, 5204, 2967, 5202, 2969, 5200, 2971, 5198, 2973, 5196, 2975, 5194, 2977, 5192, 2979, 5190, 2981, 5188, 2983, 5186, 2985, 5184, 2987, 5182, 2989, 5180, 2991, 5178, 2993, 5176, 2995, 5174, 2997, 5172, 2999, 5170, 3001, 5168, 3003, 5166, 3005, 5164, 3007, 5162, 3009, 5160, 3011, 5158, 3013, 5156, 3015, 5154, 3017, 5152, 3019, 5150, 3021, 5148, 3023, 5146, 3025, 5144, 3027, 5142, 3029, 5140, 3031, 5138, 3033, 5136, 3035, 5134, 3037, 5132, 3039, 5130, 3041, 5128, 3043, 5126, 3045, 5124, 3047, 5122, 3049, 5120, 3051, 5118, 3053, 5116, 3055, 5114, 3057, 5112, 3059, 5110, 3061, 5108, 3063, 5106, 3065, 5104, 3067, 5102, 3069, 5100, 3071, 5098, 3073, 5096, 3075, 5094, 3077, 5092, 3079, 5090, 3081, 5088, 3083, 5086, 3085, 5084, 3087, 5082, 3089, 5080, 3091, 5078, 3093, 5076, 3095, 5074, 3097, 5072, 3099, 5070, 3101, 5068, 3103, 5066, 3105, 5064, 3107, 5062, 3109, 5060, 3111, 5058, 3113, 5056, 3115, 5054, 3117, 5052, 3119, 5050, 3121, 5048, 3123, 5046, 3125, 5044, 3127, 5042, 3129, 5040, 3131, 5038, 3133, 5036, 3135, 5034, 3137, 5032, 3139, 5030, 3141, 5028, 3143, 5026, 3145, 5024, 3147, 5022, 3149, 5020, 3151, 5018, 3153, 5016, 3155, 5014, 3157, 5012, 3159, 5010, 3161, 5008, 3163, 5006, 3165, 5004, 3167, 5002, 3169, 5000, 3171, 4998, 3173, 4996, 3175, 4994, 3177, 4992, 3179, 4990, 3181, 4988, 3183, 4986, 3185, 4984, 3187, 4982, 3189, 4980, 3191, 4978, 3193, 4976, 3195, 4974, 3197, 4972, 3199, 4970, 3201, 4968, 3203, 4966, 3205, 4964, 3207, 4962, 3209, 4960, 3211, 4958, 3213, 4956, 3215, 4954, 3217, 4952, 3219, 4950, 3221, 4948, 3223, 4946, 3225, 4944, 3227, 4942, 3229, 4940, 3231, 4938, 3233, 4936, 3235, 4934, 3237, 4932, 3239, 4930, 3241, 4928, 3243, 4926, 3245, 4924, 3247, 4922, 3249, 4920, 3251, 4918, 3253, 4916, 3255, 4914, 3257, 4912, 3259, 4910, 3261, 4908, 3263, 4906, 3265, 4904, 3267, 4902, 3269, 4900, 3271, 4898, 3273, 4896, 3275, 4894, 3277, 4892, 3279, 4890, 3281, 4888, 3283, 4886, 3285, 4884, 3287, 4882, 3289, 4880, 3291, 4878, 3293, 4876, 3295, 4874, 3297, 4872, 3299, 4870, 3301, 4868, 3303, 4866, 3305, 4864, 3307, 4862, 3309, 4860, 3311, 4858, 3313, 4856, 3315, 4854, 3317, 4852, 3319, 4850, 3321, 4848, 3323, 4846, 3325, 4844, 3327, 4842, 3329, 4840, 3331, 4838, 3333, 4836, 3335, 4834, 3337, 4832, 3339, 4830, 3341, 4828, 3343, 4826, 3345, 4824, 3347, 4822, 3349, 4820, 3351, 4818, 3353, 4816, 3355, 4814, 3357, 4812, 3359, 4810, 3361, 4808, 3363, 4806, 3365, 4804, 3367, 4802, 3369, 4800, 3371, 4798, 3373, 4796, 3375, 4794, 3377, 4792, 3379, 4790, 3381, 4788, 3383, 4786, 3385, 4784, 3387, 4782, 3389, 4780, 3391, 4778, 3393, 4776, 3395, 4774, 3397, 4772, 3399, 4770, 3401, 4768, 3403, 4766, 3405, 4764, 3407, 4762, 3409, 4760, 3411, 4758, 3413, 4756, 3415, 4754, 3417, 4752, 3419, 4750, 3421, 4748, 3423, 4746, 3425, 4744, 3427, 4742, 3429, 4740, 3431, 4738, 3433, 4736, 3435, 4734, 3437, 4732, 3439, 4730, 3441, 4728, 3443, 4726, 3445, 4724, 3447, 4722, 3449, 4720, 3451, 4718, 3453, 4716, 3455, 4714, 3457, 4712, 3459, 4710, 3461, 4708, 3463, 4706, 3465, 4704, 3467, 4702, 3469, 4700, 3471, 4698, 3473, 4696, 3475, 4694, 3477, 4692, 3479, 4690, 3481, 4688, 3483, 4686, 3485, 4684, 3487, 4682, 3489, 4680, 3491, 4678, 3493, 4676, 3495, 4674, 3497, 4672, 3499, 4670, 3501, 4668, 3503, 4666, 3505, 4664, 3507, 4662, 3509, 4660, 3511, 4658, 3513, 4656, 3515, 4654, 3517, 4652, 3519, 4650, 3521, 4648, 3523, 4646, 3525, 4644, 3527, 4642, 3529, 4640, 3531, 4638, 3533, 4636, 3535, 4634, 3537, 4632, 3539, 4630, 3541, 4628, 3543, 4626, 3545, 4624, 3547, 4622, 3549, 4620, 3551, 4618, 3553, 4616, 3555, 4614, 3557, 4612, 3559, 4610, 3561, 4608, 3563, 4606, 3565, 4604, 3567, 4602, 3569, 4600, 3571, 4598, 3573, 4596, 3575, 4594, 3577, 4592, 3579, 4590, 3581, 4588, 3583, 4586, 3585, 4584, 3587, 4582, 3589, 4580, 3591, 4578, 3593, 4576, 3595, 4574, 3597, 4572, 3599, 4570, 3601, 4568, 3603, 4566, 3605, 4564, 3607, 4562, 3609, 4560, 3611, 4558, 3613, 4556, 3615, 4554, 3617, 4552, 3619, 4550, 3621, 4548, 3623, 4546, 3625, 4544, 3627, 4542, 3629, 4540, 3631, 4538, 3633, 4536, 3635, 4534, 3637, 4532, 3639, 4530, 3641, 4528, 3643, 4526, 3645, 4524, 3647, 4522, 3649, 4520, 3651, 4518, 3653, 4516, 3655, 4514, 3657, 4512, 3659, 4510, 3661, 4508, 3663, 4506, 3665, 4504, 3667, 4502, 3669, 4500, 3671, 4498, 3673, 4496, 3675, 4494, 3677, 4492, 3679, 4490, 3681, 4488, 3683, 4486, 3685, 4484, 3687, 4482, 3689, 4480, 3691, 4478, 3693, 4476, 3695, 4474, 3697, 4472, 3699, 4470, 3701, 4468, 3703, 4466, 3705, 4464, 3707, 4462, 3709, 4460, 3711, 4458, 3713, 4456, 3715, 4454, 3717, 4452, 3719, 4450, 3721, 4448, 3723, 4446, 3725, 4444, 3727, 4442, 3729, 4440, 3731, 4438, 3733, 4436, 3735, 4434, 3737, 4432, 3739, 4430, 3741, 4428, 3743, 4426, 3745, 4424, 3747, 4422, 3749, 4420, 3751, 4418, 3753, 4416, 3755, 4414, 3757, 4412, 3759, 4410, 3761, 4408, 3763, 4406, 3765, 4404, 3767, 4402, 3769, 4400, 3771, 4398, 3773, 4396, 3775, 4394, 3777, 4392, 3779, 4390, 3781, 4388, 3783, 4386, 3785, 4384, 3787, 4382, 3789, 4380, 3791, 4378, 3793, 4376, 3795, 4374, 3797, 4372, 3799, 4370, 3801, 4368, 3803, 4366, 3805, 4364, 3807, 4362, 3809, 4360, 3811, 4358, 3813, 4356, 3815, 4354, 3817, 4352, 3819, 4350, 3821, 4348, 3823, 4346, 3825, 4344, 3827, 4342, 3829, 4340, 3831, 4338, 3833, 4336, 3835, 4334, 3837, 4332, 3839, 4330, 3841, 4328, 3843, 4326, 3845, 4324, 3847, 4322, 3849, 4320, 3851, 4318, 3853, 4316, 3855, 4314, 3857, 4312, 3859, 4310, 3861, 4308, 3863, 4306, 3865, 4304, 3867, 4302, 3869, 4300, 3871, 4298, 3873, 4296, 3875, 4294, 3877, 4292, 3879, 4290, 3881, 4288, 3883, 4286, 3885, 4284, 3887, 4282, 3889, 4280, 3891, 4278, 3893, 4276, 3895, 4274, 3897, 4272, 3899, 4270, 3901, 4268, 3903, 4266, 3905, 4264, 3907, 4262, 3909, 4260, 3911, 4258, 3913, 4256, 3915, 4254, 3917, 4252, 3919, 4250, 3921, 4248, 3923, 4246, 3925, 4244, 3927, 4242, 3929, 4240, 3931, 4238, 3933, 4236, 3935, 4234, 3937, 4232, 3939, 4230, 3941, 4228, 3943, 4226, 3945, 4224, 3947, 4222, 3949, 4220, 3951, 4218, 3953, 4216, 3955, 4214, 3957, 4212, 3959, 4210, 3961, 4208, 3963, 4206, 3965, 4204, 3967, 4202, 3969, 4200, 3971, 4198, 3973, 4196, 3975, 4194, 3977, 4192, 3979, 4190, 3981, 4188, 3983, 4186, 3985, 4184, 3987, 4182, 3989, 4180, 3991, 4178, 3993, 4176, 3995, 4174, 3997, 4172, 3999, 4170, 4001, 4168, 4003, 4166, 4005, 4164, 4007, 4162, 4009, 4160, 4011, 4158, 4013, 4156, 4015, 4154, 4017, 4152, 4019, 4150, 4021, 4148, 4023, 4146, 4025, 4144, 4027, 4142, 4029, 4140, 4031, 4138, 4033, 4136, 4035, 4134, 4037, 4132, 4039, 4130, 4041, 4128, 4043, 4126, 4045, 4124, 4047, 4122, 4049, 4120, 4051, 4118, 4053, 4116, 4055, 4114, 4057, 4112, 4059, 4110, 4061, 4108, 4063, 4106, 4065, 4104, 4067, 4102, 4069, 4100, 4071, 4098, 4073, 4096, 4075, 4094, 4077, 4092, 4079, 4090, 4081, 4088, 4083, 4086, 4085, 4084, 4087, 4082, 4089, 4080, 4091, 4078, 4093, 4076, 4095, 4074, 4097, 4072, 4099, 4070, 4101, 4068, 4103, 4066, 4105, 4064, 4107, 4062, 4109, 4060, 4111, 4058, 4113, 4056, 4115, 4054, 4117, 4052, 4119, 4050, 4121, 4048, 4123, 4046, 4125, 4044, 4127, 4042, 4129, 4040, 4131, 4038, 4133, 4036, 4135, 4034, 4137, 4032, 4139, 4030, 4141, 4028, 4143, 4026, 4145, 4024, 4147, 4022, 4149, 4020, 4151, 4018, 4153, 4016, 4155, 4014, 4157, 4012, 4159, 4010, 4161, 4008, 4163, 4006, 4165, 4004, 4167, 4002, 4169, 4000, 4171, 3998, 4173, 3996, 4175, 3994, 4177, 3992, 4179, 3990, 4181, 3988, 4183, 3986, 4185, 3984, 4187, 3982, 4189, 3980, 4191, 3978, 4193, 3976, 4195, 3974, 4197, 3972, 4199, 3970, 4201, 3968, 4203, 3966, 4205, 3964, 4207, 3962, 4209, 3960, 4211, 3958, 4213, 3956, 4215, 3954, 4217, 3952, 4219, 3950, 4221, 3948, 4223, 3946, 4225, 3944, 4227, 3942, 4229, 3940, 4231, 3938, 4233, 3936, 4235, 3934, 4237, 3932, 4239, 3930, 4241, 3928, 4243, 3926, 4245, 3924, 4247, 3922, 4249, 3920, 4251, 3918, 4253, 3916, 4255, 3914, 4257, 3912, 4259, 3910, 4261, 3908, 4263, 3906, 4265, 3904, 4267, 3902, 4269, 3900, 4271, 3898, 4273, 3896, 4275, 3894, 4277, 3892, 4279, 3890, 4281, 3888, 4283, 3886, 4285, 3884, 4287, 3882, 4289, 3880, 4291, 3878, 4293, 3876, 4295, 3874, 4297, 3872, 4299, 3870, 4301, 3868, 4303, 3866, 4305, 3864, 4307, 3862, 4309, 3860, 4311, 3858, 4313, 3856, 4315, 3854, 4317, 3852, 4319, 3850, 4321, 3848, 4323, 3846, 4325, 3844, 4327, 3842, 4329, 3840, 4331, 3838, 4333, 3836, 4335, 3834, 4337, 3832, 4339, 3830, 4341, 3828, 4343, 3826, 4345, 3824, 4347, 3822, 4349, 3820, 4351, 3818, 4353, 3816, 4355, 3814, 4357, 3812, 4359, 3810, 4361, 3808, 4363, 3806, 4365, 3804, 4367, 3802, 4369, 3800, 4371, 3798, 4373, 3796, 4375, 3794, 4377, 3792, 4379, 3790, 4381, 3788, 4383, 3786, 4385, 3784, 4387, 3782, 4389, 3780, 4391, 3778, 4393, 3776, 4395, 3774, 4397, 3772, 4399, 3770, 4401, 3768, 4403, 3766, 4405, 3764, 4407, 3762, 4409, 3760, 4411, 3758, 4413, 3756, 4415, 3754, 4417, 3752, 4419, 3750, 4421, 3748, 4423, 3746, 4425, 3744, 4427, 3742, 4429, 3740, 4431, 3738, 4433, 3736, 4435, 3734, 4437, 3732, 4439, 3730, 4441, 3728, 4443, 3726, 4445, 3724, 4447, 3722, 4449, 3720, 4451, 3718, 4453, 3716, 4455, 3714, 4457, 3712, 4459, 3710, 4461, 3708, 4463, 3706, 4465, 3704, 4467, 3702, 4469, 3700, 4471, 3698, 4473, 3696, 4475, 3694, 4477, 3692, 4479, 3690, 4481, 3688, 4483, 3686, 4485, 3684, 4487, 3682, 4489, 3680, 4491, 3678, 4493, 3676, 4495, 3674, 4497, 3672, 4499, 3670, 4501, 3668, 4503, 3666, 4505, 3664, 4507, 3662, 4509, 3660, 4511, 3658, 4513, 3656, 4515, 3654, 4517, 3652, 4519, 3650, 4521, 3648, 4523, 3646, 4525, 3644, 4527, 3642, 4529, 3640, 4531, 3638, 4533, 3636, 4535, 3634, 4537, 3632, 4539, 3630, 4541, 3628, 4543, 3626, 4545, 3624, 4547, 3622, 4549, 3620, 4551, 3618, 4553, 3616, 4555, 3614, 4557, 3612, 4559, 3610, 4561, 3608, 4563, 3606, 4565, 3604, 4567, 3602, 4569, 3600, 4571, 3598, 4573, 3596, 4575, 3594, 4577, 3592, 4579, 3590, 4581, 3588, 4583, 3586, 4585, 3584, 4587, 3582, 4589, 3580, 4591, 3578, 4593, 3576, 4595, 3574, 4597, 3572, 4599, 3570, 4601, 3568, 4603, 3566, 4605, 3564, 4607, 3562, 4609, 3560, 4611, 3558, 4613, 3556, 4615, 3554, 4617, 3552, 4619, 3550, 4621, 3548, 4623, 3546, 4625, 3544, 4627, 3542, 4629, 3540, 4631, 3538, 4633, 3536, 4635, 3534, 4637, 3532, 4639, 3530, 4641, 3528, 4643, 3526, 4645, 3524, 4647, 3522, 4649, 3520, 4651, 3518, 4653, 3516, 4655, 3514, 4657, 3512, 4659, 3510, 4661, 3508, 4663, 3506, 4665, 3504, 4667, 3502, 4669, 3500, 4671, 3498, 4673, 3496, 4675, 3494, 4677, 3492, 4679, 3490, 4681, 3488, 4683, 3486, 4685, 3484, 4687, 3482, 4689, 3480, 4691, 3478, 4693, 3476, 4695, 3474, 4697, 3472, 4699, 3470, 4701, 3468, 4703, 3466, 4705, 3464, 4707, 3462, 4709, 3460, 4711, 3458, 4713, 3456, 4715, 3454, 4717, 3452, 4719, 3450, 4721, 3448, 4723, 3446, 4725, 3444, 4727, 3442, 4729, 3440, 4731, 3438, 4733, 3436, 4735, 3434, 4737, 3432, 4739, 3430, 4741, 3428, 4743, 3426, 4745, 3424, 4747, 3422, 4749, 3420, 4751, 3418, 4753, 3416, 4755, 3414, 4757, 3412, 4759, 3410, 4761, 3408, 4763, 3406, 4765, 3404, 4767, 3402, 4769, 3400, 4771, 3398, 4773, 3396, 4775, 3394, 4777, 3392, 4779, 3390, 4781, 3388, 4783, 3386, 4785, 3384, 4787, 3382, 4789, 3380, 4791, 3378, 4793, 3376, 4795, 3374, 4797, 3372, 4799, 3370, 4801, 3368, 4803, 3366, 4805, 3364, 4807, 3362, 4809, 3360, 4811, 3358, 4813, 3356, 4815, 3354, 4817, 3352, 4819, 3350, 4821, 3348, 4823, 3346, 4825, 3344, 4827, 3342, 4829, 3340, 4831, 3338, 4833, 3336, 4835, 3334, 4837, 3332, 4839, 3330, 4841, 3328, 4843, 3326, 4845, 3324, 4847, 3322, 4849, 3320, 4851, 3318, 4853, 3316, 4855, 3314, 4857, 3312, 4859, 3310, 4861, 3308, 4863, 3306, 4865, 3304, 4867, 3302, 4869, 3300, 4871, 3298, 4873, 3296, 4875, 3294, 4877, 3292, 4879, 3290, 4881, 3288, 4883, 3286, 4885, 3284, 4887, 3282, 4889, 3280, 4891, 3278, 4893, 3276, 4895, 3274, 4897, 3272, 4899, 3270, 4901, 3268, 4903, 3266, 4905, 3264, 4907, 3262, 4909, 3260, 4911, 3258, 4913, 3256, 4915, 3254, 4917, 3252, 4919, 3250, 4921, 3248, 4923, 3246, 4925, 3244, 4927, 3242, 4929, 3240, 4931, 3238, 4933, 3236, 4935, 3234, 4937, 3232, 4939, 3230, 4941, 3228, 4943, 3226, 4945, 3224, 4947, 3222, 4949, 3220, 4951, 3218, 4953, 3216, 4955, 3214, 4957, 3212, 4959, 3210, 4961, 3208, 4963, 3206, 4965, 3204, 4967, 3202, 4969, 3200, 4971, 3198, 4973, 3196, 4975, 3194, 4977, 3192, 4979, 3190, 4981, 3188, 4983, 3186, 4985, 3184, 4987, 3182, 4989, 3180, 4991, 3178, 4993, 3176, 4995, 3174, 4997, 3172, 4999, 3170, 5001, 3168, 5003, 3166, 5005, 3164, 5007, 3162, 5009, 3160, 5011, 3158, 5013, 3156, 5015, 3154, 5017, 3152, 5019, 3150, 5021, 3148, 5023, 3146, 5025, 3144, 5027, 3142, 5029, 3140, 5031, 3138, 5033, 3136, 5035, 3134, 5037, 3132, 5039, 3130, 5041, 3128, 5043, 3126, 5045, 3124, 5047, 3122, 5049, 3120, 5051, 3118, 5053, 3116, 5055, 3114, 5057, 3112, 5059, 3110, 5061, 3108, 5063, 3106, 5065, 3104, 5067, 3102, 5069, 3100, 5071, 3098, 5073, 3096, 5075, 3094, 5077, 3092, 5079, 3090, 5081, 3088, 5083, 3086, 5085, 3084, 5087, 3082, 5089, 3080, 5091, 3078, 5093, 3076, 5095, 3074, 5097, 3072, 5099, 3070, 5101, 3068, 5103, 3066, 5105, 3064, 5107, 3062, 5109, 3060, 5111, 3058, 5113, 3056, 5115, 3054, 5117, 3052, 5119, 3050, 5121, 3048, 5123, 3046, 5125, 3044, 5127, 3042, 5129, 3040, 5131, 3038, 5133, 3036, 5135, 3034, 5137, 3032, 5139, 3030, 5141, 3028, 5143, 3026, 5145, 3024, 5147, 3022, 5149, 3020, 5151, 3018, 5153, 3016, 5155, 3014, 5157, 3012, 5159, 3010, 5161, 3008, 5163, 3006, 5165, 3004, 5167, 3002, 5169, 3000, 5171, 2998, 5173, 2996, 5175, 2994, 5177, 2992, 5179, 2990, 5181, 2988, 5183, 2986, 5185, 2984, 5187, 2982, 5189, 2980, 5191, 2978, 5193, 2976, 5195, 2974, 5197, 2972, 5199, 2970, 5201, 2968, 5203, 2966, 5205, 2964, 5207, 2962, 5209, 2960, 5211, 2958, 5213, 2956, 5215, 2954, 5217, 2952, 5219, 2950, 5221, 2948, 5223, 2946, 5225, 2944, 5227, 2942, 5229, 2940, 5231, 2938, 5233, 2936, 5235, 2934, 5237, 2932, 5239, 2930, 5241, 2928, 5243, 2926, 5245, 2924, 5247, 2922, 5249, 2920, 5251, 2918, 5253, 2916, 5255, 2914, 5257, 2912, 5259, 2910, 5261, 2908, 5263, 2906, 5265, 2904, 5267, 2902, 5269, 2900, 5271, 2898, 5273, 2896, 5275, 2894, 5277, 2892, 5279, 2890, 5281, 2888, 5283, 2886, 5285, 2884, 5287, 2882, 5289, 2880, 5291, 2878, 5293, 2876, 5295, 2874, 5297, 2872, 5299, 2870, 5301, 2868, 5303, 2866, 5305, 2864, 5307, 2862, 5309, 2860, 5311, 2858, 5313, 2856, 5315, 2854, 5317, 2852, 5319, 2850, 5321, 2848, 5323, 2846, 5325, 2844, 5327, 2842, 5329, 2840, 5331, 2838, 5333, 2836, 5335, 2834, 5337, 2832, 5339, 2830, 5341, 2828, 5343, 2826, 5345, 2824, 5347, 2822, 5349, 2820, 5351, 2818, 5353, 2816, 5355, 2814, 5357, 2812, 5359, 2810, 5361, 2808, 5363, 2806, 5365, 2804, 5367, 2802, 5369, 2800, 5371, 2798, 5373, 2796, 5375, 2794, 5377, 2792, 5379, 2790, 5381, 2788, 5383, 2786, 5385, 2784, 5387, 2782, 5389, 2780, 5391, 2778, 5393, 2776, 5395, 2774, 5397, 2772, 5399, 2770, 5401, 2768, 5403, 2766, 5405, 2764, 5407, 2762, 5409, 2760, 5411, 2758, 5413, 2756, 5415, 2754, 5417, 2752, 5419, 2750, 5421, 2748, 5423, 2746, 5425, 2744, 5427, 2742, 5429, 2740, 5431, 2738, 5433, 2736, 5435, 2734, 5437, 2732, 5439, 2730, 5441, 2728, 5443, 2726, 5445, 2724, 5447, 2722, 5449, 2720, 5451, 2718, 5453, 2716, 5455, 2714, 5457, 2712, 5459, 2710, 5461, 2708, 5463, 2706, 5465, 2704, 5467, 2702, 5469, 2700, 5471, 2698, 5473, 2696, 5475, 2694, 5477, 2692, 5479, 2690, 5481, 2688, 5483, 2686, 5485, 2684, 5487, 2682, 5489, 2680, 5491, 2678, 5493, 2676, 5495, 2674, 5497, 2672, 5499, 2670, 5501, 2668, 5503, 2666, 5505, 2664, 5507, 2662, 5509, 2660, 5511, 2658, 5513, 2656, 5515, 2654, 5517, 2652, 5519, 2650, 5521, 2648, 5523, 2646, 5525, 2644, 5527, 2642, 5529, 2640, 5531, 2638, 5533, 2636, 5535, 2634, 5537, 2632, 5539, 2630, 5541, 2628, 5543, 2626, 5545, 2624, 5547, 2622, 5549, 2620, 5551, 2618, 5553, 2616, 5555, 2614, 5557, 2612, 5559, 2610, 5561, 2608, 5563, 2606, 5565, 2604, 5567, 2602, 5569, 2600, 5571, 2598, 5573, 2596, 5575, 2594, 5577, 2592, 5579, 2590, 5581, 2588, 5583, 2586, 5585, 2584, 5587, 2582, 5589, 2580, 5591, 2578, 5593, 2576, 5595, 2574, 5597, 2572, 5599, 2570, 5601, 2568, 5603, 2566, 5605, 2564, 5607, 2562, 5609, 2560, 5611, 2558, 5613, 2556, 5615, 2554, 5617, 2552, 5619, 2550, 5621, 2548, 5623, 2546, 5625, 2544, 5627, 2542, 5629, 2540, 5631, 2538, 5633, 2536, 5635, 2534, 5637, 2532, 5639, 2530, 5641, 2528, 5643, 2526, 5645, 2524, 5647, 2522, 5649, 2520, 5651, 2518, 5653, 2516, 5655, 2514, 5657, 2512, 5659, 2510, 5661, 2508, 5663, 2506, 5665, 2504, 5667, 2502, 5669, 2500, 5671, 2498, 5673, 2496, 5675, 2494, 5677, 2492, 5679, 2490, 5681, 2488, 5683, 2486, 5685, 2484, 5687, 2482, 5689, 2480, 5691, 2478, 5693, 2476, 5695, 2474, 5697, 2472, 5699, 2470, 5701, 2468, 5703, 2466, 5705, 2464, 5707, 2462, 5709, 2460, 5711, 2458, 5713, 2456, 5715, 2454, 5717, 2452, 5719, 2450, 5721, 2448, 5723, 2446, 5725, 2444, 5727, 2442, 5729, 2440, 5731, 2438, 5733, 2436, 5735, 2434, 5737, 2432, 5739, 2430, 5741, 2428, 5743, 2426, 5745, 2424, 5747, 2422, 5749, 2420, 5751, 2418, 5753, 2416, 5755, 2414, 5757, 2412, 5759, 2410, 5761, 2408, 5763, 2406, 5765, 2404, 5767, 2402, 5769, 2400, 5771, 2398, 5773, 2396, 5775, 2394, 5777, 2392, 5779, 2390, 5781, 2388, 5783, 2386, 5785, 2384, 5787, 2382, 5789, 2380, 5791, 2378, 5793, 2376, 5795, 2374, 5797, 2372, 5799, 2370, 5801, 2368, 5803, 2366, 5805, 2364, 5807, 2362, 5809, 2360, 5811, 2358, 5813, 2356, 5815, 2354, 5817, 2352, 5819, 2350, 5821, 2348, 5823, 2346, 5825, 2344, 5827, 2342, 5829, 2340, 5831, 2338, 5833, 2336, 5835, 2334, 5837, 2332, 5839, 2330, 5841, 2328, 5843, 2326, 5845, 2324, 5847, 2322, 5849, 2320, 5851, 2318, 5853, 2316, 5855, 2314, 5857, 2312, 5859, 2310, 5861, 2308, 5863, 2306, 5865, 2304, 5867, 2302, 5869, 2300, 5871, 2298, 5873, 2296, 5875, 2294, 5877, 2292, 5879, 2290, 5881, 2288, 5883, 2286, 5885, 2284, 5887, 2282, 5889, 2280, 5891, 2278, 5893, 2276, 5895, 2274, 5897, 2272, 5899, 2270, 5901, 2268, 5903, 2266, 5905, 2264, 5907, 2262, 5909, 2260, 5911, 2258, 5913, 2256, 5915, 2254, 5917, 2252, 5919, 2250, 5921, 2248, 5923, 2246, 5925, 2244, 5927, 2242, 5929, 2240, 5931, 2238, 5933, 2236, 5935, 2234, 5937, 2232, 5939, 2230, 5941, 2228, 5943, 2226, 5945, 2224, 5947, 2222, 5949, 2220, 5951, 2218, 5953, 2216, 5955, 2214, 5957, 2212, 5959, 2210, 5961, 2208, 5963, 2206, 5965, 2204, 5967, 2202, 5969, 2200, 5971, 2198, 5973, 2196, 5975, 2194, 5977, 2192, 5979, 2190, 5981, 2188, 5983, 2186, 5985, 2184, 5987, 2182, 5989, 2180, 5991, 2178, 5993, 2176, 5995, 2174, 5997, 2172, 5999, 2170, 6001, 2168, 6003, 2166, 6005, 2164, 6007, 2162, 6009, 2160, 6011, 2158, 6013, 2156, 6015, 2154, 6017, 2152, 6019, 2150, 6021, 2148, 6023, 2146, 6025, 2144, 6027, 2142, 6029, 2140, 6031, 2138, 6033, 2136, 6035, 2134, 6037, 2132, 6039, 2130, 6041, 2128, 6043, 2126, 6045, 2124, 6047, 2122, 6049, 2120, 6051, 2118, 6053, 2116, 6055, 2114, 6057, 2112, 6059, 2110, 6061, 2108, 6063, 2106, 6065, 2104, 6067, 2102, 6069, 2100, 6071, 2098, 6073, 2096, 6075, 2094, 6077, 2092, 6079, 2090, 6081, 2088, 6083, 2086, 6085, 2084, 6087, 2082, 6089, 2080, 6091, 2078, 6093, 2076, 6095, 2074, 6097, 2072, 6099, 2070, 6101, 2068, 6103, 2066, 6105, 2064, 6107, 2062, 6109, 2060, 6111, 2058, 6113, 2056, 6115, 2054, 6117, 2052, 6119, 2050, 6121, 2048, 6123, 2046, 6125, 2044, 6127, 2042, 6129, 2040, 6131, 2038, 6133, 2036, 6135, 2034, 6137, 2032, 6139, 2030, 6141, 2028, 6143, 2026, 6145, 2024, 6147, 2022, 6149, 2020, 6151, 2018, 6153, 2016, 6155, 2014, 6157, 2012, 6159, 2010, 6161, 2008, 6163, 2006, 6165, 2004, 6167, 2002, 6169, 2000, 6171, 1998, 6173, 1996, 6175, 1994, 6177, 1992, 6179, 1990, 6181, 1988, 6183, 1986, 6185, 1984, 6187, 1982, 6189, 1980, 6191, 1978, 6193, 1976, 6195, 1974, 6197, 1972, 6199, 1970, 6201, 1968, 6203, 1966, 6205, 1964, 6207, 1962, 6209, 1960, 6211, 1958, 6213, 1956, 6215, 1954, 6217, 1952, 6219, 1950, 6221, 1948, 6223, 1946, 6225, 1944, 6227, 1942, 6229, 1940, 6231, 1938, 6233, 1936, 6235, 1934, 6237, 1932, 6239, 1930, 6241, 1928, 6243, 1926, 6245, 1924, 6247, 1922, 6249, 1920, 6251, 1918, 6253, 1916, 6255, 1914, 6257, 1912, 6259, 1910, 6261, 1908, 6263, 1906, 6265, 1904, 6267, 1902, 6269, 1900, 6271, 1898, 6273, 1896, 6275, 1894, 6277, 1892, 6279, 1890, 6281, 1888, 6283, 1886, 6285, 1884, 6287, 1882, 6289, 1880, 6291, 1878, 6293, 1876, 6295, 1874, 6297, 1872, 6299, 1870, 6301, 1868, 6303, 1866, 6305, 1864, 6307, 1862, 6309, 1860, 6311, 1858, 6313, 1856, 6315, 1854, 6317, 1852, 6319, 1850, 6321, 1848, 6323, 1846, 6325, 1844, 6327, 1842, 6329, 1840, 6331, 1838, 6333, 1836, 6335, 1834, 6337, 1832, 6339, 1830, 6341, 1828, 6343, 1826, 6345, 1824, 6347, 1822, 6349, 1820, 6351, 1818, 6353, 1816, 6355, 1814, 6357, 1812, 6359, 1810, 6361, 1808, 6363, 1806, 6365, 1804, 6367, 1802, 6369, 1800, 6371, 1798, 6373, 1796, 6375, 1794, 6377, 1792, 6379, 1790, 6381, 1788, 6383, 1786, 6385, 1784, 6387, 1782, 6389, 1780, 6391, 1778, 6393, 1776, 6395, 1774, 6397, 1772, 6399, 1770, 6401, 1768, 6403, 1766, 6405, 1764, 6407, 1762, 6409, 1760, 6411, 1758, 6413, 1756, 6415, 1754, 6417, 1752, 6419, 1750, 6421, 1748, 6423, 1746, 6425, 1744, 6427, 1742, 6429, 1740, 6431, 1738, 6433, 1736, 6435, 1734, 6437, 1732, 6439, 1730, 6441, 1728, 6443, 1726, 6445, 1724, 6447, 1722, 6449, 1720, 6451, 1718, 6453, 1716, 6455, 1714, 6457, 1712, 6459, 1710, 6461, 1708, 6463, 1706, 6465, 1704, 6467, 1702, 6469, 1700, 6471, 1698, 6473, 1696, 6475, 1694, 6477, 1692, 6479, 1690, 6481, 1688, 6483, 1686, 6485, 1684, 6487, 1682, 6489, 1680, 6491, 1678, 6493, 1676, 6495, 1674, 6497, 1672, 6499, 1670, 6501, 1668, 6503, 1666, 6505, 1664, 6507, 1662, 6509, 1660, 6511, 1658, 6513, 1656, 6515, 1654, 6517, 1652, 6519, 1650, 6521, 1648, 6523, 1646, 6525, 1644, 6527, 1642, 6529, 1640, 6531, 1638, 6533, 1636, 6535, 1634, 6537, 1632, 6539, 1630, 6541, 1628, 6543, 1626, 6545, 1624, 6547, 1622, 6549, 1620, 6551, 1618, 6553, 1616, 6555, 1614, 6557, 1612, 6559, 1610, 6561, 1608, 6563, 1606, 6565, 1604, 6567, 1602, 6569, 1600, 6571, 1598, 6573, 1596, 6575, 1594, 6577, 1592, 6579, 1590, 6581, 1588, 6583, 1586, 6585, 1584, 6587, 1582, 6589, 1580, 6591, 1578, 6593, 1576, 6595, 1574, 6597, 1572, 6599, 1570, 6601, 1568, 6603, 1566, 6605, 1564, 6607, 1562, 6609, 1560, 6611, 1558, 6613, 1556, 6615, 1554, 6617, 1552, 6619, 1550, 6621, 1548, 6623, 1546, 6625, 1544, 6627, 1542, 6629, 1540, 6631, 1538, 6633, 1536, 6635, 1534, 6637, 1532, 6639, 1530, 6641, 1528, 6643, 1526, 6645, 1524, 6647, 1522, 6649, 1520, 6651, 1518, 6653, 1516, 6655, 1514, 6657, 1512, 6659, 1510, 6661, 1508, 6663, 1506, 6665, 1504, 6667, 1502, 6669, 1500, 6671, 1498, 6673, 1496, 6675, 1494, 6677, 1492, 6679, 1490, 6681, 1488, 6683, 1486, 6685, 1484, 6687, 1482, 6689, 1480, 6691, 1478, 6693, 1476, 6695, 1474, 6697, 1472, 6699, 1470, 6701, 1468, 6703, 1466, 6705, 1464, 6707, 1462, 6709, 1460, 6711, 1458, 6713, 1456, 6715, 1454, 6717, 1452, 6719, 1450, 6721, 1448, 6723, 1446, 6725, 1444, 6727, 1442, 6729, 1440, 6731, 1438, 6733, 1436, 6735, 1434, 6737, 1432, 6739, 1430, 6741, 1428, 6743, 1426, 6745, 1424, 6747, 1422, 6749, 1420, 6751, 1418, 6753, 1416, 6755, 1414, 6757, 1412, 6759, 1410, 6761, 1408, 6763, 1406, 6765, 1404, 6767, 1402, 6769, 1400, 6771, 1398, 6773, 1396, 6775, 1394, 6777, 1392, 6779, 1390, 6781, 1388, 6783, 1386, 6785, 1384, 6787, 1382, 6789, 1380, 6791, 1378, 6793, 1376, 6795, 1374, 6797, 1372, 6799, 1370, 6801, 1368, 6803, 1366, 6805, 1364, 6807, 1362, 6809, 1360, 6811, 1358, 6813, 1356, 6815, 1354, 6817, 1352, 6819, 1350, 6821, 1348, 6823, 1346, 6825, 1344, 6827, 1342, 6829, 1340, 6831, 1338, 6833, 1336, 6835, 1334, 6837, 1332, 6839, 1330, 6841, 1328, 6843, 1326, 6845, 1324, 6847, 1322, 6849, 1320, 6851, 1318, 6853, 1316, 6855, 1314, 6857, 1312, 6859, 1310, 6861, 1308, 6863, 1306, 6865, 1304, 6867, 1302, 6869, 1300, 6871, 1298, 6873, 1296, 6875, 1294, 6877, 1292, 6879, 1290, 6881, 1288, 6883, 1286, 6885, 1284, 6887, 1282, 6889, 1280, 6891, 1278, 6893, 1276, 6895, 1274, 6897, 1272, 6899, 1270, 6901, 1268, 6903, 1266, 6905, 1264, 6907, 1262, 6909, 1260, 6911, 1258, 6913, 1256, 6915, 1254, 6917, 1252, 6919, 1250, 6921, 1248, 6923, 1246, 6925, 1244, 6927, 1242, 6929, 1240, 6931, 1238, 6933, 1236, 6935, 1234, 6937, 1232, 6939, 1230, 6941, 1228, 6943, 1226, 6945, 1224, 6947, 1222, 6949, 1220, 6951, 1218, 6953, 1216, 6955, 1214, 6957, 1212, 6959, 1210, 6961, 1208, 6963, 1206, 6965, 1204, 6967, 1202, 6969, 1200, 6971, 1198, 6973, 1196, 6975, 1194, 6977, 1192, 6979, 1190, 6981, 1188, 6983, 1186, 6985, 1184, 6987, 1182, 6989, 1180, 6991, 1178, 6993, 1176, 6995, 1174, 6997, 1172, 6999, 1170, 7001, 1168, 7003, 1166, 7005, 1164, 7007, 1162, 7009, 1160, 7011, 1158, 7013, 1156, 7015, 1154, 7017, 1152, 7019, 1150, 7021, 1148, 7023, 1146, 7025, 1144, 7027, 1142, 7029, 1140, 7031, 1138, 7033, 1136, 7035, 1134, 7037, 1132, 7039, 1130, 7041, 1128, 7043, 1126, 7045, 1124, 7047, 1122, 7049, 1120, 7051, 1118, 7053, 1116, 7055, 1114, 7057, 1112, 7059, 1110, 7061, 1108, 7063, 1106, 7065, 1104, 7067, 1102, 7069, 1100, 7071, 1098, 7073, 1096, 7075, 1094, 7077, 1092, 7079, 1090, 7081, 1088, 7083, 1086, 7085, 1084, 7087, 1082, 7089, 1080, 7091, 1078, 7093, 1076, 7095, 1074, 7097, 1072, 7099, 1070, 7101, 1068, 7103, 1066, 7105, 1064, 7107, 1062, 7109, 1060, 7111, 1058, 7113, 1056, 7115, 1054, 7117, 1052, 7119, 1050, 7121, 1048, 7123, 1046, 7125, 1044, 7127, 1042, 7129, 1040, 7131, 1038, 7133, 1036, 7135, 1034, 7137, 1032, 7139, 1030, 7141, 1028, 7143, 1026, 7145, 1024, 7147, 1022, 7149, 1020, 7151, 1018, 7153, 1016, 7155, 1014, 7157, 1012, 7159, 1010, 7161, 1008, 7163, 1006, 7165, 1004, 7167, 1002, 7169, 1000, 7171, 998, 7173, 996, 7175, 994, 7177, 992, 7179, 990, 7181, 988, 7183, 986, 7185, 984, 7187, 982, 7189, 980, 7191, 978, 7193, 976, 7195, 974, 7197, 972, 7199, 970, 7201, 968, 7203, 966, 7205, 964, 7207, 962, 7209, 960, 7211, 958, 7213, 956, 7215, 954, 7217, 952, 7219, 950, 7221, 948, 7223, 946, 7225, 944, 7227, 942, 7229, 940, 7231, 938, 7233, 936, 7235, 934, 7237, 932, 7239, 930, 7241, 928, 7243, 926, 7245, 924, 7247, 922, 7249, 920, 7251, 918, 7253, 916, 7255, 914, 7257, 912, 7259, 910, 7261, 908, 7263, 906, 7265, 904, 7267, 902, 7269, 900, 7271, 898, 7273, 896, 7275, 894, 7277, 892, 7279, 890, 7281, 888, 7283, 886, 7285, 884, 7287, 882, 7289, 880, 7291, 878, 7293, 876, 7295, 874, 7297, 872, 7299, 870, 7301, 868, 7303, 866, 7305, 864, 7307, 862, 7309, 860, 7311, 858, 7313, 856, 7315, 854, 7317, 852, 7319, 850, 7321, 848, 7323, 846, 7325, 844, 7327, 842, 7329, 840, 7331, 838, 7333, 836, 7335, 834, 7337, 832, 7339, 830, 7341, 828, 7343, 826, 7345, 824, 7347, 822, 7349, 820, 7351, 818, 7353, 816, 7355, 814, 7357, 812, 7359, 810, 7361, 808, 7363, 806, 7365, 804, 7367, 802, 7369, 800, 7371, 798, 7373, 796, 7375, 794, 7377, 792, 7379, 790, 7381, 788, 7383, 786, 7385, 784, 7387, 782, 7389, 780, 7391, 778, 7393, 776, 7395, 774, 7397, 772, 7399, 770, 7401, 768, 7403, 766, 7405, 764, 7407, 762, 7409, 760, 7411, 758, 7413, 756, 7415, 754, 7417, 752, 7419, 750, 7421, 748, 7423, 746, 7425, 744, 7427, 742, 7429, 740, 7431, 738, 7433, 736, 7435, 734, 7437, 732, 7439, 730, 7441, 728, 7443, 726, 7445, 724, 7447, 722, 7449, 720, 7451, 718, 7453, 716, 7455, 714, 7457, 712, 7459, 710, 7461, 708, 7463, 706, 7465, 704, 7467, 702, 7469, 700, 7471, 698, 7473, 696, 7475, 694, 7477, 692, 7479, 690, 7481, 688, 7483, 686, 7485, 684, 7487, 682, 7489, 680, 7491, 678, 7493, 676, 7495, 674, 7497, 672, 7499, 670, 7501, 668, 7503, 666, 7505, 664, 7507, 662, 7509, 660, 7511, 658, 7513, 656, 7515, 654, 7517, 652, 7519, 650, 7521, 648, 7523, 646, 7525, 644, 7527, 642, 7529, 640, 7531, 638, 7533, 636, 7535, 634, 7537, 632, 7539, 630, 7541, 628, 7543, 626, 7545, 624, 7547, 622, 7549, 620, 7551, 618, 7553, 616, 7555, 614, 7557, 612, 7559, 610, 7561, 608, 7563, 606, 7565, 604, 7567, 602, 7569, 600, 7571, 598, 7573, 596, 7575, 594, 7577, 592, 7579, 590, 7581, 588, 7583, 586, 7585, 584, 7587, 582, 7589, 580, 7591, 578, 7593, 576, 7595, 574, 7597, 572, 7599, 570, 7601, 568, 7603, 566, 7605, 564, 7607, 562, 7609, 560, 7611, 558, 7613, 556, 7615, 554, 7617, 552, 7619, 550, 7621, 548, 7623, 546, 7625, 544, 7627, 542, 7629, 540, 7631, 538, 7633, 536, 7635, 534, 7637, 532, 7639, 530, 7641, 528, 7643, 526, 7645, 524, 7647, 522, 7649, 520, 7651, 518, 7653, 516, 7655, 514, 7657, 512, 7659, 510, 7661, 508, 7663, 506, 7665, 504, 7667, 502, 7669, 500, 7671, 498, 7673, 496, 7675, 494, 7677, 492, 7679, 490, 7681, 488, 7683, 486, 7685, 484, 7687, 482, 7689, 480, 7691, 478, 7693, 476, 7695, 474, 7697, 472, 7699, 470, 7701, 468, 7703, 466, 7705, 464, 7707, 462, 7709, 460, 7711, 458, 7713, 456, 7715, 454, 7717, 452, 7719, 450, 7721, 448, 7723, 446, 7725, 444, 7727, 442, 7729, 440, 7731, 438, 7733, 436, 7735, 434, 7737, 432, 7739, 430, 7741, 428, 7743, 426, 7745, 424, 7747, 422, 7749, 420, 7751, 418, 7753, 416, 7755, 414, 7757, 412, 7759, 410, 7761, 408, 7763, 406, 7765, 404, 7767, 402, 7769, 400, 7771, 398, 7773, 396, 7775, 394, 7777, 392, 7779, 390, 7781, 388, 7783, 386, 7785, 384, 7787, 382, 7789, 380, 7791, 378, 7793, 376, 7795, 374, 7797, 372, 7799, 370, 7801, 368, 7803, 366, 7805, 364, 7807, 362, 7809, 360, 7811, 358, 7813, 356, 7815, 354, 7817, 352, 7819, 350, 7821, 348, 7823, 346, 7825, 344, 7827, 342, 7829, 340, 7831, 338, 7833, 336, 7835, 334, 7837, 332, 7839, 330, 7841, 328, 7843, 326, 7845, 324, 7847, 322, 7849, 320, 7851, 318, 7853, 316, 7855, 314, 7857, 312, 7859, 310, 7861, 308, 7863, 306, 7865, 304, 7867, 302, 7869, 300, 7871, 298, 7873, 296, 7875, 294, 7877, 292, 7879, 290, 7881, 288, 7883, 286, 7885, 284, 7887, 282, 7889, 280, 7891, 278, 7893, 276, 7895, 274, 7897, 272, 7899, 270, 7901, 268, 7903, 266, 7905, 264, 7907, 262, 7909, 260, 7911, 258, 7913, 256, 7915, 254, 7917, 252, 7919, 250, 7921, 248, 7923, 246, 7925, 244, 7927, 242, 7929, 240, 7931, 238, 7933, 236, 7935, 234, 7937, 232, 7939, 230, 7941, 228, 7943, 226, 7945, 224, 7947, 222, 7949, 220, 7951, 218, 7953, 216, 7955, 214, 7957, 212, 7959, 210, 7961, 208, 7963, 206, 7965, 204, 7967, 202, 7969, 200, 7971, 198, 7973, 196, 7975, 194, 7977, 192, 7979, 190, 7981, 188, 7983, 186, 7985, 184, 7987, 182, 7989, 180, 7991, 178, 7993, 176, 7995, 174, 7997, 172, 7999, 170, 8001, 168, 8003, 166, 8005, 164, 8007, 162, 8009, 160, 8011, 158, 8013, 156, 8015, 154, 8017, 152, 8019, 150, 8021, 148, 8023, 146, 8025, 144, 8027, 142, 8029, 140, 8031, 138, 8033, 136, 8035, 134, 8037, 132, 8039, 130, 8041, 128, 8043, 126, 8045, 124, 8047, 122, 8049, 120, 8051, 118, 8053, 116, 8055, 114, 8057, 112, 8059, 110, 8061, 108, 8063, 106, 8065, 104, 8067, 102, 8069, 100, 8071, 98, 8073, 96, 8075, 94, 8077, 92, 8079, 90, 8081, 88, 8083, 86, 8085, 84, 8087, 82, 8089, 80, 8091, 78, 8093, 76, 8095, 74, 8097, 72, 8099, 70, 8101, 68, 8103, 66, 8105, 64, 8107, 62, 8109, 60, 8111, 58, 8113, 56, 8115, 54, 8117, 52, 8119, 50, 8121, 48, 8123, 46, 8125, 44, 8127, 42, 8129, 40, 8131, 38, 8133, 36, 8135, 34, 8137, 32, 8139, 30, 8141, 28, 8143, 26, 8145, 24, 8147, 22, 8149, 20, 8151, 18, 8153, 16, 8155, 14, 8157, 12, 8159, 10, 8161, 8, 8163, 6, 8165, 4, 8167, 2, 8169]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-sum-permutation-l5-s1/tests/check.py b/tasks/construct-rlve-prefix-sum-permutation-l5-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..60c3e0996cdfa8673fd7f34ad70cccb789b17654 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l5-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-l5-s1/tests/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l5-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9a0e43c25035f34824f1fa548c47db4b0fc26af9 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l5-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 8170, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l5-s1/tests/run.py b/tasks/construct-rlve-prefix-sum-permutation-l5-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-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-rlve-prefix-sum-permutation-l5-s1/tests/test.sh b/tasks/construct-rlve-prefix-sum-permutation-l5-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-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-rlve-prefix-sum-permutation-l5-s6/environment/Dockerfile b/tasks/construct-rlve-prefix-sum-permutation-l5-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l5-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-l5-s6/environment/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l5-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5605d3bb0630cb9523e7e022c608611acd2aa3d1 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l5-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 2806, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l5-s6/solution/solve.sh b/tasks/construct-rlve-prefix-sum-permutation-l5-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..316b24bc5d2b5440b92ef3d3c8624872f1434125 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l5-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": [2806, 1, 2804, 3, 2802, 5, 2800, 7, 2798, 9, 2796, 11, 2794, 13, 2792, 15, 2790, 17, 2788, 19, 2786, 21, 2784, 23, 2782, 25, 2780, 27, 2778, 29, 2776, 31, 2774, 33, 2772, 35, 2770, 37, 2768, 39, 2766, 41, 2764, 43, 2762, 45, 2760, 47, 2758, 49, 2756, 51, 2754, 53, 2752, 55, 2750, 57, 2748, 59, 2746, 61, 2744, 63, 2742, 65, 2740, 67, 2738, 69, 2736, 71, 2734, 73, 2732, 75, 2730, 77, 2728, 79, 2726, 81, 2724, 83, 2722, 85, 2720, 87, 2718, 89, 2716, 91, 2714, 93, 2712, 95, 2710, 97, 2708, 99, 2706, 101, 2704, 103, 2702, 105, 2700, 107, 2698, 109, 2696, 111, 2694, 113, 2692, 115, 2690, 117, 2688, 119, 2686, 121, 2684, 123, 2682, 125, 2680, 127, 2678, 129, 2676, 131, 2674, 133, 2672, 135, 2670, 137, 2668, 139, 2666, 141, 2664, 143, 2662, 145, 2660, 147, 2658, 149, 2656, 151, 2654, 153, 2652, 155, 2650, 157, 2648, 159, 2646, 161, 2644, 163, 2642, 165, 2640, 167, 2638, 169, 2636, 171, 2634, 173, 2632, 175, 2630, 177, 2628, 179, 2626, 181, 2624, 183, 2622, 185, 2620, 187, 2618, 189, 2616, 191, 2614, 193, 2612, 195, 2610, 197, 2608, 199, 2606, 201, 2604, 203, 2602, 205, 2600, 207, 2598, 209, 2596, 211, 2594, 213, 2592, 215, 2590, 217, 2588, 219, 2586, 221, 2584, 223, 2582, 225, 2580, 227, 2578, 229, 2576, 231, 2574, 233, 2572, 235, 2570, 237, 2568, 239, 2566, 241, 2564, 243, 2562, 245, 2560, 247, 2558, 249, 2556, 251, 2554, 253, 2552, 255, 2550, 257, 2548, 259, 2546, 261, 2544, 263, 2542, 265, 2540, 267, 2538, 269, 2536, 271, 2534, 273, 2532, 275, 2530, 277, 2528, 279, 2526, 281, 2524, 283, 2522, 285, 2520, 287, 2518, 289, 2516, 291, 2514, 293, 2512, 295, 2510, 297, 2508, 299, 2506, 301, 2504, 303, 2502, 305, 2500, 307, 2498, 309, 2496, 311, 2494, 313, 2492, 315, 2490, 317, 2488, 319, 2486, 321, 2484, 323, 2482, 325, 2480, 327, 2478, 329, 2476, 331, 2474, 333, 2472, 335, 2470, 337, 2468, 339, 2466, 341, 2464, 343, 2462, 345, 2460, 347, 2458, 349, 2456, 351, 2454, 353, 2452, 355, 2450, 357, 2448, 359, 2446, 361, 2444, 363, 2442, 365, 2440, 367, 2438, 369, 2436, 371, 2434, 373, 2432, 375, 2430, 377, 2428, 379, 2426, 381, 2424, 383, 2422, 385, 2420, 387, 2418, 389, 2416, 391, 2414, 393, 2412, 395, 2410, 397, 2408, 399, 2406, 401, 2404, 403, 2402, 405, 2400, 407, 2398, 409, 2396, 411, 2394, 413, 2392, 415, 2390, 417, 2388, 419, 2386, 421, 2384, 423, 2382, 425, 2380, 427, 2378, 429, 2376, 431, 2374, 433, 2372, 435, 2370, 437, 2368, 439, 2366, 441, 2364, 443, 2362, 445, 2360, 447, 2358, 449, 2356, 451, 2354, 453, 2352, 455, 2350, 457, 2348, 459, 2346, 461, 2344, 463, 2342, 465, 2340, 467, 2338, 469, 2336, 471, 2334, 473, 2332, 475, 2330, 477, 2328, 479, 2326, 481, 2324, 483, 2322, 485, 2320, 487, 2318, 489, 2316, 491, 2314, 493, 2312, 495, 2310, 497, 2308, 499, 2306, 501, 2304, 503, 2302, 505, 2300, 507, 2298, 509, 2296, 511, 2294, 513, 2292, 515, 2290, 517, 2288, 519, 2286, 521, 2284, 523, 2282, 525, 2280, 527, 2278, 529, 2276, 531, 2274, 533, 2272, 535, 2270, 537, 2268, 539, 2266, 541, 2264, 543, 2262, 545, 2260, 547, 2258, 549, 2256, 551, 2254, 553, 2252, 555, 2250, 557, 2248, 559, 2246, 561, 2244, 563, 2242, 565, 2240, 567, 2238, 569, 2236, 571, 2234, 573, 2232, 575, 2230, 577, 2228, 579, 2226, 581, 2224, 583, 2222, 585, 2220, 587, 2218, 589, 2216, 591, 2214, 593, 2212, 595, 2210, 597, 2208, 599, 2206, 601, 2204, 603, 2202, 605, 2200, 607, 2198, 609, 2196, 611, 2194, 613, 2192, 615, 2190, 617, 2188, 619, 2186, 621, 2184, 623, 2182, 625, 2180, 627, 2178, 629, 2176, 631, 2174, 633, 2172, 635, 2170, 637, 2168, 639, 2166, 641, 2164, 643, 2162, 645, 2160, 647, 2158, 649, 2156, 651, 2154, 653, 2152, 655, 2150, 657, 2148, 659, 2146, 661, 2144, 663, 2142, 665, 2140, 667, 2138, 669, 2136, 671, 2134, 673, 2132, 675, 2130, 677, 2128, 679, 2126, 681, 2124, 683, 2122, 685, 2120, 687, 2118, 689, 2116, 691, 2114, 693, 2112, 695, 2110, 697, 2108, 699, 2106, 701, 2104, 703, 2102, 705, 2100, 707, 2098, 709, 2096, 711, 2094, 713, 2092, 715, 2090, 717, 2088, 719, 2086, 721, 2084, 723, 2082, 725, 2080, 727, 2078, 729, 2076, 731, 2074, 733, 2072, 735, 2070, 737, 2068, 739, 2066, 741, 2064, 743, 2062, 745, 2060, 747, 2058, 749, 2056, 751, 2054, 753, 2052, 755, 2050, 757, 2048, 759, 2046, 761, 2044, 763, 2042, 765, 2040, 767, 2038, 769, 2036, 771, 2034, 773, 2032, 775, 2030, 777, 2028, 779, 2026, 781, 2024, 783, 2022, 785, 2020, 787, 2018, 789, 2016, 791, 2014, 793, 2012, 795, 2010, 797, 2008, 799, 2006, 801, 2004, 803, 2002, 805, 2000, 807, 1998, 809, 1996, 811, 1994, 813, 1992, 815, 1990, 817, 1988, 819, 1986, 821, 1984, 823, 1982, 825, 1980, 827, 1978, 829, 1976, 831, 1974, 833, 1972, 835, 1970, 837, 1968, 839, 1966, 841, 1964, 843, 1962, 845, 1960, 847, 1958, 849, 1956, 851, 1954, 853, 1952, 855, 1950, 857, 1948, 859, 1946, 861, 1944, 863, 1942, 865, 1940, 867, 1938, 869, 1936, 871, 1934, 873, 1932, 875, 1930, 877, 1928, 879, 1926, 881, 1924, 883, 1922, 885, 1920, 887, 1918, 889, 1916, 891, 1914, 893, 1912, 895, 1910, 897, 1908, 899, 1906, 901, 1904, 903, 1902, 905, 1900, 907, 1898, 909, 1896, 911, 1894, 913, 1892, 915, 1890, 917, 1888, 919, 1886, 921, 1884, 923, 1882, 925, 1880, 927, 1878, 929, 1876, 931, 1874, 933, 1872, 935, 1870, 937, 1868, 939, 1866, 941, 1864, 943, 1862, 945, 1860, 947, 1858, 949, 1856, 951, 1854, 953, 1852, 955, 1850, 957, 1848, 959, 1846, 961, 1844, 963, 1842, 965, 1840, 967, 1838, 969, 1836, 971, 1834, 973, 1832, 975, 1830, 977, 1828, 979, 1826, 981, 1824, 983, 1822, 985, 1820, 987, 1818, 989, 1816, 991, 1814, 993, 1812, 995, 1810, 997, 1808, 999, 1806, 1001, 1804, 1003, 1802, 1005, 1800, 1007, 1798, 1009, 1796, 1011, 1794, 1013, 1792, 1015, 1790, 1017, 1788, 1019, 1786, 1021, 1784, 1023, 1782, 1025, 1780, 1027, 1778, 1029, 1776, 1031, 1774, 1033, 1772, 1035, 1770, 1037, 1768, 1039, 1766, 1041, 1764, 1043, 1762, 1045, 1760, 1047, 1758, 1049, 1756, 1051, 1754, 1053, 1752, 1055, 1750, 1057, 1748, 1059, 1746, 1061, 1744, 1063, 1742, 1065, 1740, 1067, 1738, 1069, 1736, 1071, 1734, 1073, 1732, 1075, 1730, 1077, 1728, 1079, 1726, 1081, 1724, 1083, 1722, 1085, 1720, 1087, 1718, 1089, 1716, 1091, 1714, 1093, 1712, 1095, 1710, 1097, 1708, 1099, 1706, 1101, 1704, 1103, 1702, 1105, 1700, 1107, 1698, 1109, 1696, 1111, 1694, 1113, 1692, 1115, 1690, 1117, 1688, 1119, 1686, 1121, 1684, 1123, 1682, 1125, 1680, 1127, 1678, 1129, 1676, 1131, 1674, 1133, 1672, 1135, 1670, 1137, 1668, 1139, 1666, 1141, 1664, 1143, 1662, 1145, 1660, 1147, 1658, 1149, 1656, 1151, 1654, 1153, 1652, 1155, 1650, 1157, 1648, 1159, 1646, 1161, 1644, 1163, 1642, 1165, 1640, 1167, 1638, 1169, 1636, 1171, 1634, 1173, 1632, 1175, 1630, 1177, 1628, 1179, 1626, 1181, 1624, 1183, 1622, 1185, 1620, 1187, 1618, 1189, 1616, 1191, 1614, 1193, 1612, 1195, 1610, 1197, 1608, 1199, 1606, 1201, 1604, 1203, 1602, 1205, 1600, 1207, 1598, 1209, 1596, 1211, 1594, 1213, 1592, 1215, 1590, 1217, 1588, 1219, 1586, 1221, 1584, 1223, 1582, 1225, 1580, 1227, 1578, 1229, 1576, 1231, 1574, 1233, 1572, 1235, 1570, 1237, 1568, 1239, 1566, 1241, 1564, 1243, 1562, 1245, 1560, 1247, 1558, 1249, 1556, 1251, 1554, 1253, 1552, 1255, 1550, 1257, 1548, 1259, 1546, 1261, 1544, 1263, 1542, 1265, 1540, 1267, 1538, 1269, 1536, 1271, 1534, 1273, 1532, 1275, 1530, 1277, 1528, 1279, 1526, 1281, 1524, 1283, 1522, 1285, 1520, 1287, 1518, 1289, 1516, 1291, 1514, 1293, 1512, 1295, 1510, 1297, 1508, 1299, 1506, 1301, 1504, 1303, 1502, 1305, 1500, 1307, 1498, 1309, 1496, 1311, 1494, 1313, 1492, 1315, 1490, 1317, 1488, 1319, 1486, 1321, 1484, 1323, 1482, 1325, 1480, 1327, 1478, 1329, 1476, 1331, 1474, 1333, 1472, 1335, 1470, 1337, 1468, 1339, 1466, 1341, 1464, 1343, 1462, 1345, 1460, 1347, 1458, 1349, 1456, 1351, 1454, 1353, 1452, 1355, 1450, 1357, 1448, 1359, 1446, 1361, 1444, 1363, 1442, 1365, 1440, 1367, 1438, 1369, 1436, 1371, 1434, 1373, 1432, 1375, 1430, 1377, 1428, 1379, 1426, 1381, 1424, 1383, 1422, 1385, 1420, 1387, 1418, 1389, 1416, 1391, 1414, 1393, 1412, 1395, 1410, 1397, 1408, 1399, 1406, 1401, 1404, 1403, 1402, 1405, 1400, 1407, 1398, 1409, 1396, 1411, 1394, 1413, 1392, 1415, 1390, 1417, 1388, 1419, 1386, 1421, 1384, 1423, 1382, 1425, 1380, 1427, 1378, 1429, 1376, 1431, 1374, 1433, 1372, 1435, 1370, 1437, 1368, 1439, 1366, 1441, 1364, 1443, 1362, 1445, 1360, 1447, 1358, 1449, 1356, 1451, 1354, 1453, 1352, 1455, 1350, 1457, 1348, 1459, 1346, 1461, 1344, 1463, 1342, 1465, 1340, 1467, 1338, 1469, 1336, 1471, 1334, 1473, 1332, 1475, 1330, 1477, 1328, 1479, 1326, 1481, 1324, 1483, 1322, 1485, 1320, 1487, 1318, 1489, 1316, 1491, 1314, 1493, 1312, 1495, 1310, 1497, 1308, 1499, 1306, 1501, 1304, 1503, 1302, 1505, 1300, 1507, 1298, 1509, 1296, 1511, 1294, 1513, 1292, 1515, 1290, 1517, 1288, 1519, 1286, 1521, 1284, 1523, 1282, 1525, 1280, 1527, 1278, 1529, 1276, 1531, 1274, 1533, 1272, 1535, 1270, 1537, 1268, 1539, 1266, 1541, 1264, 1543, 1262, 1545, 1260, 1547, 1258, 1549, 1256, 1551, 1254, 1553, 1252, 1555, 1250, 1557, 1248, 1559, 1246, 1561, 1244, 1563, 1242, 1565, 1240, 1567, 1238, 1569, 1236, 1571, 1234, 1573, 1232, 1575, 1230, 1577, 1228, 1579, 1226, 1581, 1224, 1583, 1222, 1585, 1220, 1587, 1218, 1589, 1216, 1591, 1214, 1593, 1212, 1595, 1210, 1597, 1208, 1599, 1206, 1601, 1204, 1603, 1202, 1605, 1200, 1607, 1198, 1609, 1196, 1611, 1194, 1613, 1192, 1615, 1190, 1617, 1188, 1619, 1186, 1621, 1184, 1623, 1182, 1625, 1180, 1627, 1178, 1629, 1176, 1631, 1174, 1633, 1172, 1635, 1170, 1637, 1168, 1639, 1166, 1641, 1164, 1643, 1162, 1645, 1160, 1647, 1158, 1649, 1156, 1651, 1154, 1653, 1152, 1655, 1150, 1657, 1148, 1659, 1146, 1661, 1144, 1663, 1142, 1665, 1140, 1667, 1138, 1669, 1136, 1671, 1134, 1673, 1132, 1675, 1130, 1677, 1128, 1679, 1126, 1681, 1124, 1683, 1122, 1685, 1120, 1687, 1118, 1689, 1116, 1691, 1114, 1693, 1112, 1695, 1110, 1697, 1108, 1699, 1106, 1701, 1104, 1703, 1102, 1705, 1100, 1707, 1098, 1709, 1096, 1711, 1094, 1713, 1092, 1715, 1090, 1717, 1088, 1719, 1086, 1721, 1084, 1723, 1082, 1725, 1080, 1727, 1078, 1729, 1076, 1731, 1074, 1733, 1072, 1735, 1070, 1737, 1068, 1739, 1066, 1741, 1064, 1743, 1062, 1745, 1060, 1747, 1058, 1749, 1056, 1751, 1054, 1753, 1052, 1755, 1050, 1757, 1048, 1759, 1046, 1761, 1044, 1763, 1042, 1765, 1040, 1767, 1038, 1769, 1036, 1771, 1034, 1773, 1032, 1775, 1030, 1777, 1028, 1779, 1026, 1781, 1024, 1783, 1022, 1785, 1020, 1787, 1018, 1789, 1016, 1791, 1014, 1793, 1012, 1795, 1010, 1797, 1008, 1799, 1006, 1801, 1004, 1803, 1002, 1805, 1000, 1807, 998, 1809, 996, 1811, 994, 1813, 992, 1815, 990, 1817, 988, 1819, 986, 1821, 984, 1823, 982, 1825, 980, 1827, 978, 1829, 976, 1831, 974, 1833, 972, 1835, 970, 1837, 968, 1839, 966, 1841, 964, 1843, 962, 1845, 960, 1847, 958, 1849, 956, 1851, 954, 1853, 952, 1855, 950, 1857, 948, 1859, 946, 1861, 944, 1863, 942, 1865, 940, 1867, 938, 1869, 936, 1871, 934, 1873, 932, 1875, 930, 1877, 928, 1879, 926, 1881, 924, 1883, 922, 1885, 920, 1887, 918, 1889, 916, 1891, 914, 1893, 912, 1895, 910, 1897, 908, 1899, 906, 1901, 904, 1903, 902, 1905, 900, 1907, 898, 1909, 896, 1911, 894, 1913, 892, 1915, 890, 1917, 888, 1919, 886, 1921, 884, 1923, 882, 1925, 880, 1927, 878, 1929, 876, 1931, 874, 1933, 872, 1935, 870, 1937, 868, 1939, 866, 1941, 864, 1943, 862, 1945, 860, 1947, 858, 1949, 856, 1951, 854, 1953, 852, 1955, 850, 1957, 848, 1959, 846, 1961, 844, 1963, 842, 1965, 840, 1967, 838, 1969, 836, 1971, 834, 1973, 832, 1975, 830, 1977, 828, 1979, 826, 1981, 824, 1983, 822, 1985, 820, 1987, 818, 1989, 816, 1991, 814, 1993, 812, 1995, 810, 1997, 808, 1999, 806, 2001, 804, 2003, 802, 2005, 800, 2007, 798, 2009, 796, 2011, 794, 2013, 792, 2015, 790, 2017, 788, 2019, 786, 2021, 784, 2023, 782, 2025, 780, 2027, 778, 2029, 776, 2031, 774, 2033, 772, 2035, 770, 2037, 768, 2039, 766, 2041, 764, 2043, 762, 2045, 760, 2047, 758, 2049, 756, 2051, 754, 2053, 752, 2055, 750, 2057, 748, 2059, 746, 2061, 744, 2063, 742, 2065, 740, 2067, 738, 2069, 736, 2071, 734, 2073, 732, 2075, 730, 2077, 728, 2079, 726, 2081, 724, 2083, 722, 2085, 720, 2087, 718, 2089, 716, 2091, 714, 2093, 712, 2095, 710, 2097, 708, 2099, 706, 2101, 704, 2103, 702, 2105, 700, 2107, 698, 2109, 696, 2111, 694, 2113, 692, 2115, 690, 2117, 688, 2119, 686, 2121, 684, 2123, 682, 2125, 680, 2127, 678, 2129, 676, 2131, 674, 2133, 672, 2135, 670, 2137, 668, 2139, 666, 2141, 664, 2143, 662, 2145, 660, 2147, 658, 2149, 656, 2151, 654, 2153, 652, 2155, 650, 2157, 648, 2159, 646, 2161, 644, 2163, 642, 2165, 640, 2167, 638, 2169, 636, 2171, 634, 2173, 632, 2175, 630, 2177, 628, 2179, 626, 2181, 624, 2183, 622, 2185, 620, 2187, 618, 2189, 616, 2191, 614, 2193, 612, 2195, 610, 2197, 608, 2199, 606, 2201, 604, 2203, 602, 2205, 600, 2207, 598, 2209, 596, 2211, 594, 2213, 592, 2215, 590, 2217, 588, 2219, 586, 2221, 584, 2223, 582, 2225, 580, 2227, 578, 2229, 576, 2231, 574, 2233, 572, 2235, 570, 2237, 568, 2239, 566, 2241, 564, 2243, 562, 2245, 560, 2247, 558, 2249, 556, 2251, 554, 2253, 552, 2255, 550, 2257, 548, 2259, 546, 2261, 544, 2263, 542, 2265, 540, 2267, 538, 2269, 536, 2271, 534, 2273, 532, 2275, 530, 2277, 528, 2279, 526, 2281, 524, 2283, 522, 2285, 520, 2287, 518, 2289, 516, 2291, 514, 2293, 512, 2295, 510, 2297, 508, 2299, 506, 2301, 504, 2303, 502, 2305, 500, 2307, 498, 2309, 496, 2311, 494, 2313, 492, 2315, 490, 2317, 488, 2319, 486, 2321, 484, 2323, 482, 2325, 480, 2327, 478, 2329, 476, 2331, 474, 2333, 472, 2335, 470, 2337, 468, 2339, 466, 2341, 464, 2343, 462, 2345, 460, 2347, 458, 2349, 456, 2351, 454, 2353, 452, 2355, 450, 2357, 448, 2359, 446, 2361, 444, 2363, 442, 2365, 440, 2367, 438, 2369, 436, 2371, 434, 2373, 432, 2375, 430, 2377, 428, 2379, 426, 2381, 424, 2383, 422, 2385, 420, 2387, 418, 2389, 416, 2391, 414, 2393, 412, 2395, 410, 2397, 408, 2399, 406, 2401, 404, 2403, 402, 2405, 400, 2407, 398, 2409, 396, 2411, 394, 2413, 392, 2415, 390, 2417, 388, 2419, 386, 2421, 384, 2423, 382, 2425, 380, 2427, 378, 2429, 376, 2431, 374, 2433, 372, 2435, 370, 2437, 368, 2439, 366, 2441, 364, 2443, 362, 2445, 360, 2447, 358, 2449, 356, 2451, 354, 2453, 352, 2455, 350, 2457, 348, 2459, 346, 2461, 344, 2463, 342, 2465, 340, 2467, 338, 2469, 336, 2471, 334, 2473, 332, 2475, 330, 2477, 328, 2479, 326, 2481, 324, 2483, 322, 2485, 320, 2487, 318, 2489, 316, 2491, 314, 2493, 312, 2495, 310, 2497, 308, 2499, 306, 2501, 304, 2503, 302, 2505, 300, 2507, 298, 2509, 296, 2511, 294, 2513, 292, 2515, 290, 2517, 288, 2519, 286, 2521, 284, 2523, 282, 2525, 280, 2527, 278, 2529, 276, 2531, 274, 2533, 272, 2535, 270, 2537, 268, 2539, 266, 2541, 264, 2543, 262, 2545, 260, 2547, 258, 2549, 256, 2551, 254, 2553, 252, 2555, 250, 2557, 248, 2559, 246, 2561, 244, 2563, 242, 2565, 240, 2567, 238, 2569, 236, 2571, 234, 2573, 232, 2575, 230, 2577, 228, 2579, 226, 2581, 224, 2583, 222, 2585, 220, 2587, 218, 2589, 216, 2591, 214, 2593, 212, 2595, 210, 2597, 208, 2599, 206, 2601, 204, 2603, 202, 2605, 200, 2607, 198, 2609, 196, 2611, 194, 2613, 192, 2615, 190, 2617, 188, 2619, 186, 2621, 184, 2623, 182, 2625, 180, 2627, 178, 2629, 176, 2631, 174, 2633, 172, 2635, 170, 2637, 168, 2639, 166, 2641, 164, 2643, 162, 2645, 160, 2647, 158, 2649, 156, 2651, 154, 2653, 152, 2655, 150, 2657, 148, 2659, 146, 2661, 144, 2663, 142, 2665, 140, 2667, 138, 2669, 136, 2671, 134, 2673, 132, 2675, 130, 2677, 128, 2679, 126, 2681, 124, 2683, 122, 2685, 120, 2687, 118, 2689, 116, 2691, 114, 2693, 112, 2695, 110, 2697, 108, 2699, 106, 2701, 104, 2703, 102, 2705, 100, 2707, 98, 2709, 96, 2711, 94, 2713, 92, 2715, 90, 2717, 88, 2719, 86, 2721, 84, 2723, 82, 2725, 80, 2727, 78, 2729, 76, 2731, 74, 2733, 72, 2735, 70, 2737, 68, 2739, 66, 2741, 64, 2743, 62, 2745, 60, 2747, 58, 2749, 56, 2751, 54, 2753, 52, 2755, 50, 2757, 48, 2759, 46, 2761, 44, 2763, 42, 2765, 40, 2767, 38, 2769, 36, 2771, 34, 2773, 32, 2775, 30, 2777, 28, 2779, 26, 2781, 24, 2783, 22, 2785, 20, 2787, 18, 2789, 16, 2791, 14, 2793, 12, 2795, 10, 2797, 8, 2799, 6, 2801, 4, 2803, 2, 2805]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-sum-permutation-l5-s6/tests/check.py b/tasks/construct-rlve-prefix-sum-permutation-l5-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..60c3e0996cdfa8673fd7f34ad70cccb789b17654 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l5-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-l5-s6/tests/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l5-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5605d3bb0630cb9523e7e022c608611acd2aa3d1 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l5-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 2806, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l5-s6/tests/run.py b/tasks/construct-rlve-prefix-sum-permutation-l5-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l5-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-l5-s6/tests/test.sh b/tasks/construct-rlve-prefix-sum-permutation-l5-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l5-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-l4-s0/environment/Dockerfile b/tasks/construct-rlve-prime-graph-coloring-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-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-prime-graph-coloring-l4-s0/environment/instance.json b/tasks/construct-rlve-prime-graph-coloring-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2d066dc7727e6a1effc67b054f8ab2dc82eb324b --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 199, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l4-s0/solution/solve.sh b/tasks/construct-rlve-prime-graph-coloring-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..73e197cf3fe84d3bd348d9bfebbd5330a0bb9062 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-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": [1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 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-l4-s0/tests/check.py b/tasks/construct-rlve-prime-graph-coloring-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b3736f1375f1862241999142c975ced361b8fcb5 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l4-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-l4-s0/tests/instance.json b/tasks/construct-rlve-prime-graph-coloring-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2d066dc7727e6a1effc67b054f8ab2dc82eb324b --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 199, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l4-s0/tests/run.py b/tasks/construct-rlve-prime-graph-coloring-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prime-graph-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-prime-graph-coloring-l4-s0/tests/test.sh b/tasks/construct-rlve-prime-graph-coloring-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-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-prime-graph-coloring-l4-s7/environment/Dockerfile b/tasks/construct-rlve-prime-graph-coloring-l4-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-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-prime-graph-coloring-l4-s7/environment/instance.json b/tasks/construct-rlve-prime-graph-coloring-l4-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e74ee021449e4414d1c3deec2262e4ea0876eda1 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l4-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 268, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l4-s7/solution/solve.sh b/tasks/construct-rlve-prime-graph-coloring-l4-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0fead859bb09b2ffe7c347e755ec28f1fce5987e --- /dev/null +++ b/tasks/construct-rlve-prime-graph-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": [1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 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-l4-s7/tests/check.py b/tasks/construct-rlve-prime-graph-coloring-l4-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b3736f1375f1862241999142c975ced361b8fcb5 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l4-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-l4-s7/tests/instance.json b/tasks/construct-rlve-prime-graph-coloring-l4-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e74ee021449e4414d1c3deec2262e4ea0876eda1 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l4-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 268, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l4-s7/tests/run.py b/tasks/construct-rlve-prime-graph-coloring-l4-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prime-graph-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-prime-graph-coloring-l4-s7/tests/test.sh b/tasks/construct-rlve-prime-graph-coloring-l4-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-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-prime-graph-coloring-l4-s9/environment/instance.json b/tasks/construct-rlve-prime-graph-coloring-l4-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8bad65e76bf0c5ce9d2a64280c0c859d712f33f4 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l4-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 274, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l6-s3/environment/Dockerfile b/tasks/construct-rlve-recursive-sequence-sum-l6-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l6-s3/environment/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l6-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4bb9689aee2f0839141491ecb152c48ce75cdaf8 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l6-s3/environment/instance.json @@ -0,0 +1 @@ +{"F0": 88, "A": 1, "B": 2172, "S": 3240592, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l6-s3/solution/solve.sh b/tasks/construct-rlve-recursive-sequence-sum-l6-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7445f4de401a77ecf471c5ed8d9331a7cf43c275 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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' +{"indices": [1, 2, 3, 4, 5, 7, 8, 10, 11, 13, 15, 16, 17, 18, 20, 21, 22, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 49, 51, 52, 53, 54, 56, 58, 59, 60]} +RLMATH_EOF diff --git a/tasks/construct-rlve-recursive-sequence-sum-l6-s3/tests/check.py b/tasks/construct-rlve-recursive-sequence-sum-l6-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..feda076c3f95e5e12198151dee30e1b8223924bc --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l6-s3/tests/check.py @@ -0,0 +1,29 @@ +from run import Invalid, int_list + + +def F(inst, n): + F0, A, B = inst["F0"], inst["A"], inst["B"] + if A == 1: + return F0 + n * B + An = A ** n + return An * F0 + B * (An - 1) // (A - 1) + + +def check(inst, ans): + S = inst["S"] + idx = int_list(ans.get("indices"), None, 1, None, "indices") + if not idx: + raise Invalid("need at least one index") + if len(set(idx)) != len(idx): + raise Invalid("indices must be distinct") + total = 0 + for n in idx: + # F is strictly increasing with F(n) >= n and, when A >= 2, F(n) >= 2^(n-1); bail out before big powers + if n > S or (inst["A"] >= 2 and n - 1 > S.bit_length()): + raise Invalid(f"F({n}) exceeds S") + total += F(inst, n) + if total > S: + raise Invalid("sum exceeds S") + if total != S: + raise Invalid(f"sum is {total}, need {S}") + return None, {} diff --git a/tasks/construct-rlve-recursive-sequence-sum-l6-s3/tests/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l6-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4bb9689aee2f0839141491ecb152c48ce75cdaf8 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l6-s3/tests/instance.json @@ -0,0 +1 @@ +{"F0": 88, "A": 1, "B": 2172, "S": 3240592, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l6-s3/tests/run.py b/tasks/construct-rlve-recursive-sequence-sum-l6-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l6-s3/tests/test.sh b/tasks/construct-rlve-recursive-sequence-sum-l6-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l6-s4/environment/Dockerfile b/tasks/construct-rlve-recursive-sequence-sum-l6-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l6-s4/environment/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l6-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b466ad477b55ce9f59c2c1e4230e8477c7eef4a0 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l6-s4/environment/instance.json @@ -0,0 +1 @@ +{"F0": 93, "A": 6, "B": 4593, "S": 57726287021072070499166522174508502366615992440421, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l6-s4/solution/solve.sh b/tasks/construct-rlve-recursive-sequence-sum-l6-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..34ac025ac88667ea3dd6dc9d9752f935f697bf15 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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' +{"indices": [1, 2, 4, 6, 7, 10, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 33, 34, 36, 37, 38, 40, 41, 43, 44, 45, 49, 50, 51, 54, 55, 56, 59, 60]} +RLMATH_EOF diff --git a/tasks/construct-rlve-recursive-sequence-sum-l6-s4/tests/check.py b/tasks/construct-rlve-recursive-sequence-sum-l6-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..feda076c3f95e5e12198151dee30e1b8223924bc --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l6-s4/tests/check.py @@ -0,0 +1,29 @@ +from run import Invalid, int_list + + +def F(inst, n): + F0, A, B = inst["F0"], inst["A"], inst["B"] + if A == 1: + return F0 + n * B + An = A ** n + return An * F0 + B * (An - 1) // (A - 1) + + +def check(inst, ans): + S = inst["S"] + idx = int_list(ans.get("indices"), None, 1, None, "indices") + if not idx: + raise Invalid("need at least one index") + if len(set(idx)) != len(idx): + raise Invalid("indices must be distinct") + total = 0 + for n in idx: + # F is strictly increasing with F(n) >= n and, when A >= 2, F(n) >= 2^(n-1); bail out before big powers + if n > S or (inst["A"] >= 2 and n - 1 > S.bit_length()): + raise Invalid(f"F({n}) exceeds S") + total += F(inst, n) + if total > S: + raise Invalid("sum exceeds S") + if total != S: + raise Invalid(f"sum is {total}, need {S}") + return None, {} diff --git a/tasks/construct-rlve-recursive-sequence-sum-l6-s4/tests/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l6-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b466ad477b55ce9f59c2c1e4230e8477c7eef4a0 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l6-s4/tests/instance.json @@ -0,0 +1 @@ +{"F0": 93, "A": 6, "B": 4593, "S": 57726287021072070499166522174508502366615992440421, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l6-s4/tests/run.py b/tasks/construct-rlve-recursive-sequence-sum-l6-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l6-s4/tests/test.sh b/tasks/construct-rlve-recursive-sequence-sum-l6-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-round-robin-scores-l2-s8/environment/Dockerfile b/tasks/construct-rlve-round-robin-scores-l2-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-rlve-round-robin-scores-l2-s8/environment/instance.json b/tasks/construct-rlve-round-robin-scores-l2-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6b9b6d5b66b931cadea8f04b824b92d0c6ee5e8a --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l2-s8/environment/instance.json @@ -0,0 +1 @@ +{"W": [7, 7, 4, 7, 5, 4], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l2-s8/solution/solve.sh b/tasks/construct-rlve-round-robin-scores-l2-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a23443c80655ceff8fcf2b74b3dbe8c3a2ca57a5 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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' +{"A": ["011112", "101112", "110110", "111012", "111101", "002010"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-round-robin-scores-l2-s8/tests/check.py b/tasks/construct-rlve-round-robin-scores-l2-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..214446acaa90ce170daad3989b42317353060f9d --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l2-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-l2-s8/tests/instance.json b/tasks/construct-rlve-round-robin-scores-l2-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6b9b6d5b66b931cadea8f04b824b92d0c6ee5e8a --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l2-s8/tests/instance.json @@ -0,0 +1 @@ +{"W": [7, 7, 4, 7, 5, 4], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l2-s8/tests/run.py b/tasks/construct-rlve-round-robin-scores-l2-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-rlve-round-robin-scores-l2-s8/tests/test.sh b/tasks/construct-rlve-round-robin-scores-l2-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-rlve-round-robin-scores-l6-s0/environment/Dockerfile b/tasks/construct-rlve-round-robin-scores-l6-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-round-robin-scores-l6-s0/environment/instance.json b/tasks/construct-rlve-round-robin-scores-l6-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..58a1095374f7a2193f6542d52b55eb0e3b2de484 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l6-s0/environment/instance.json @@ -0,0 +1 @@ +{"W": [38, 20, 35, 27, 38, 33, 41, 39, 22, 37, 38, 33, 42, 28, 30, 28, 30, 26, 31, 34, 31, 29, 36, 32, 29], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l6-s0/solution/solve.sh b/tasks/construct-rlve-round-robin-scores-l6-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e42678308d12739db155575a11f8c49de6b33b13 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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' +{"A": ["0221210022011110022221021", "0011101020000112102002001", "0100220202120201022020121", "1120010220000212110002020", "0102011122220121220211111", "1201101111100021220022022", "2122110221020111022221111", "2200110011200201222212022", "0020010101022201102110000", "0202011110221201210202202", "2212012020021110221121200", "1202020200001021122022101", "1222222201110012022200102", "1100121000122020101011212", "1121001222101002120110002", "2010111111210200210100220", "2121002010012110011022012", "0201000021000201102102220", "0002220002100122100221020", "0222020010120211210010212", "0202100112002112020100221", "1020101020102122001220101", "2212121220011020202001002", "0200101022222120100102200", "1112101020210002022011020"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-round-robin-scores-l6-s0/tests/check.py b/tasks/construct-rlve-round-robin-scores-l6-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..214446acaa90ce170daad3989b42317353060f9d --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l6-s0/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-l6-s0/tests/instance.json b/tasks/construct-rlve-round-robin-scores-l6-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..58a1095374f7a2193f6542d52b55eb0e3b2de484 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l6-s0/tests/instance.json @@ -0,0 +1 @@ +{"W": [38, 20, 35, 27, 38, 33, 41, 39, 22, 37, 38, 33, 42, 28, 30, 28, 30, 26, 31, 34, 31, 29, 36, 32, 29], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l6-s0/tests/run.py b/tasks/construct-rlve-round-robin-scores-l6-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-round-robin-scores-l6-s0/tests/test.sh b/tasks/construct-rlve-round-robin-scores-l6-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-round-robin-scores-l6-s7/environment/Dockerfile b/tasks/construct-rlve-round-robin-scores-l6-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-rlve-round-robin-scores-l6-s7/environment/instance.json b/tasks/construct-rlve-round-robin-scores-l6-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0f54f5686a951ede033d2a35c4e14c313d9662c3 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l6-s7/environment/instance.json @@ -0,0 +1 @@ +{"W": [28, 26, 24, 26, 26, 29, 29, 22, 25, 27, 25, 24, 26, 20, 32, 27, 33, 31, 27, 27, 30, 31, 27, 24, 19], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l6-s7/solution/solve.sh b/tasks/construct-rlve-round-robin-scores-l6-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ac03ab67b7539af341fa1ed4488aa6326a387d85 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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' +{"A": ["0111011121122111110011201", "1011101111121211111110111", "1100110111112111111111111", "1120101211011111111111111", "2111011110110111111111121", "1212102211101111001111111", "1121100111111211112110012", "1110101011120111111111011", "0111111100211111111011112", "1111211120011111101110121", "1112111102011111010111111", "0011121011101101111211111", "0101211211110110011112111", "1011110111111001101111111", "1111111111121202011201112", "1111111111112100111111112", "1111121111212121010211111", "1111121112111211101101112", "2111110111211111210101101", "2111111121101101011011121", "1111111111111121122101111", "1211112112110111111110121", "0111112211111111111111011", "2111011110111111112010101", "1111110101111100101111110"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-round-robin-scores-l6-s7/tests/check.py b/tasks/construct-rlve-round-robin-scores-l6-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..214446acaa90ce170daad3989b42317353060f9d --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l6-s7/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-l6-s7/tests/instance.json b/tasks/construct-rlve-round-robin-scores-l6-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0f54f5686a951ede033d2a35c4e14c313d9662c3 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l6-s7/tests/instance.json @@ -0,0 +1 @@ +{"W": [28, 26, 24, 26, 26, 29, 29, 22, 25, 27, 25, 24, 26, 20, 32, 27, 33, 31, 27, 27, 30, 31, 27, 24, 19], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l6-s7/tests/run.py b/tasks/construct-rlve-round-robin-scores-l6-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-rlve-round-robin-scores-l6-s7/tests/test.sh b/tasks/construct-rlve-round-robin-scores-l6-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-rlve-shortest-path-count-l1-s2/environment/Dockerfile b/tasks/construct-rlve-shortest-path-count-l1-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l1-s2/environment/instance.json b/tasks/construct-rlve-shortest-path-count-l1-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bc3f96c795d4c23eba090e470e1a08e9ae86d088 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l1-s2/environment/instance.json @@ -0,0 +1 @@ +{"K": 22, "n_max": 23, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l1-s2/solution/solve.sh b/tasks/construct-rlve-shortest-path-count-l1-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..01ea90fd6fd07c230d45237654934d855de6bf4f --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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' +{"n": 15, "adj": ["NNYYNNNNNNNNNNN", "NNNNNNNNNNNNNNY", "YNNNYYNNNNNYNNN", "YNNNYYNNNNNYNNN", "NNYYNNYYNNNNYNN", "NNYYNNYYNNNNYNN", "NNNNYYNNYYNNNNN", "NNNNYYNNYYNNNNN", "NNNNNNYYNNNNNNY", "NNNNNNYYNNNNNNY", "NNNNNNNNNNNYNNN", "NNYYNNNNNNYNYNN", "NNNNYYNNNNNYNYN", "NNNNNNNNNNNNYNY", "NYNNNNNNYYNNNYN"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-shortest-path-count-l1-s2/tests/check.py b/tasks/construct-rlve-shortest-path-count-l1-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c59d4c4f4bb4e824a2019380643a5b3ade0ca974 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l1-s2/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-l1-s2/tests/instance.json b/tasks/construct-rlve-shortest-path-count-l1-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bc3f96c795d4c23eba090e470e1a08e9ae86d088 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l1-s2/tests/instance.json @@ -0,0 +1 @@ +{"K": 22, "n_max": 23, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l1-s2/tests/run.py b/tasks/construct-rlve-shortest-path-count-l1-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l1-s2/tests/test.sh b/tasks/construct-rlve-shortest-path-count-l1-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l1-s5/environment/Dockerfile b/tasks/construct-rlve-shortest-path-count-l1-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l1-s5/environment/instance.json b/tasks/construct-rlve-shortest-path-count-l1-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f59596a7f9eba9364282e37c3496b81f2339d9a3 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l1-s5/environment/instance.json @@ -0,0 +1 @@ +{"K": 32, "n_max": 33, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l1-s5/solution/solve.sh b/tasks/construct-rlve-shortest-path-count-l1-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c7cd86ce58b37dfc4529a56ac19032f15ac08312 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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' +{"n": 18, "adj": ["NNYYNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNY", "YNNNYYNNNNNNNNNNNN", "YNNNYYNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNN", "NNYYNNYYNNNNNNNNNN", "NNNNYYNNYYNNNNNNNN", "NNNNYYNNYYNNNNNNNN", "NNNNNNYYNNYYNNNNNN", "NNNNNNYYNNYYNNNNNN", "NNNNNNNNYYNNNNNNNY", "NNNNNNNNYYNNNNNNNY", "NNNNNNNNNNNNNYNNNN", "NNNNNNNNNNNNYNYNNN", "NNNNNNNNNNNNNYNYNN", "NNNNNNNNNNNNNNYNYN", "NNNNNNNNNNNNNNNYNY", "NYNNNNNNNNYYNNNNYN"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-shortest-path-count-l1-s5/tests/check.py b/tasks/construct-rlve-shortest-path-count-l1-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c59d4c4f4bb4e824a2019380643a5b3ade0ca974 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l1-s5/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-l1-s5/tests/instance.json b/tasks/construct-rlve-shortest-path-count-l1-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f59596a7f9eba9364282e37c3496b81f2339d9a3 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l1-s5/tests/instance.json @@ -0,0 +1 @@ +{"K": 32, "n_max": 33, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l1-s5/tests/run.py b/tasks/construct-rlve-shortest-path-count-l1-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l1-s5/tests/test.sh b/tasks/construct-rlve-shortest-path-count-l1-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l5-s3/environment/Dockerfile b/tasks/construct-rlve-shortest-path-count-l5-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l5-s3/environment/instance.json b/tasks/construct-rlve-shortest-path-count-l5-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ca5a1e66b03b84cb2ee3add3885bd2fb0fe1dbe9 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l5-s3/environment/instance.json @@ -0,0 +1 @@ +{"K": 65311362926762, "n_max": 279, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l5-s3/solution/solve.sh b/tasks/construct-rlve-shortest-path-count-l5-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5baa96ae17a52c627c86fc79a15ab2f01e51fc83 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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' +{"n": 138, "adj": ["NNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "YNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "YNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNY", "NYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYN"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-shortest-path-count-l5-s3/tests/check.py b/tasks/construct-rlve-shortest-path-count-l5-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c59d4c4f4bb4e824a2019380643a5b3ade0ca974 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l5-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-l5-s3/tests/instance.json b/tasks/construct-rlve-shortest-path-count-l5-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ca5a1e66b03b84cb2ee3add3885bd2fb0fe1dbe9 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l5-s3/tests/instance.json @@ -0,0 +1 @@ +{"K": 65311362926762, "n_max": 279, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l5-s3/tests/run.py b/tasks/construct-rlve-shortest-path-count-l5-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l5-s3/tests/test.sh b/tasks/construct-rlve-shortest-path-count-l5-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-smallest-enclosing-circle-l2-s9/environment/Dockerfile b/tasks/construct-rlve-smallest-enclosing-circle-l2-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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-smallest-enclosing-circle-l2-s9/environment/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l2-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5452e0f463e0fcf1e8a6662fae6c976e59794dea --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l2-s9/environment/instance.json @@ -0,0 +1 @@ +{"points": [[0, 1], [7, 15], [7, 16], [11, 15], [12, 9], [14, 8], [15, 16], [16, 1]], "r_opt": 10.63014581273465, "r2_num": 113, "r2_den": 1, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l2-s9/solution/solve.sh b/tasks/construct-rlve-smallest-enclosing-circle-l2-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4a6b8115fbeb2bd401076b8cef52a36b4714f561 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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' +{"x": 8.0, "y": 8.0, "r": 10.63014581373465} +RLMATH_EOF diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l2-s9/tests/check.py b/tasks/construct-rlve-smallest-enclosing-circle-l2-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0eabf3219588f98db42bf5fd305dc24ce21ca495 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l2-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-l2-s9/tests/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l2-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5452e0f463e0fcf1e8a6662fae6c976e59794dea --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l2-s9/tests/instance.json @@ -0,0 +1 @@ +{"points": [[0, 1], [7, 15], [7, 16], [11, 15], [12, 9], [14, 8], [15, 16], [16, 1]], "r_opt": 10.63014581273465, "r2_num": 113, "r2_den": 1, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l2-s9/tests/run.py b/tasks/construct-rlve-smallest-enclosing-circle-l2-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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-smallest-enclosing-circle-l2-s9/tests/test.sh b/tasks/construct-rlve-smallest-enclosing-circle-l2-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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-smallest-enclosing-circle-l6-s1/environment/Dockerfile b/tasks/construct-rlve-smallest-enclosing-circle-l6-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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-smallest-enclosing-circle-l6-s1/environment/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l6-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..28a6c2e90478aa5ba7fae221632f5ee1777da8a5 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l6-s1/environment/instance.json @@ -0,0 +1 @@ +{"points": [[3, 138], [3, 161], [7, 117], [9, 160], [10, 5], [11, 18], [12, 138], [16, 210], [18, 106], [19, 119], [25, 122], [30, 26], [32, 63], [34, 156], [34, 174], [36, 171], [42, 156], [43, 133], [43, 166], [45, 166], [51, 226], [52, 40], [52, 168], [55, 25], [56, 51], [57, 225], [61, 70], [64, 6], [65, 234], [67, 76], [68, 128], [69, 38], [70, 117], [78, 45], [78, 83], [79, 58], [79, 76], [82, 161], [85, 197], [88, 235], [90, 23], [91, 192], [92, 22], [97, 6], [97, 54], [100, 153], [101, 218], [103, 29], [103, 105], [107, 14], [108, 74], [109, 169], [111, 127], [115, 190], [118, 126], [119, 1], [121, 14], [130, 83], [135, 133], [136, 67], [136, 199], [137, 11], [141, 164], [142, 30], [146, 87], [146, 130], [147, 15], [150, 149], [155, 234], [156, 109], [157, 77], [157, 219], [158, 31], [158, 58], [159, 232], [161, 235], [162, 3], [162, 100], [164, 192], [169, 79], [170, 217], [170, 225], [172, 118], [172, 184], [173, 236], [174, 164], [178, 168], [186, 149], [192, 214], [193, 80], [197, 33], [200, 87], [200, 179], [201, 236], [204, 53], [205, 70], [206, 86], [206, 135], [210, 217], [212, 216], [215, 228], [217, 12], [220, 185], [222, 151], [224, 146], [225, 147], [225, 170], [226, 128], [229, 49], [231, 75], [233, 38], [233, 103], [234, 104], [234, 199], [235, 228], [236, 147], [236, 167], [239, 129], [240, 175], [240, 176]], "r_opt": 158.39349734127345, "r2_num": 50177, "r2_den": 2, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l6-s1/solution/solve.sh b/tasks/construct-rlve-smallest-enclosing-circle-l6-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0f4dc6295d7f47eb402fa2f6ca2e2d9c398d7e0b --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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' +{"x": 122.5, "y": 116.5, "r": 158.39349734227343} +RLMATH_EOF diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l6-s1/tests/check.py b/tasks/construct-rlve-smallest-enclosing-circle-l6-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0eabf3219588f98db42bf5fd305dc24ce21ca495 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l6-s1/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-l6-s1/tests/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l6-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..28a6c2e90478aa5ba7fae221632f5ee1777da8a5 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l6-s1/tests/instance.json @@ -0,0 +1 @@ +{"points": [[3, 138], [3, 161], [7, 117], [9, 160], [10, 5], [11, 18], [12, 138], [16, 210], [18, 106], [19, 119], [25, 122], [30, 26], [32, 63], [34, 156], [34, 174], [36, 171], [42, 156], [43, 133], [43, 166], [45, 166], [51, 226], [52, 40], [52, 168], [55, 25], [56, 51], [57, 225], [61, 70], [64, 6], [65, 234], [67, 76], [68, 128], [69, 38], [70, 117], [78, 45], [78, 83], [79, 58], [79, 76], [82, 161], [85, 197], [88, 235], [90, 23], [91, 192], [92, 22], [97, 6], [97, 54], [100, 153], [101, 218], [103, 29], [103, 105], [107, 14], [108, 74], [109, 169], [111, 127], [115, 190], [118, 126], [119, 1], [121, 14], [130, 83], [135, 133], [136, 67], [136, 199], [137, 11], [141, 164], [142, 30], [146, 87], [146, 130], [147, 15], [150, 149], [155, 234], [156, 109], [157, 77], [157, 219], [158, 31], [158, 58], [159, 232], [161, 235], [162, 3], [162, 100], [164, 192], [169, 79], [170, 217], [170, 225], [172, 118], [172, 184], [173, 236], [174, 164], [178, 168], [186, 149], [192, 214], [193, 80], [197, 33], [200, 87], [200, 179], [201, 236], [204, 53], [205, 70], [206, 86], [206, 135], [210, 217], [212, 216], [215, 228], [217, 12], [220, 185], [222, 151], [224, 146], [225, 147], [225, 170], [226, 128], [229, 49], [231, 75], [233, 38], [233, 103], [234, 104], [234, 199], [235, 228], [236, 147], [236, 167], [239, 129], [240, 175], [240, 176]], "r_opt": 158.39349734127345, "r2_num": 50177, "r2_den": 2, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l6-s1/tests/run.py b/tasks/construct-rlve-smallest-enclosing-circle-l6-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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-smallest-enclosing-circle-l6-s1/tests/test.sh b/tasks/construct-rlve-smallest-enclosing-circle-l6-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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-smallest-enclosing-circle-l6-s6/environment/Dockerfile b/tasks/construct-rlve-smallest-enclosing-circle-l6-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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-smallest-enclosing-circle-l6-s6/environment/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l6-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9ef1e60d2b134d1bde15c05b87a56375ba4bdc50 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l6-s6/environment/instance.json @@ -0,0 +1 @@ +{"points": [[5, 48], [6, 110], [7, 114], [8, 68], [8, 172], [9, 81], [9, 104], [12, 181], [13, 64], [15, 31], [17, 17], [19, 177], [22, 141], [23, 8], [23, 138], [24, 17], [28, 70], [29, 93], [29, 171], [30, 237], [35, 39], [36, 47], [37, 167], [38, 200], [40, 212], [43, 31], [44, 170], [45, 90], [48, 60], [49, 73], [52, 11], [58, 95], [60, 64], [60, 199], [63, 143], [64, 39], [67, 171], [68, 139], [71, 107], [72, 122], [74, 113], [75, 192], [80, 166], [82, 121], [84, 219], [85, 158], [85, 184], [88, 176], [89, 8], [89, 76], [91, 97], [92, 4], [105, 159], [107, 149], [109, 4], [110, 168], [113, 186], [115, 82], [115, 105], [116, 24], [118, 111], [119, 16], [119, 56], [121, 84], [123, 159], [127, 232], [130, 201], [135, 50], [135, 173], [137, 53], [137, 96], [141, 46], [141, 213], [142, 180], [144, 91], [146, 226], [147, 53], [156, 117], [158, 34], [158, 150], [159, 60], [161, 158], [163, 62], [163, 183], [166, 176], [167, 82], [167, 123], [171, 199], [172, 123], [173, 75], [175, 33], [175, 105], [179, 167], [181, 97], [181, 210], [183, 120], [186, 57], [191, 166], [192, 147], [194, 225], [195, 86], [198, 117], [199, 169], [199, 189], [201, 34], [202, 209], [208, 141], [211, 54], [218, 121], [219, 101], [219, 186], [224, 118], [227, 216], [228, 33], [228, 227], [229, 58], [235, 44], [236, 108], [239, 112], [240, 153]], "r_opt": 150.01804817598216, "r2_num": 5801473233205, "r2_den": 257781218, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l6-s6/solution/solve.sh b/tasks/construct-rlve-smallest-enclosing-circle-l6-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9750c120f202d8415074d1148e6cf79adce0c8f1 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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' +{"x": 123.32022372941073, "y": 119.54042984233243, "r": 150.01804817698215} +RLMATH_EOF diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l6-s6/tests/check.py b/tasks/construct-rlve-smallest-enclosing-circle-l6-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0eabf3219588f98db42bf5fd305dc24ce21ca495 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l6-s6/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-l6-s6/tests/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l6-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9ef1e60d2b134d1bde15c05b87a56375ba4bdc50 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l6-s6/tests/instance.json @@ -0,0 +1 @@ +{"points": [[5, 48], [6, 110], [7, 114], [8, 68], [8, 172], [9, 81], [9, 104], [12, 181], [13, 64], [15, 31], [17, 17], [19, 177], [22, 141], [23, 8], [23, 138], [24, 17], [28, 70], [29, 93], [29, 171], [30, 237], [35, 39], [36, 47], [37, 167], [38, 200], [40, 212], [43, 31], [44, 170], [45, 90], [48, 60], [49, 73], [52, 11], [58, 95], [60, 64], [60, 199], [63, 143], [64, 39], [67, 171], [68, 139], [71, 107], [72, 122], [74, 113], [75, 192], [80, 166], [82, 121], [84, 219], [85, 158], [85, 184], [88, 176], [89, 8], [89, 76], [91, 97], [92, 4], [105, 159], [107, 149], [109, 4], [110, 168], [113, 186], [115, 82], [115, 105], [116, 24], [118, 111], [119, 16], [119, 56], [121, 84], [123, 159], [127, 232], [130, 201], [135, 50], [135, 173], [137, 53], [137, 96], [141, 46], [141, 213], [142, 180], [144, 91], [146, 226], [147, 53], [156, 117], [158, 34], [158, 150], [159, 60], [161, 158], [163, 62], [163, 183], [166, 176], [167, 82], [167, 123], [171, 199], [172, 123], [173, 75], [175, 33], [175, 105], [179, 167], [181, 97], [181, 210], [183, 120], [186, 57], [191, 166], [192, 147], [194, 225], [195, 86], [198, 117], [199, 169], [199, 189], [201, 34], [202, 209], [208, 141], [211, 54], [218, 121], [219, 101], [219, 186], [224, 118], [227, 216], [228, 33], [228, 227], [229, 58], [235, 44], [236, 108], [239, 112], [240, 153]], "r_opt": 150.01804817598216, "r2_num": 5801473233205, "r2_den": 257781218, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l6-s6/tests/run.py b/tasks/construct-rlve-smallest-enclosing-circle-l6-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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-smallest-enclosing-circle-l6-s6/tests/test.sh b/tasks/construct-rlve-smallest-enclosing-circle-l6-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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-smallest-enclosing-circle-l6-s8/environment/Dockerfile b/tasks/construct-rlve-smallest-enclosing-circle-l6-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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-smallest-enclosing-circle-l6-s8/environment/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l6-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..73e3d3edf97c77d70a7db3746db4db1d870b3517 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l6-s8/environment/instance.json @@ -0,0 +1 @@ +{"points": [[3, 138], [3, 145], [5, 64], [8, 14], [8, 98], [11, 115], [13, 117], [14, 53], [14, 201], [15, 221], [16, 77], [19, 32], [22, 12], [25, 43], [25, 206], [29, 94], [32, 3], [35, 1], [35, 190], [38, 144], [40, 31], [44, 18], [44, 204], [45, 20], [45, 216], [46, 92], [47, 128], [47, 131], [49, 154], [52, 66], [52, 68], [53, 17], [55, 131], [60, 11], [60, 46], [62, 184], [64, 121], [65, 172], [66, 53], [67, 200], [68, 176], [71, 171], [77, 229], [79, 51], [81, 193], [84, 132], [85, 188], [86, 137], [94, 158], [94, 215], [100, 152], [102, 55], [106, 68], [106, 107], [107, 69], [108, 141], [108, 230], [109, 114], [109, 133], [111, 223], [114, 23], [116, 149], [117, 107], [121, 187], [124, 140], [125, 183], [126, 167], [131, 134], [133, 178], [133, 240], [136, 156], [138, 42], [142, 85], [144, 80], [144, 123], [146, 169], [149, 188], [152, 205], [157, 78], [165, 0], [165, 214], [168, 181], [169, 168], [169, 228], [173, 104], [173, 114], [176, 26], [177, 198], [177, 234], [179, 31], [184, 69], [190, 81], [201, 213], [207, 56], [210, 147], [211, 233], [213, 43], [213, 145], [214, 0], [215, 88], [215, 185], [216, 71], [216, 159], [217, 63], [218, 143], [219, 208], [220, 110], [221, 76], [221, 205], [224, 128], [226, 3], [229, 59], [229, 201], [231, 173], [232, 99], [234, 228], [235, 160], [237, 65], [239, 206], [240, 44]], "r_opt": 155.63855457541234, "r2_num": 29244172297145, "r2_den": 1207271522, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l6-s8/solution/solve.sh b/tasks/construct-rlve-smallest-enclosing-circle-l6-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9835a90250503a5678e02f80f81f64cfc6cdd9d9 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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' +{"x": 122.59178232732305, "y": 119.31895885058407, "r": 155.63855457641233} +RLMATH_EOF diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l6-s8/tests/check.py b/tasks/construct-rlve-smallest-enclosing-circle-l6-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0eabf3219588f98db42bf5fd305dc24ce21ca495 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l6-s8/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-l6-s8/tests/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l6-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..73e3d3edf97c77d70a7db3746db4db1d870b3517 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l6-s8/tests/instance.json @@ -0,0 +1 @@ +{"points": [[3, 138], [3, 145], [5, 64], [8, 14], [8, 98], [11, 115], [13, 117], [14, 53], [14, 201], [15, 221], [16, 77], [19, 32], [22, 12], [25, 43], [25, 206], [29, 94], [32, 3], [35, 1], [35, 190], [38, 144], [40, 31], [44, 18], [44, 204], [45, 20], [45, 216], [46, 92], [47, 128], [47, 131], [49, 154], [52, 66], [52, 68], [53, 17], [55, 131], [60, 11], [60, 46], [62, 184], [64, 121], [65, 172], [66, 53], [67, 200], [68, 176], [71, 171], [77, 229], [79, 51], [81, 193], [84, 132], [85, 188], [86, 137], [94, 158], [94, 215], [100, 152], [102, 55], [106, 68], [106, 107], [107, 69], [108, 141], [108, 230], [109, 114], [109, 133], [111, 223], [114, 23], [116, 149], [117, 107], [121, 187], [124, 140], [125, 183], [126, 167], [131, 134], [133, 178], [133, 240], [136, 156], [138, 42], [142, 85], [144, 80], [144, 123], [146, 169], [149, 188], [152, 205], [157, 78], [165, 0], [165, 214], [168, 181], [169, 168], [169, 228], [173, 104], [173, 114], [176, 26], [177, 198], [177, 234], [179, 31], [184, 69], [190, 81], [201, 213], [207, 56], [210, 147], [211, 233], [213, 43], [213, 145], [214, 0], [215, 88], [215, 185], [216, 71], [216, 159], [217, 63], [218, 143], [219, 208], [220, 110], [221, 76], [221, 205], [224, 128], [226, 3], [229, 59], [229, 201], [231, 173], [232, 99], [234, 228], [235, 160], [237, 65], [239, 206], [240, 44]], "r_opt": 155.63855457541234, "r2_num": 29244172297145, "r2_den": 1207271522, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l6-s8/tests/run.py b/tasks/construct-rlve-smallest-enclosing-circle-l6-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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-smallest-enclosing-circle-l6-s8/tests/test.sh b/tasks/construct-rlve-smallest-enclosing-circle-l6-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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-subgraph-isomorphism-l2-s2/environment/Dockerfile b/tasks/construct-rlve-subgraph-isomorphism-l2-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l2-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-l2-s2/environment/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l2-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6a3a5bd8d505835ff5fb48bd0db3530404e2a8e6 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l2-s2/environment/instance.json @@ -0,0 +1 @@ +{"n1": 4, "n2": 8, "edges1": [[0, 1], [0, 3]], "edges2": [[0, 4], [0, 1], [1, 7], [2, 5], [3, 6], [2, 3], [2, 6], [0, 6], [3, 5], [6, 7], [2, 7], [1, 5], [4, 6], [5, 7], [1, 6]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l2-s2/solution/solve.sh b/tasks/construct-rlve-subgraph-isomorphism-l2-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..15f5abc0833db07d5100b23782fd3feba125fc04 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l2-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": [5, 1, 4, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-subgraph-isomorphism-l2-s2/tests/check.py b/tasks/construct-rlve-subgraph-isomorphism-l2-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b8467dd00c27c8902c06206c376ff7a11ac78ae0 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l2-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-l2-s2/tests/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l2-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6a3a5bd8d505835ff5fb48bd0db3530404e2a8e6 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l2-s2/tests/instance.json @@ -0,0 +1 @@ +{"n1": 4, "n2": 8, "edges1": [[0, 1], [0, 3]], "edges2": [[0, 4], [0, 1], [1, 7], [2, 5], [3, 6], [2, 3], [2, 6], [0, 6], [3, 5], [6, 7], [2, 7], [1, 5], [4, 6], [5, 7], [1, 6]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l2-s2/tests/run.py b/tasks/construct-rlve-subgraph-isomorphism-l2-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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-rlve-subgraph-isomorphism-l2-s2/tests/test.sh b/tasks/construct-rlve-subgraph-isomorphism-l2-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l2-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-l2-s5/environment/Dockerfile b/tasks/construct-rlve-subgraph-isomorphism-l2-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l2-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-l2-s5/environment/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l2-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..212663d598cb28f4890ace7daeee17a5590b02f7 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l2-s5/environment/instance.json @@ -0,0 +1 @@ +{"n1": 4, "n2": 8, "edges1": [[1, 3], [1, 2]], "edges2": [[5, 7], [2, 3], [0, 5], [3, 5], [2, 5], [2, 4], [1, 6], [1, 7], [1, 3], [6, 7], [0, 2], [1, 2], [4, 7], [2, 6], [5, 6]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l2-s5/solution/solve.sh b/tasks/construct-rlve-subgraph-isomorphism-l2-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..63eb2eac4e44f88651d7786d20ab7f4cd5f651f9 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l2-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": [4, 5, 6, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-subgraph-isomorphism-l2-s5/tests/check.py b/tasks/construct-rlve-subgraph-isomorphism-l2-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b8467dd00c27c8902c06206c376ff7a11ac78ae0 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l2-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-l2-s5/tests/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l2-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..212663d598cb28f4890ace7daeee17a5590b02f7 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l2-s5/tests/instance.json @@ -0,0 +1 @@ +{"n1": 4, "n2": 8, "edges1": [[1, 3], [1, 2]], "edges2": [[5, 7], [2, 3], [0, 5], [3, 5], [2, 5], [2, 4], [1, 6], [1, 7], [1, 3], [6, 7], [0, 2], [1, 2], [4, 7], [2, 6], [5, 6]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l2-s5/tests/run.py b/tasks/construct-rlve-subgraph-isomorphism-l2-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l2-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-l2-s5/tests/test.sh b/tasks/construct-rlve-subgraph-isomorphism-l2-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l2-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-p11/environment/Dockerfile b/tasks/optimize-ae-p1-ff-kakeya-d4-p11/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-ae-p1-ff-kakeya-d4-p11/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-p11/environment/instance.json b/tasks/optimize-ae-p1-ff-kakeya-d4-p11/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..398b0a1e31792bcce92e391fe5ee949311338894 --- /dev/null +++ b/tasks/optimize-ae-p1-ff-kakeya-d4-p11/environment/instance.json @@ -0,0 +1 @@ +{"p": 11, "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-p11/solution/solve.sh b/tasks/optimize-ae-p1-ff-kakeya-d4-p11/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..563579815288258770180aa4c68bc2cdde46b880 --- /dev/null +++ b/tasks/optimize-ae-p1-ff-kakeya-d4-p11/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, 0, 5], [0, 0, 0, 6], [0, 0, 0, 7], [0, 0, 0, 8], [0, 0, 0, 9], [0, 0, 0, 10], [0, 0, 1, 2], [0, 0, 1, 3], [0, 0, 1, 4], [0, 0, 1, 7], [0, 0, 1, 8], [0, 0, 1, 9], [0, 0, 2, 0], [0, 0, 2, 1], [0, 0, 2, 3], [0, 0, 2, 4], [0, 0, 2, 8], [0, 0, 2, 10], [0, 0, 3, 1], [0, 0, 3, 2], [0, 0, 3, 4], [0, 0, 3, 7], [0, 0, 3, 9], [0, 0, 3, 10], [0, 0, 4, 3], [0, 0, 4, 4], [0, 0, 4, 5], [0, 0, 4, 6], [0, 0, 4, 7], [0, 0, 4, 8], [0, 0, 5, 1], [0, 0, 5, 3], [0, 0, 5, 4], [0, 0, 5, 5], [0, 0, 5, 6], [0, 0, 5, 8], [0, 0, 5, 10], [0, 0, 6, 0], [0, 0, 6, 4], [0, 0, 6, 5], [0, 0, 6, 6], [0, 0, 6, 7], [0, 0, 7, 0], [0, 0, 7, 2], [0, 0, 7, 3], [0, 0, 7, 4], [0, 0, 7, 8], [0, 0, 7, 9], [0, 0, 8, 0], [0, 0, 8, 2], [0, 0, 8, 4], [0, 0, 8, 5], [0, 0, 8, 6], [0, 0, 8, 9], [0, 0, 9, 1], [0, 0, 9, 2], [0, 0, 9, 4], [0, 0, 9, 5], [0, 0, 9, 6], [0, 0, 9, 9], [0, 0, 9, 10], [0, 0, 10, 0], [0, 0, 10, 1], [0, 0, 10, 4], [0, 0, 10, 7], [0, 0, 10, 10], [0, 1, 0, 2], [0, 1, 0, 3], [0, 1, 0, 4], [0, 1, 0, 7], [0, 1, 0, 8], [0, 1, 0, 9], [0, 1, 1, 2], [0, 1, 1, 3], [0, 1, 1, 4], [0, 1, 1, 7], [0, 1, 1, 8], [0, 1, 1, 9], [0, 1, 2, 3], [0, 1, 2, 4], [0, 1, 2, 8], [0, 1, 3, 2], [0, 1, 3, 4], [0, 1, 3, 7], [0, 1, 3, 9], [0, 1, 4, 3], [0, 1, 4, 4], [0, 1, 4, 7], [0, 1, 4, 8], [0, 1, 5, 3], [0, 1, 5, 8], [0, 1, 6, 4], [0, 1, 6, 7], [0, 1, 7, 2], [0, 1, 7, 3], [0, 1, 7, 4], [0, 1, 7, 8], [0, 1, 7, 9], [0, 1, 8, 2], [0, 1, 8, 4], [0, 1, 8, 9], [0, 1, 9, 2], [0, 1, 9, 9], [0, 1, 10, 4], [0, 1, 10, 7], [0, 2, 0, 0], [0, 2, 0, 1], [0, 2, 0, 3], [0, 2, 0, 4], [0, 2, 0, 8], [0, 2, 0, 10], [0, 2, 1, 3], [0, 2, 1, 8], [0, 2, 2, 0], [0, 2, 2, 1], [0, 2, 2, 3], [0, 2, 2, 4], [0, 2, 2, 8], [0, 2, 2, 10], [0, 2, 3, 1], [0, 2, 3, 10], [0, 2, 4, 3], [0, 2, 4, 8], [0, 2, 5, 1], [0, 2, 5, 3], [0, 2, 5, 8], [0, 2, 5, 10], [0, 2, 6, 0], [0, 2, 7, 0], [0, 2, 7, 3], [0, 2, 7, 4], [0, 2, 7, 8], [0, 2, 8, 0], [0, 2, 9, 1], [0, 2, 9, 4], [0, 2, 9, 10], [0, 2, 10, 0], [0, 2, 10, 1], [0, 2, 10, 4], [0, 2, 10, 10], [0, 3, 0, 1], [0, 3, 0, 2], [0, 3, 0, 4], [0, 3, 0, 7], [0, 3, 0, 9], [0, 3, 0, 10], [0, 3, 1, 2], [0, 3, 1, 4], [0, 3, 1, 7], [0, 3, 1, 9], [0, 3, 2, 1], [0, 3, 2, 10], [0, 3, 3, 1], [0, 3, 3, 2], [0, 3, 3, 4], [0, 3, 3, 7], [0, 3, 3, 9], [0, 3, 3, 10], [0, 3, 4, 4], [0, 3, 4, 7], [0, 3, 5, 1], [0, 3, 5, 10], [0, 3, 6, 4], [0, 3, 6, 7], [0, 3, 7, 2], [0, 3, 7, 9], [0, 3, 8, 2], [0, 3, 8, 4], [0, 3, 8, 9], [0, 3, 9, 1], [0, 3, 9, 2], [0, 3, 9, 4], [0, 3, 9, 9], [0, 3, 9, 10], [0, 3, 10, 1], [0, 3, 10, 4], [0, 3, 10, 7], [0, 3, 10, 10], [0, 4, 0, 3], [0, 4, 0, 4], [0, 4, 0, 5], [0, 4, 0, 6], [0, 4, 0, 7], [0, 4, 0, 8], [0, 4, 1, 3], [0, 4, 1, 4], [0, 4, 1, 7], [0, 4, 1, 8], [0, 4, 2, 3], [0, 4, 2, 4], [0, 4, 2, 8], [0, 4, 3, 4], [0, 4, 3, 7], [0, 4, 4, 3], [0, 4, 4, 4], [0, 4, 4, 5], [0, 4, 4, 6], [0, 4, 4, 7], [0, 4, 4, 8], [0, 4, 5, 3], [0, 4, 5, 4], [0, 4, 5, 5], [0, 4, 5, 6], [0, 4, 5, 8], [0, 4, 6, 4], [0, 4, 6, 5], [0, 4, 6, 6], [0, 4, 6, 7], [0, 4, 7, 3], [0, 4, 7, 4], [0, 4, 7, 8], [0, 4, 8, 5], [0, 4, 8, 6], [0, 4, 9, 5], [0, 4, 9, 6], [0, 4, 10, 4], [0, 4, 10, 7], [0, 5, 0, 1], [0, 5, 0, 3], [0, 5, 0, 4], [0, 5, 0, 5], [0, 5, 0, 6], [0, 5, 0, 8], [0, 5, 0, 10], [0, 5, 1, 3], [0, 5, 1, 8], [0, 5, 2, 1], [0, 5, 2, 3], [0, 5, 2, 4], [0, 5, 2, 8], [0, 5, 2, 10], [0, 5, 3, 1], [0, 5, 3, 10], [0, 5, 4, 3], [0, 5, 4, 4], [0, 5, 4, 5], [0, 5, 4, 6], [0, 5, 4, 8], [0, 5, 5, 1], [0, 5, 5, 3], [0, 5, 5, 4], [0, 5, 5, 5], [0, 5, 5, 6], [0, 5, 5, 8], [0, 5, 5, 10], [0, 5, 6, 5], [0, 5, 6, 6], [0, 5, 7, 3], [0, 5, 7, 4], [0, 5, 7, 8], [0, 5, 8, 5], [0, 5, 8, 6], [0, 5, 9, 1], [0, 5, 9, 4], [0, 5, 9, 5], [0, 5, 9, 6], [0, 5, 9, 10], [0, 5, 10, 1], [0, 5, 10, 10], [0, 6, 0, 0], [0, 6, 0, 4], [0, 6, 0, 5], [0, 6, 0, 6], [0, 6, 0, 7], [0, 6, 1, 4], [0, 6, 1, 7], [0, 6, 2, 0], [0, 6, 3, 4], [0, 6, 3, 7], [0, 6, 4, 4], [0, 6, 4, 5], [0, 6, 4, 6], [0, 6, 4, 7], [0, 6, 5, 4], [0, 6, 5, 5], [0, 6, 5, 6], [0, 6, 6, 0], [0, 6, 6, 4], [0, 6, 6, 5], [0, 6, 6, 6], [0, 6, 6, 7], [0, 6, 7, 0], [0, 6, 8, 0], [0, 6, 8, 5], [0, 6, 8, 6], [0, 6, 9, 5], [0, 6, 9, 6], [0, 6, 10, 0], [0, 6, 10, 4], [0, 6, 10, 7], [0, 7, 0, 0], [0, 7, 0, 2], [0, 7, 0, 3], [0, 7, 0, 4], [0, 7, 0, 8], [0, 7, 0, 9], [0, 7, 1, 2], [0, 7, 1, 3], [0, 7, 1, 4], [0, 7, 1, 8], [0, 7, 1, 9], [0, 7, 2, 0], [0, 7, 2, 3], [0, 7, 2, 4], [0, 7, 2, 8], [0, 7, 3, 2], [0, 7, 3, 9], [0, 7, 4, 3], [0, 7, 4, 8], [0, 7, 5, 3], [0, 7, 5, 8], [0, 7, 6, 0], [0, 7, 7, 0], [0, 7, 7, 2], [0, 7, 7, 3], [0, 7, 7, 4], [0, 7, 7, 8], [0, 7, 7, 9], [0, 7, 8, 0], [0, 7, 8, 2], [0, 7, 8, 4], [0, 7, 8, 9], [0, 7, 9, 2], [0, 7, 9, 9], [0, 7, 10, 0], [0, 7, 10, 4], [0, 8, 0, 0], [0, 8, 0, 2], [0, 8, 0, 5], [0, 8, 0, 6], [0, 8, 0, 9], [0, 8, 1, 2], [0, 8, 1, 4], [0, 8, 1, 9], [0, 8, 2, 0], [0, 8, 3, 2], [0, 8, 3, 9], [0, 8, 4, 4], [0, 8, 4, 5], [0, 8, 4, 6], [0, 8, 5, 4], [0, 8, 5, 5], [0, 8, 5, 6], [0, 8, 6, 0], [0, 8, 6, 5], [0, 8, 6, 6], [0, 8, 7, 0], [0, 8, 7, 2], [0, 8, 7, 9], [0, 8, 8, 0], [0, 8, 8, 2], [0, 8, 8, 4], [0, 8, 8, 5], [0, 8, 8, 6], [0, 8, 8, 9], [0, 8, 9, 2], [0, 8, 9, 5], [0, 8, 9, 6], [0, 8, 9, 9], [0, 8, 10, 0], [0, 8, 10, 4], [0, 9, 0, 1], [0, 9, 0, 2], [0, 9, 0, 4], [0, 9, 0, 5], [0, 9, 0, 6], [0, 9, 0, 9], [0, 9, 0, 10], [0, 9, 1, 2], [0, 9, 1, 4], [0, 9, 1, 9], [0, 9, 2, 1], [0, 9, 2, 10], [0, 9, 3, 1], [0, 9, 3, 2], [0, 9, 3, 9], [0, 9, 3, 10], [0, 9, 4, 4], [0, 9, 4, 5], [0, 9, 4, 6], [0, 9, 5, 1], [0, 9, 5, 4], [0, 9, 5, 5], [0, 9, 5, 6], [0, 9, 5, 10], [0, 9, 6, 5], [0, 9, 6, 6], [0, 9, 7, 2], [0, 9, 7, 9], [0, 9, 8, 2], [0, 9, 8, 4], [0, 9, 8, 5], [0, 9, 8, 6], [0, 9, 8, 9], [0, 9, 9, 1], [0, 9, 9, 2], [0, 9, 9, 4], [0, 9, 9, 5], [0, 9, 9, 6], [0, 9, 9, 9], [0, 9, 9, 10], [0, 9, 10, 1], [0, 9, 10, 10], [0, 10, 0, 0], [0, 10, 0, 1], [0, 10, 0, 4], [0, 10, 0, 7], [0, 10, 0, 10], [0, 10, 1, 4], [0, 10, 1, 7], [0, 10, 2, 0], [0, 10, 2, 1], [0, 10, 2, 10], [0, 10, 3, 1], [0, 10, 3, 4], [0, 10, 3, 7], [0, 10, 3, 10], [0, 10, 4, 4], [0, 10, 4, 7], [0, 10, 5, 1], [0, 10, 5, 10], [0, 10, 6, 0], [0, 10, 6, 4], [0, 10, 6, 7], [0, 10, 7, 0], [0, 10, 8, 0], [0, 10, 9, 1], [0, 10, 9, 4], [0, 10, 9, 10], [0, 10, 10, 0], [0, 10, 10, 1], [0, 10, 10, 4], [0, 10, 10, 7], [0, 10, 10, 10], [1, 0, 0, 2], [1, 0, 0, 3], [1, 0, 0, 4], [1, 0, 0, 7], [1, 0, 0, 8], [1, 0, 0, 9], [1, 0, 1, 2], [1, 0, 1, 3], [1, 0, 1, 4], [1, 0, 1, 7], [1, 0, 1, 8], [1, 0, 1, 9], [1, 0, 2, 3], [1, 0, 2, 4], [1, 0, 2, 8], [1, 0, 3, 2], [1, 0, 3, 4], [1, 0, 3, 7], [1, 0, 3, 9], [1, 0, 4, 3], [1, 0, 4, 4], [1, 0, 4, 7], [1, 0, 4, 8], [1, 0, 5, 3], [1, 0, 5, 8], [1, 0, 6, 4], [1, 0, 6, 7], [1, 0, 7, 2], [1, 0, 7, 3], [1, 0, 7, 4], [1, 0, 7, 8], [1, 0, 7, 9], [1, 0, 8, 2], [1, 0, 8, 4], [1, 0, 8, 9], [1, 0, 9, 2], [1, 0, 9, 9], [1, 0, 10, 4], [1, 0, 10, 7], [1, 1, 0, 2], [1, 1, 0, 3], [1, 1, 0, 4], [1, 1, 0, 7], [1, 1, 0, 8], [1, 1, 0, 9], [1, 1, 1, 2], [1, 1, 1, 3], [1, 1, 1, 4], [1, 1, 1, 7], [1, 1, 1, 8], [1, 1, 1, 9], [1, 1, 2, 3], [1, 1, 2, 4], [1, 1, 2, 8], [1, 1, 3, 2], [1, 1, 3, 4], [1, 1, 3, 7], [1, 1, 3, 9], [1, 1, 4, 3], [1, 1, 4, 4], [1, 1, 4, 7], [1, 1, 4, 8], [1, 1, 5, 3], [1, 1, 5, 8], [1, 1, 6, 4], [1, 1, 6, 7], [1, 1, 7, 2], [1, 1, 7, 3], [1, 1, 7, 4], [1, 1, 7, 8], [1, 1, 7, 9], [1, 1, 8, 2], [1, 1, 8, 4], [1, 1, 8, 9], [1, 1, 9, 2], [1, 1, 9, 9], [1, 1, 10, 4], [1, 1, 10, 7], [1, 2, 0, 3], [1, 2, 0, 8], [1, 2, 1, 3], [1, 2, 1, 8], [1, 2, 2, 3], [1, 2, 2, 4], [1, 2, 2, 8], [1, 2, 4, 3], [1, 2, 4, 8], [1, 2, 5, 3], [1, 2, 5, 8], [1, 2, 7, 3], [1, 2, 7, 4], [1, 2, 7, 8], [1, 3, 0, 2], [1, 3, 0, 4], [1, 3, 0, 7], [1, 3, 0, 9], [1, 3, 1, 2], [1, 3, 1, 4], [1, 3, 1, 7], [1, 3, 1, 9], [1, 3, 3, 2], [1, 3, 3, 4], [1, 3, 3, 7], [1, 3, 3, 9], [1, 3, 4, 4], [1, 3, 4, 7], [1, 3, 6, 4], [1, 3, 6, 7], [1, 3, 7, 2], [1, 3, 7, 9], [1, 3, 8, 2], [1, 3, 8, 4], [1, 3, 8, 9], [1, 3, 9, 2], [1, 3, 9, 9], [1, 3, 10, 4], [1, 3, 10, 7], [1, 4, 0, 3], [1, 4, 0, 4], [1, 4, 0, 7], [1, 4, 0, 8], [1, 4, 1, 3], [1, 4, 1, 4], [1, 4, 1, 7], [1, 4, 1, 8], [1, 4, 2, 3], [1, 4, 2, 4], [1, 4, 2, 8], [1, 4, 3, 4], [1, 4, 3, 7], [1, 4, 4, 3], [1, 4, 4, 4], [1, 4, 4, 7], [1, 4, 4, 8], [1, 4, 5, 3], [1, 4, 5, 8], [1, 4, 6, 4], [1, 4, 6, 7], [1, 4, 7, 3], [1, 4, 7, 4], [1, 4, 7, 8], [1, 4, 10, 4], [1, 4, 10, 7], [1, 5, 0, 3], [1, 5, 0, 8], [1, 5, 1, 3], [1, 5, 1, 8], [1, 5, 2, 3], [1, 5, 2, 4], [1, 5, 2, 8], [1, 5, 4, 3], [1, 5, 4, 8], [1, 5, 5, 3], [1, 5, 5, 8], [1, 5, 7, 3], [1, 5, 7, 4], [1, 5, 7, 8], [1, 6, 0, 4], [1, 6, 0, 7], [1, 6, 1, 4], [1, 6, 1, 7], [1, 6, 3, 4], [1, 6, 3, 7], [1, 6, 4, 4], [1, 6, 4, 7], [1, 6, 6, 4], [1, 6, 6, 7], [1, 6, 10, 4], [1, 6, 10, 7], [1, 7, 0, 2], [1, 7, 0, 3], [1, 7, 0, 8], [1, 7, 0, 9], [1, 7, 1, 2], [1, 7, 1, 3], [1, 7, 1, 4], [1, 7, 1, 8], [1, 7, 1, 9], [1, 7, 2, 3], [1, 7, 2, 4], [1, 7, 2, 8], [1, 7, 3, 2], [1, 7, 3, 9], [1, 7, 4, 3], [1, 7, 4, 8], [1, 7, 5, 3], [1, 7, 5, 8], [1, 7, 7, 2], [1, 7, 7, 3], [1, 7, 7, 4], [1, 7, 7, 8], [1, 7, 7, 9], [1, 7, 8, 2], [1, 7, 8, 4], [1, 7, 8, 9], [1, 7, 9, 2], [1, 7, 9, 9], [1, 8, 0, 2], [1, 8, 0, 4], [1, 8, 0, 9], [1, 8, 1, 2], [1, 8, 1, 4], [1, 8, 1, 9], [1, 8, 3, 2], [1, 8, 3, 9], [1, 8, 7, 2], [1, 8, 7, 9], [1, 8, 8, 2], [1, 8, 8, 4], [1, 8, 8, 9], [1, 8, 9, 2], [1, 8, 9, 9], [1, 9, 0, 2], [1, 9, 0, 4], [1, 9, 0, 9], [1, 9, 1, 2], [1, 9, 1, 4], [1, 9, 1, 9], [1, 9, 3, 2], [1, 9, 3, 9], [1, 9, 7, 2], [1, 9, 7, 9], [1, 9, 8, 2], [1, 9, 8, 4], [1, 9, 8, 9], [1, 9, 9, 2], [1, 9, 9, 9], [1, 10, 0, 4], [1, 10, 0, 7], [1, 10, 1, 4], [1, 10, 1, 7], [1, 10, 3, 4], [1, 10, 3, 7], [1, 10, 4, 4], [1, 10, 4, 7], [1, 10, 6, 4], [1, 10, 6, 7], [1, 10, 10, 4], [1, 10, 10, 7], [2, 0, 0, 0], [2, 0, 0, 1], [2, 0, 0, 3], [2, 0, 0, 4], [2, 0, 0, 8], [2, 0, 0, 10], [2, 0, 1, 3], [2, 0, 1, 8], [2, 0, 2, 0], [2, 0, 2, 1], [2, 0, 2, 3], [2, 0, 2, 4], [2, 0, 2, 8], [2, 0, 2, 10], [2, 0, 3, 1], [2, 0, 3, 10], [2, 0, 4, 3], [2, 0, 4, 8], [2, 0, 5, 1], [2, 0, 5, 3], [2, 0, 5, 8], [2, 0, 5, 10], [2, 0, 6, 0], [2, 0, 7, 0], [2, 0, 7, 3], [2, 0, 7, 4], [2, 0, 7, 8], [2, 0, 8, 0], [2, 0, 9, 1], [2, 0, 9, 4], [2, 0, 9, 10], [2, 0, 10, 0], [2, 0, 10, 1], [2, 0, 10, 4], [2, 0, 10, 10], [2, 1, 0, 3], [2, 1, 0, 8], [2, 1, 1, 3], [2, 1, 1, 8], [2, 1, 2, 3], [2, 1, 2, 4], [2, 1, 2, 8], [2, 1, 4, 3], [2, 1, 4, 8], [2, 1, 5, 3], [2, 1, 5, 8], [2, 1, 7, 3], [2, 1, 7, 4], [2, 1, 7, 8], [2, 2, 0, 0], [2, 2, 0, 1], [2, 2, 0, 3], [2, 2, 0, 4], [2, 2, 0, 8], [2, 2, 0, 10], [2, 2, 1, 3], [2, 2, 1, 8], [2, 2, 2, 0], [2, 2, 2, 1], [2, 2, 2, 3], [2, 2, 2, 4], [2, 2, 2, 8], [2, 2, 2, 10], [2, 2, 3, 1], [2, 2, 3, 10], [2, 2, 4, 3], [2, 2, 4, 8], [2, 2, 5, 1], [2, 2, 5, 3], [2, 2, 5, 8], [2, 2, 5, 10], [2, 2, 6, 0], [2, 2, 7, 0], [2, 2, 7, 3], [2, 2, 7, 4], [2, 2, 7, 8], [2, 2, 8, 0], [2, 2, 9, 1], [2, 2, 9, 4], [2, 2, 9, 10], [2, 2, 10, 0], [2, 2, 10, 1], [2, 2, 10, 4], [2, 2, 10, 10], [2, 3, 0, 1], [2, 3, 0, 4], [2, 3, 0, 10], [2, 3, 2, 1], [2, 3, 2, 10], [2, 3, 3, 1], [2, 3, 3, 10], [2, 3, 5, 1], [2, 3, 5, 10], [2, 3, 9, 1], [2, 3, 9, 4], [2, 3, 9, 10], [2, 3, 10, 1], [2, 3, 10, 10], [2, 4, 0, 3], [2, 4, 0, 8], [2, 4, 1, 3], [2, 4, 1, 8], [2, 4, 2, 3], [2, 4, 2, 4], [2, 4, 2, 8], [2, 4, 4, 3], [2, 4, 4, 8], [2, 4, 5, 3], [2, 4, 5, 8], [2, 4, 7, 3], [2, 4, 7, 4], [2, 4, 7, 8], [2, 5, 0, 1], [2, 5, 0, 3], [2, 5, 0, 4], [2, 5, 0, 8], [2, 5, 0, 10], [2, 5, 1, 3], [2, 5, 1, 8], [2, 5, 2, 1], [2, 5, 2, 3], [2, 5, 2, 4], [2, 5, 2, 8], [2, 5, 2, 10], [2, 5, 3, 1], [2, 5, 3, 10], [2, 5, 4, 3], [2, 5, 4, 8], [2, 5, 5, 1], [2, 5, 5, 3], [2, 5, 5, 8], [2, 5, 5, 10], [2, 5, 7, 3], [2, 5, 7, 4], [2, 5, 7, 8], [2, 5, 9, 1], [2, 5, 9, 4], [2, 5, 9, 10], [2, 5, 10, 1], [2, 5, 10, 10], [2, 6, 0, 0], [2, 6, 2, 0], [2, 6, 6, 0], [2, 6, 7, 0], [2, 6, 8, 0], [2, 6, 10, 0], [2, 6, 10, 4], [2, 7, 0, 0], [2, 7, 0, 3], [2, 7, 0, 4], [2, 7, 0, 8], [2, 7, 1, 3], [2, 7, 1, 8], [2, 7, 2, 0], [2, 7, 2, 3], [2, 7, 2, 4], [2, 7, 2, 8], [2, 7, 4, 3], [2, 7, 4, 8], [2, 7, 5, 3], [2, 7, 5, 8], [2, 7, 6, 0], [2, 7, 7, 0], [2, 7, 7, 3], [2, 7, 7, 4], [2, 7, 7, 8], [2, 7, 8, 0], [2, 7, 10, 0], [2, 7, 10, 4], [2, 8, 0, 0], [2, 8, 0, 4], [2, 8, 2, 0], [2, 8, 6, 0], [2, 8, 7, 0], [2, 8, 8, 0], [2, 8, 10, 0], [2, 8, 10, 4], [2, 9, 0, 1], [2, 9, 0, 4], [2, 9, 0, 10], [2, 9, 2, 1], [2, 9, 2, 10], [2, 9, 3, 1], [2, 9, 3, 10], [2, 9, 5, 1], [2, 9, 5, 10], [2, 9, 9, 1], [2, 9, 9, 4], [2, 9, 9, 10], [2, 9, 10, 1], [2, 9, 10, 10], [2, 10, 0, 0], [2, 10, 0, 1], [2, 10, 0, 4], [2, 10, 0, 10], [2, 10, 2, 0], [2, 10, 2, 1], [2, 10, 2, 10], [2, 10, 3, 1], [2, 10, 3, 10], [2, 10, 5, 1], [2, 10, 5, 10], [2, 10, 6, 0], [2, 10, 7, 0], [2, 10, 8, 0], [2, 10, 9, 1], [2, 10, 9, 4], [2, 10, 9, 10], [2, 10, 10, 0], [2, 10, 10, 1], [2, 10, 10, 4], [2, 10, 10, 10], [3, 0, 0, 1], [3, 0, 0, 2], [3, 0, 0, 4], [3, 0, 0, 7], [3, 0, 0, 9], [3, 0, 0, 10], [3, 0, 1, 2], [3, 0, 1, 4], [3, 0, 1, 7], [3, 0, 1, 9], [3, 0, 2, 1], [3, 0, 2, 10], [3, 0, 3, 1], [3, 0, 3, 2], [3, 0, 3, 4], [3, 0, 3, 7], [3, 0, 3, 9], [3, 0, 3, 10], [3, 0, 4, 4], [3, 0, 4, 7], [3, 0, 5, 1], [3, 0, 5, 10], [3, 0, 6, 4], [3, 0, 6, 7], [3, 0, 7, 2], [3, 0, 7, 9], [3, 0, 8, 2], [3, 0, 8, 4], [3, 0, 8, 9], [3, 0, 9, 1], [3, 0, 9, 2], [3, 0, 9, 4], [3, 0, 9, 9], [3, 0, 9, 10], [3, 0, 10, 1], [3, 0, 10, 4], [3, 0, 10, 7], [3, 0, 10, 10], [3, 1, 0, 2], [3, 1, 0, 4], [3, 1, 0, 7], [3, 1, 0, 9], [3, 1, 1, 2], [3, 1, 1, 4], [3, 1, 1, 7], [3, 1, 1, 9], [3, 1, 3, 2], [3, 1, 3, 4], [3, 1, 3, 7], [3, 1, 3, 9], [3, 1, 4, 4], [3, 1, 4, 7], [3, 1, 6, 4], [3, 1, 6, 7], [3, 1, 7, 2], [3, 1, 7, 9], [3, 1, 8, 2], [3, 1, 8, 4], [3, 1, 8, 9], [3, 1, 9, 2], [3, 1, 9, 9], [3, 1, 10, 4], [3, 1, 10, 7], [3, 2, 0, 1], [3, 2, 0, 4], [3, 2, 0, 10], [3, 2, 2, 1], [3, 2, 2, 10], [3, 2, 3, 1], [3, 2, 3, 10], [3, 2, 5, 1], [3, 2, 5, 10], [3, 2, 9, 1], [3, 2, 9, 4], [3, 2, 9, 10], [3, 2, 10, 1], [3, 2, 10, 10], [3, 3, 0, 1], [3, 3, 0, 2], [3, 3, 0, 4], [3, 3, 0, 7], [3, 3, 0, 9], [3, 3, 0, 10], [3, 3, 1, 2], [3, 3, 1, 4], [3, 3, 1, 7], [3, 3, 1, 9], [3, 3, 2, 1], [3, 3, 2, 10], [3, 3, 3, 1], [3, 3, 3, 2], [3, 3, 3, 4], [3, 3, 3, 7], [3, 3, 3, 9], [3, 3, 3, 10], [3, 3, 4, 4], [3, 3, 4, 7], [3, 3, 5, 1], [3, 3, 5, 10], [3, 3, 6, 4], [3, 3, 6, 7], [3, 3, 7, 2], [3, 3, 7, 9], [3, 3, 8, 2], [3, 3, 8, 4], [3, 3, 8, 9], [3, 3, 9, 1], [3, 3, 9, 2], [3, 3, 9, 4], [3, 3, 9, 9], [3, 3, 9, 10], [3, 3, 10, 1], [3, 3, 10, 4], [3, 3, 10, 7], [3, 3, 10, 10], [3, 4, 0, 4], [3, 4, 0, 7], [3, 4, 1, 4], [3, 4, 1, 7], [3, 4, 3, 4], [3, 4, 3, 7], [3, 4, 4, 4], [3, 4, 4, 7], [3, 4, 6, 4], [3, 4, 6, 7], [3, 4, 10, 4], [3, 4, 10, 7], [3, 5, 0, 1], [3, 5, 0, 4], [3, 5, 0, 10], [3, 5, 2, 1], [3, 5, 2, 10], [3, 5, 3, 1], [3, 5, 3, 10], [3, 5, 5, 1], [3, 5, 5, 10], [3, 5, 9, 1], [3, 5, 9, 4], [3, 5, 9, 10], [3, 5, 10, 1], [3, 5, 10, 10], [3, 6, 0, 4], [3, 6, 0, 7], [3, 6, 1, 4], [3, 6, 1, 7], [3, 6, 3, 4], [3, 6, 3, 7], [3, 6, 4, 4], [3, 6, 4, 7], [3, 6, 6, 4], [3, 6, 6, 7], [3, 6, 10, 4], [3, 6, 10, 7], [3, 7, 0, 2], [3, 7, 0, 9], [3, 7, 1, 2], [3, 7, 1, 4], [3, 7, 1, 9], [3, 7, 3, 2], [3, 7, 3, 9], [3, 7, 7, 2], [3, 7, 7, 9], [3, 7, 8, 2], [3, 7, 8, 4], [3, 7, 8, 9], [3, 7, 9, 2], [3, 7, 9, 9], [3, 8, 0, 2], [3, 8, 0, 9], [3, 8, 1, 2], [3, 8, 1, 4], [3, 8, 1, 9], [3, 8, 3, 2], [3, 8, 3, 9], [3, 8, 7, 2], [3, 8, 7, 9], [3, 8, 8, 2], [3, 8, 8, 4], [3, 8, 8, 9], [3, 8, 9, 2], [3, 8, 9, 9], [3, 9, 0, 1], [3, 9, 0, 2], [3, 9, 0, 4], [3, 9, 0, 9], [3, 9, 0, 10], [3, 9, 1, 2], [3, 9, 1, 4], [3, 9, 1, 9], [3, 9, 2, 1], [3, 9, 2, 10], [3, 9, 3, 1], [3, 9, 3, 2], [3, 9, 3, 9], [3, 9, 3, 10], [3, 9, 5, 1], [3, 9, 5, 10], [3, 9, 7, 2], [3, 9, 7, 9], [3, 9, 8, 2], [3, 9, 8, 4], [3, 9, 8, 9], [3, 9, 9, 1], [3, 9, 9, 2], [3, 9, 9, 4], [3, 9, 9, 9], [3, 9, 9, 10], [3, 9, 10, 1], [3, 9, 10, 10], [3, 10, 0, 1], [3, 10, 0, 4], [3, 10, 0, 7], [3, 10, 0, 10], [3, 10, 1, 4], [3, 10, 1, 7], [3, 10, 2, 1], [3, 10, 2, 10], [3, 10, 3, 1], [3, 10, 3, 4], [3, 10, 3, 7], [3, 10, 3, 10], [3, 10, 4, 4], [3, 10, 4, 7], [3, 10, 5, 1], [3, 10, 5, 10], [3, 10, 6, 4], [3, 10, 6, 7], [3, 10, 9, 1], [3, 10, 9, 4], [3, 10, 9, 10], [3, 10, 10, 1], [3, 10, 10, 4], [3, 10, 10, 7], [3, 10, 10, 10], [4, 0, 0, 3], [4, 0, 0, 4], [4, 0, 0, 5], [4, 0, 0, 6], [4, 0, 0, 7], [4, 0, 0, 8], [4, 0, 1, 3], [4, 0, 1, 4], [4, 0, 1, 7], [4, 0, 1, 8], [4, 0, 2, 3], [4, 0, 2, 4], [4, 0, 2, 8], [4, 0, 3, 4], [4, 0, 3, 7], [4, 0, 4, 3], [4, 0, 4, 4], [4, 0, 4, 5], [4, 0, 4, 6], [4, 0, 4, 7], [4, 0, 4, 8], [4, 0, 5, 3], [4, 0, 5, 4], [4, 0, 5, 5], [4, 0, 5, 6], [4, 0, 5, 8], [4, 0, 6, 4], [4, 0, 6, 5], [4, 0, 6, 6], [4, 0, 6, 7], [4, 0, 7, 3], [4, 0, 7, 4], [4, 0, 7, 8], [4, 0, 8, 5], [4, 0, 8, 6], [4, 0, 9, 5], [4, 0, 9, 6], [4, 0, 10, 4], [4, 0, 10, 7], [4, 1, 0, 3], [4, 1, 0, 4], [4, 1, 0, 7], [4, 1, 0, 8], [4, 1, 1, 3], [4, 1, 1, 4], [4, 1, 1, 7], [4, 1, 1, 8], [4, 1, 2, 3], [4, 1, 2, 4], [4, 1, 2, 8], [4, 1, 3, 4], [4, 1, 3, 7], [4, 1, 4, 3], [4, 1, 4, 4], [4, 1, 4, 7], [4, 1, 4, 8], [4, 1, 5, 3], [4, 1, 5, 8], [4, 1, 6, 4], [4, 1, 6, 7], [4, 1, 7, 3], [4, 1, 7, 4], [4, 1, 7, 8], [4, 1, 10, 4], [4, 1, 10, 7], [4, 2, 0, 3], [4, 2, 0, 8], [4, 2, 1, 3], [4, 2, 1, 8], [4, 2, 2, 3], [4, 2, 2, 4], [4, 2, 2, 8], [4, 2, 4, 3], [4, 2, 4, 8], [4, 2, 5, 3], [4, 2, 5, 8], [4, 2, 7, 3], [4, 2, 7, 4], [4, 2, 7, 8], [4, 3, 0, 4], [4, 3, 0, 7], [4, 3, 1, 4], [4, 3, 1, 7], [4, 3, 3, 4], [4, 3, 3, 7], [4, 3, 4, 4], [4, 3, 4, 7], [4, 3, 6, 4], [4, 3, 6, 7], [4, 3, 10, 4], [4, 3, 10, 7], [4, 4, 0, 3], [4, 4, 0, 4], [4, 4, 0, 5], [4, 4, 0, 6], [4, 4, 0, 7], [4, 4, 0, 8], [4, 4, 1, 3], [4, 4, 1, 4], [4, 4, 1, 7], [4, 4, 1, 8], [4, 4, 2, 3], [4, 4, 2, 4], [4, 4, 2, 8], [4, 4, 3, 4], [4, 4, 3, 7], [4, 4, 4, 3], [4, 4, 4, 4], [4, 4, 4, 5], [4, 4, 4, 6], [4, 4, 4, 7], [4, 4, 4, 8], [4, 4, 5, 3], [4, 4, 5, 4], [4, 4, 5, 5], [4, 4, 5, 6], [4, 4, 5, 8], [4, 4, 6, 4], [4, 4, 6, 5], [4, 4, 6, 6], [4, 4, 6, 7], [4, 4, 7, 3], [4, 4, 7, 4], [4, 4, 7, 8], [4, 4, 8, 5], [4, 4, 8, 6], [4, 4, 9, 5], [4, 4, 9, 6], [4, 4, 10, 4], [4, 4, 10, 7], [4, 5, 0, 3], [4, 5, 0, 5], [4, 5, 0, 6], [4, 5, 0, 8], [4, 5, 1, 3], [4, 5, 1, 8], [4, 5, 2, 3], [4, 5, 2, 4], [4, 5, 2, 8], [4, 5, 4, 3], [4, 5, 4, 4], [4, 5, 4, 5], [4, 5, 4, 6], [4, 5, 4, 8], [4, 5, 5, 3], [4, 5, 5, 4], [4, 5, 5, 5], [4, 5, 5, 6], [4, 5, 5, 8], [4, 5, 6, 5], [4, 5, 6, 6], [4, 5, 7, 3], [4, 5, 7, 4], [4, 5, 7, 8], [4, 5, 8, 5], [4, 5, 8, 6], [4, 5, 9, 5], [4, 5, 9, 6], [4, 6, 0, 4], [4, 6, 0, 5], [4, 6, 0, 6], [4, 6, 0, 7], [4, 6, 1, 4], [4, 6, 1, 7], [4, 6, 3, 4], [4, 6, 3, 7], [4, 6, 4, 4], [4, 6, 4, 5], [4, 6, 4, 6], [4, 6, 4, 7], [4, 6, 5, 4], [4, 6, 5, 5], [4, 6, 5, 6], [4, 6, 6, 4], [4, 6, 6, 5], [4, 6, 6, 6], [4, 6, 6, 7], [4, 6, 8, 5], [4, 6, 8, 6], [4, 6, 9, 5], [4, 6, 9, 6], [4, 6, 10, 4], [4, 6, 10, 7], [4, 7, 0, 3], [4, 7, 0, 8], [4, 7, 1, 3], [4, 7, 1, 8], [4, 7, 2, 3], [4, 7, 2, 4], [4, 7, 2, 8], [4, 7, 4, 3], [4, 7, 4, 8], [4, 7, 5, 3], [4, 7, 5, 8], [4, 7, 7, 3], [4, 7, 7, 4], [4, 7, 7, 8], [4, 8, 0, 4], [4, 8, 0, 5], [4, 8, 0, 6], [4, 8, 4, 4], [4, 8, 4, 5], [4, 8, 4, 6], [4, 8, 5, 4], [4, 8, 5, 5], [4, 8, 5, 6], [4, 8, 6, 5], [4, 8, 6, 6], [4, 8, 8, 5], [4, 8, 8, 6], [4, 8, 9, 5], [4, 8, 9, 6], [4, 9, 0, 5], [4, 9, 0, 6], [4, 9, 4, 4], [4, 9, 4, 5], [4, 9, 4, 6], [4, 9, 5, 4], [4, 9, 5, 5], [4, 9, 5, 6], [4, 9, 6, 5], [4, 9, 6, 6], [4, 9, 8, 5], [4, 9, 8, 6], [4, 9, 9, 5], [4, 9, 9, 6], [4, 10, 0, 4], [4, 10, 0, 7], [4, 10, 1, 4], [4, 10, 1, 7], [4, 10, 3, 4], [4, 10, 3, 7], [4, 10, 4, 4], [4, 10, 4, 7], [4, 10, 6, 4], [4, 10, 6, 7], [4, 10, 10, 4], [4, 10, 10, 7], [5, 0, 0, 1], [5, 0, 0, 3], [5, 0, 0, 4], [5, 0, 0, 5], [5, 0, 0, 6], [5, 0, 0, 8], [5, 0, 0, 10], [5, 0, 1, 3], [5, 0, 1, 8], [5, 0, 2, 1], [5, 0, 2, 3], [5, 0, 2, 4], [5, 0, 2, 8], [5, 0, 2, 10], [5, 0, 3, 1], [5, 0, 3, 10], [5, 0, 4, 3], [5, 0, 4, 4], [5, 0, 4, 5], [5, 0, 4, 6], [5, 0, 4, 8], [5, 0, 5, 1], [5, 0, 5, 3], [5, 0, 5, 4], [5, 0, 5, 5], [5, 0, 5, 6], [5, 0, 5, 8], [5, 0, 5, 10], [5, 0, 6, 5], [5, 0, 6, 6], [5, 0, 7, 3], [5, 0, 7, 4], [5, 0, 7, 8], [5, 0, 8, 5], [5, 0, 8, 6], [5, 0, 9, 1], [5, 0, 9, 4], [5, 0, 9, 5], [5, 0, 9, 6], [5, 0, 9, 10], [5, 0, 10, 1], [5, 0, 10, 10], [5, 1, 0, 3], [5, 1, 0, 8], [5, 1, 1, 3], [5, 1, 1, 8], [5, 1, 2, 3], [5, 1, 2, 4], [5, 1, 2, 8], [5, 1, 4, 3], [5, 1, 4, 8], [5, 1, 5, 3], [5, 1, 5, 8], [5, 1, 7, 3], [5, 1, 7, 4], [5, 1, 7, 8], [5, 2, 0, 1], [5, 2, 0, 3], [5, 2, 0, 4], [5, 2, 0, 8], [5, 2, 0, 10], [5, 2, 1, 3], [5, 2, 1, 8], [5, 2, 2, 1], [5, 2, 2, 3], [5, 2, 2, 4], [5, 2, 2, 8], [5, 2, 2, 10], [5, 2, 3, 1], [5, 2, 3, 10], [5, 2, 4, 3], [5, 2, 4, 8], [5, 2, 5, 1], [5, 2, 5, 3], [5, 2, 5, 8], [5, 2, 5, 10], [5, 2, 7, 3], [5, 2, 7, 4], [5, 2, 7, 8], [5, 2, 9, 1], [5, 2, 9, 4], [5, 2, 9, 10], [5, 2, 10, 1], [5, 2, 10, 10], [5, 3, 0, 1], [5, 3, 0, 4], [5, 3, 0, 10], [5, 3, 2, 1], [5, 3, 2, 10], [5, 3, 3, 1], [5, 3, 3, 10], [5, 3, 5, 1], [5, 3, 5, 10], [5, 3, 9, 1], [5, 3, 9, 4], [5, 3, 9, 10], [5, 3, 10, 1], [5, 3, 10, 10], [5, 4, 0, 3], [5, 4, 0, 4], [5, 4, 0, 5], [5, 4, 0, 6], [5, 4, 0, 8], [5, 4, 1, 3], [5, 4, 1, 8], [5, 4, 2, 3], [5, 4, 2, 4], [5, 4, 2, 8], [5, 4, 4, 3], [5, 4, 4, 4], [5, 4, 4, 5], [5, 4, 4, 6], [5, 4, 4, 8], [5, 4, 5, 3], [5, 4, 5, 4], [5, 4, 5, 5], [5, 4, 5, 6], [5, 4, 5, 8], [5, 4, 6, 5], [5, 4, 6, 6], [5, 4, 7, 3], [5, 4, 7, 4], [5, 4, 7, 8], [5, 4, 8, 5], [5, 4, 8, 6], [5, 4, 9, 5], [5, 4, 9, 6], [5, 5, 0, 1], [5, 5, 0, 3], [5, 5, 0, 4], [5, 5, 0, 5], [5, 5, 0, 6], [5, 5, 0, 8], [5, 5, 0, 10], [5, 5, 1, 3], [5, 5, 1, 8], [5, 5, 2, 1], [5, 5, 2, 3], [5, 5, 2, 4], [5, 5, 2, 8], [5, 5, 2, 10], [5, 5, 3, 1], [5, 5, 3, 10], [5, 5, 4, 3], [5, 5, 4, 4], [5, 5, 4, 5], [5, 5, 4, 6], [5, 5, 4, 8], [5, 5, 5, 1], [5, 5, 5, 3], [5, 5, 5, 4], [5, 5, 5, 5], [5, 5, 5, 6], [5, 5, 5, 8], [5, 5, 5, 10], [5, 5, 6, 5], [5, 5, 6, 6], [5, 5, 7, 3], [5, 5, 7, 4], [5, 5, 7, 8], [5, 5, 8, 5], [5, 5, 8, 6], [5, 5, 9, 1], [5, 5, 9, 4], [5, 5, 9, 5], [5, 5, 9, 6], [5, 5, 9, 10], [5, 5, 10, 1], [5, 5, 10, 10], [5, 6, 0, 5], [5, 6, 0, 6], [5, 6, 4, 4], [5, 6, 4, 5], [5, 6, 4, 6], [5, 6, 5, 4], [5, 6, 5, 5], [5, 6, 5, 6], [5, 6, 6, 5], [5, 6, 6, 6], [5, 6, 8, 5], [5, 6, 8, 6], [5, 6, 9, 5], [5, 6, 9, 6], [5, 7, 0, 3], [5, 7, 0, 8], [5, 7, 1, 3], [5, 7, 1, 8], [5, 7, 2, 3], [5, 7, 2, 4], [5, 7, 2, 8], [5, 7, 4, 3], [5, 7, 4, 8], [5, 7, 5, 3], [5, 7, 5, 8], [5, 7, 7, 3], [5, 7, 7, 4], [5, 7, 7, 8], [5, 8, 0, 5], [5, 8, 0, 6], [5, 8, 4, 4], [5, 8, 4, 5], [5, 8, 4, 6], [5, 8, 5, 4], [5, 8, 5, 5], [5, 8, 5, 6], [5, 8, 6, 5], [5, 8, 6, 6], [5, 8, 8, 5], [5, 8, 8, 6], [5, 8, 9, 5], [5, 8, 9, 6], [5, 9, 0, 1], [5, 9, 0, 4], [5, 9, 0, 5], [5, 9, 0, 6], [5, 9, 0, 10], [5, 9, 2, 1], [5, 9, 2, 10], [5, 9, 3, 1], [5, 9, 3, 10], [5, 9, 4, 4], [5, 9, 4, 5], [5, 9, 4, 6], [5, 9, 5, 1], [5, 9, 5, 4], [5, 9, 5, 5], [5, 9, 5, 6], [5, 9, 5, 10], [5, 9, 6, 5], [5, 9, 6, 6], [5, 9, 8, 5], [5, 9, 8, 6], [5, 9, 9, 1], [5, 9, 9, 4], [5, 9, 9, 5], [5, 9, 9, 6], [5, 9, 9, 10], [5, 9, 10, 1], [5, 9, 10, 10], [5, 10, 0, 1], [5, 10, 0, 4], [5, 10, 0, 10], [5, 10, 2, 1], [5, 10, 2, 10], [5, 10, 3, 1], [5, 10, 3, 10], [5, 10, 5, 1], [5, 10, 5, 10], [5, 10, 9, 1], [5, 10, 9, 4], [5, 10, 9, 10], [5, 10, 10, 1], [5, 10, 10, 10], [6, 0, 0, 0], [6, 0, 0, 4], [6, 0, 0, 5], [6, 0, 0, 6], [6, 0, 0, 7], [6, 0, 1, 4], [6, 0, 1, 7], [6, 0, 2, 0], [6, 0, 3, 4], [6, 0, 3, 7], [6, 0, 4, 4], [6, 0, 4, 5], [6, 0, 4, 6], [6, 0, 4, 7], [6, 0, 5, 4], [6, 0, 5, 5], [6, 0, 5, 6], [6, 0, 6, 0], [6, 0, 6, 4], [6, 0, 6, 5], [6, 0, 6, 6], [6, 0, 6, 7], [6, 0, 7, 0], [6, 0, 8, 0], [6, 0, 8, 5], [6, 0, 8, 6], [6, 0, 9, 5], [6, 0, 9, 6], [6, 0, 10, 0], [6, 0, 10, 4], [6, 0, 10, 7], [6, 1, 0, 4], [6, 1, 0, 7], [6, 1, 1, 4], [6, 1, 1, 7], [6, 1, 3, 4], [6, 1, 3, 7], [6, 1, 4, 4], [6, 1, 4, 7], [6, 1, 6, 4], [6, 1, 6, 7], [6, 1, 10, 4], [6, 1, 10, 7], [6, 2, 0, 0], [6, 2, 2, 0], [6, 2, 6, 0], [6, 2, 7, 0], [6, 2, 8, 0], [6, 2, 10, 0], [6, 2, 10, 4], [6, 3, 0, 4], [6, 3, 0, 7], [6, 3, 1, 4], [6, 3, 1, 7], [6, 3, 3, 4], [6, 3, 3, 7], [6, 3, 4, 4], [6, 3, 4, 7], [6, 3, 6, 4], [6, 3, 6, 7], [6, 3, 10, 4], [6, 3, 10, 7], [6, 4, 0, 4], [6, 4, 0, 5], [6, 4, 0, 6], [6, 4, 0, 7], [6, 4, 1, 4], [6, 4, 1, 7], [6, 4, 3, 4], [6, 4, 3, 7], [6, 4, 4, 4], [6, 4, 4, 5], [6, 4, 4, 6], [6, 4, 4, 7], [6, 4, 5, 4], [6, 4, 5, 5], [6, 4, 5, 6], [6, 4, 6, 4], [6, 4, 6, 5], [6, 4, 6, 6], [6, 4, 6, 7], [6, 4, 8, 5], [6, 4, 8, 6], [6, 4, 9, 5], [6, 4, 9, 6], [6, 4, 10, 4], [6, 4, 10, 7], [6, 5, 0, 5], [6, 5, 0, 6], [6, 5, 4, 4], [6, 5, 4, 5], [6, 5, 4, 6], [6, 5, 5, 4], [6, 5, 5, 5], [6, 5, 5, 6], [6, 5, 6, 5], [6, 5, 6, 6], [6, 5, 8, 5], [6, 5, 8, 6], [6, 5, 9, 5], [6, 5, 9, 6], [6, 6, 0, 0], [6, 6, 0, 4], [6, 6, 0, 5], [6, 6, 0, 6], [6, 6, 0, 7], [6, 6, 1, 4], [6, 6, 1, 7], [6, 6, 2, 0], [6, 6, 3, 4], [6, 6, 3, 7], [6, 6, 4, 4], [6, 6, 4, 5], [6, 6, 4, 6], [6, 6, 4, 7], [6, 6, 5, 4], [6, 6, 5, 5], [6, 6, 5, 6], [6, 6, 6, 0], [6, 6, 6, 4], [6, 6, 6, 5], [6, 6, 6, 6], [6, 6, 6, 7], [6, 6, 7, 0], [6, 6, 8, 0], [6, 6, 8, 5], [6, 6, 8, 6], [6, 6, 9, 5], [6, 6, 9, 6], [6, 6, 10, 0], [6, 6, 10, 4], [6, 6, 10, 7], [6, 7, 0, 0], [6, 7, 0, 4], [6, 7, 2, 0], [6, 7, 6, 0], [6, 7, 7, 0], [6, 7, 8, 0], [6, 7, 10, 0], [6, 7, 10, 4], [6, 8, 0, 0], [6, 8, 0, 5], [6, 8, 0, 6], [6, 8, 2, 0], [6, 8, 4, 4], [6, 8, 4, 5], [6, 8, 4, 6], [6, 8, 5, 4], [6, 8, 5, 5], [6, 8, 5, 6], [6, 8, 6, 0], [6, 8, 6, 5], [6, 8, 6, 6], [6, 8, 7, 0], [6, 8, 8, 0], [6, 8, 8, 5], [6, 8, 8, 6], [6, 8, 9, 5], [6, 8, 9, 6], [6, 8, 10, 0], [6, 8, 10, 4], [6, 9, 0, 4], [6, 9, 0, 5], [6, 9, 0, 6], [6, 9, 4, 4], [6, 9, 4, 5], [6, 9, 4, 6], [6, 9, 5, 4], [6, 9, 5, 5], [6, 9, 5, 6], [6, 9, 6, 5], [6, 9, 6, 6], [6, 9, 8, 5], [6, 9, 8, 6], [6, 9, 9, 5], [6, 9, 9, 6], [6, 10, 0, 0], [6, 10, 0, 4], [6, 10, 0, 7], [6, 10, 1, 4], [6, 10, 1, 7], [6, 10, 2, 0], [6, 10, 3, 4], [6, 10, 3, 7], [6, 10, 4, 4], [6, 10, 4, 7], [6, 10, 6, 0], [6, 10, 6, 4], [6, 10, 6, 7], [6, 10, 7, 0], [6, 10, 8, 0], [6, 10, 10, 0], [6, 10, 10, 4], [6, 10, 10, 7], [7, 0, 0, 0], [7, 0, 0, 2], [7, 0, 0, 3], [7, 0, 0, 4], [7, 0, 0, 8], [7, 0, 0, 9], [7, 0, 1, 2], [7, 0, 1, 3], [7, 0, 1, 4], [7, 0, 1, 8], [7, 0, 1, 9], [7, 0, 2, 0], [7, 0, 2, 3], [7, 0, 2, 4], [7, 0, 2, 8], [7, 0, 3, 2], [7, 0, 3, 9], [7, 0, 4, 3], [7, 0, 4, 8], [7, 0, 5, 3], [7, 0, 5, 8], [7, 0, 6, 0], [7, 0, 7, 0], [7, 0, 7, 2], [7, 0, 7, 3], [7, 0, 7, 4], [7, 0, 7, 8], [7, 0, 7, 9], [7, 0, 8, 0], [7, 0, 8, 2], [7, 0, 8, 4], [7, 0, 8, 9], [7, 0, 9, 2], [7, 0, 9, 9], [7, 0, 10, 0], [7, 0, 10, 4], [7, 1, 0, 2], [7, 1, 0, 3], [7, 1, 0, 8], [7, 1, 0, 9], [7, 1, 1, 2], [7, 1, 1, 3], [7, 1, 1, 4], [7, 1, 1, 8], [7, 1, 1, 9], [7, 1, 2, 3], [7, 1, 2, 4], [7, 1, 2, 8], [7, 1, 3, 2], [7, 1, 3, 9], [7, 1, 4, 3], [7, 1, 4, 8], [7, 1, 5, 3], [7, 1, 5, 8], [7, 1, 7, 2], [7, 1, 7, 3], [7, 1, 7, 4], [7, 1, 7, 8], [7, 1, 7, 9], [7, 1, 8, 2], [7, 1, 8, 4], [7, 1, 8, 9], [7, 1, 9, 2], [7, 1, 9, 9], [7, 2, 0, 0], [7, 2, 0, 3], [7, 2, 0, 8], [7, 2, 1, 3], [7, 2, 1, 8], [7, 2, 2, 0], [7, 2, 2, 3], [7, 2, 2, 4], [7, 2, 2, 8], [7, 2, 4, 3], [7, 2, 4, 8], [7, 2, 5, 3], [7, 2, 5, 8], [7, 2, 6, 0], [7, 2, 7, 0], [7, 2, 7, 3], [7, 2, 7, 4], [7, 2, 7, 8], [7, 2, 8, 0], [7, 2, 10, 0], [7, 2, 10, 4], [7, 3, 0, 2], [7, 3, 0, 4], [7, 3, 0, 9], [7, 3, 1, 2], [7, 3, 1, 4], [7, 3, 1, 9], [7, 3, 3, 2], [7, 3, 3, 9], [7, 3, 7, 2], [7, 3, 7, 9], [7, 3, 8, 2], [7, 3, 8, 4], [7, 3, 8, 9], [7, 3, 9, 2], [7, 3, 9, 9], [7, 4, 0, 3], [7, 4, 0, 4], [7, 4, 0, 8], [7, 4, 1, 3], [7, 4, 1, 8], [7, 4, 2, 3], [7, 4, 2, 4], [7, 4, 2, 8], [7, 4, 4, 3], [7, 4, 4, 8], [7, 4, 5, 3], [7, 4, 5, 8], [7, 4, 7, 3], [7, 4, 7, 4], [7, 4, 7, 8], [7, 5, 0, 3], [7, 5, 0, 8], [7, 5, 1, 3], [7, 5, 1, 8], [7, 5, 2, 3], [7, 5, 2, 4], [7, 5, 2, 8], [7, 5, 4, 3], [7, 5, 4, 8], [7, 5, 5, 3], [7, 5, 5, 8], [7, 5, 7, 3], [7, 5, 7, 4], [7, 5, 7, 8], [7, 6, 0, 0], [7, 6, 2, 0], [7, 6, 6, 0], [7, 6, 7, 0], [7, 6, 8, 0], [7, 6, 10, 0], [7, 6, 10, 4], [7, 7, 0, 0], [7, 7, 0, 2], [7, 7, 0, 3], [7, 7, 0, 4], [7, 7, 0, 8], [7, 7, 0, 9], [7, 7, 1, 2], [7, 7, 1, 3], [7, 7, 1, 4], [7, 7, 1, 8], [7, 7, 1, 9], [7, 7, 2, 0], [7, 7, 2, 3], [7, 7, 2, 4], [7, 7, 2, 8], [7, 7, 3, 2], [7, 7, 3, 9], [7, 7, 4, 3], [7, 7, 4, 8], [7, 7, 5, 3], [7, 7, 5, 8], [7, 7, 6, 0], [7, 7, 7, 0], [7, 7, 7, 2], [7, 7, 7, 3], [7, 7, 7, 4], [7, 7, 7, 8], [7, 7, 7, 9], [7, 7, 8, 0], [7, 7, 8, 2], [7, 7, 8, 4], [7, 7, 8, 9], [7, 7, 9, 2], [7, 7, 9, 9], [7, 7, 10, 0], [7, 7, 10, 4], [7, 8, 0, 0], [7, 8, 0, 2], [7, 8, 0, 9], [7, 8, 1, 2], [7, 8, 1, 4], [7, 8, 1, 9], [7, 8, 2, 0], [7, 8, 3, 2], [7, 8, 3, 9], [7, 8, 6, 0], [7, 8, 7, 0], [7, 8, 7, 2], [7, 8, 7, 9], [7, 8, 8, 0], [7, 8, 8, 2], [7, 8, 8, 4], [7, 8, 8, 9], [7, 8, 9, 2], [7, 8, 9, 9], [7, 8, 10, 0], [7, 8, 10, 4], [7, 9, 0, 2], [7, 9, 0, 4], [7, 9, 0, 9], [7, 9, 1, 2], [7, 9, 1, 4], [7, 9, 1, 9], [7, 9, 3, 2], [7, 9, 3, 9], [7, 9, 7, 2], [7, 9, 7, 9], [7, 9, 8, 2], [7, 9, 8, 4], [7, 9, 8, 9], [7, 9, 9, 2], [7, 9, 9, 9], [7, 10, 0, 0], [7, 10, 2, 0], [7, 10, 6, 0], [7, 10, 7, 0], [7, 10, 8, 0], [7, 10, 10, 0], [7, 10, 10, 4], [8, 0, 0, 0], [8, 0, 0, 2], [8, 0, 0, 4], [8, 0, 0, 5], [8, 0, 0, 6], [8, 0, 0, 9], [8, 0, 1, 2], [8, 0, 1, 4], [8, 0, 1, 9], [8, 0, 2, 0], [8, 0, 3, 2], [8, 0, 3, 9], [8, 0, 4, 4], [8, 0, 4, 5], [8, 0, 4, 6], [8, 0, 5, 4], [8, 0, 5, 5], [8, 0, 5, 6], [8, 0, 6, 0], [8, 0, 6, 5], [8, 0, 6, 6], [8, 0, 7, 0], [8, 0, 7, 2], [8, 0, 7, 9], [8, 0, 8, 0], [8, 0, 8, 2], [8, 0, 8, 4], [8, 0, 8, 5], [8, 0, 8, 6], [8, 0, 8, 9], [8, 0, 9, 2], [8, 0, 9, 5], [8, 0, 9, 6], [8, 0, 9, 9], [8, 0, 10, 0], [8, 0, 10, 4], [8, 1, 0, 2], [8, 1, 0, 9], [8, 1, 1, 2], [8, 1, 1, 4], [8, 1, 1, 9], [8, 1, 3, 2], [8, 1, 3, 9], [8, 1, 7, 2], [8, 1, 7, 9], [8, 1, 8, 2], [8, 1, 8, 4], [8, 1, 8, 9], [8, 1, 9, 2], [8, 1, 9, 9], [8, 2, 0, 0], [8, 2, 2, 0], [8, 2, 6, 0], [8, 2, 7, 0], [8, 2, 8, 0], [8, 2, 10, 0], [8, 2, 10, 4], [8, 3, 0, 2], [8, 3, 0, 4], [8, 3, 0, 9], [8, 3, 1, 2], [8, 3, 1, 4], [8, 3, 1, 9], [8, 3, 3, 2], [8, 3, 3, 9], [8, 3, 7, 2], [8, 3, 7, 9], [8, 3, 8, 2], [8, 3, 8, 4], [8, 3, 8, 9], [8, 3, 9, 2], [8, 3, 9, 9], [8, 4, 0, 4], [8, 4, 0, 5], [8, 4, 0, 6], [8, 4, 4, 4], [8, 4, 4, 5], [8, 4, 4, 6], [8, 4, 5, 4], [8, 4, 5, 5], [8, 4, 5, 6], [8, 4, 6, 5], [8, 4, 6, 6], [8, 4, 8, 5], [8, 4, 8, 6], [8, 4, 9, 5], [8, 4, 9, 6], [8, 5, 0, 5], [8, 5, 0, 6], [8, 5, 4, 4], [8, 5, 4, 5], [8, 5, 4, 6], [8, 5, 5, 4], [8, 5, 5, 5], [8, 5, 5, 6], [8, 5, 6, 5], [8, 5, 6, 6], [8, 5, 8, 5], [8, 5, 8, 6], [8, 5, 9, 5], [8, 5, 9, 6], [8, 6, 0, 0], [8, 6, 0, 5], [8, 6, 0, 6], [8, 6, 2, 0], [8, 6, 4, 4], [8, 6, 4, 5], [8, 6, 4, 6], [8, 6, 5, 4], [8, 6, 5, 5], [8, 6, 5, 6], [8, 6, 6, 0], [8, 6, 6, 5], [8, 6, 6, 6], [8, 6, 7, 0], [8, 6, 8, 0], [8, 6, 8, 5], [8, 6, 8, 6], [8, 6, 9, 5], [8, 6, 9, 6], [8, 6, 10, 0], [8, 6, 10, 4], [8, 7, 0, 0], [8, 7, 0, 2], [8, 7, 0, 4], [8, 7, 0, 9], [8, 7, 1, 2], [8, 7, 1, 4], [8, 7, 1, 9], [8, 7, 2, 0], [8, 7, 3, 2], [8, 7, 3, 9], [8, 7, 6, 0], [8, 7, 7, 0], [8, 7, 7, 2], [8, 7, 7, 9], [8, 7, 8, 0], [8, 7, 8, 2], [8, 7, 8, 4], [8, 7, 8, 9], [8, 7, 9, 2], [8, 7, 9, 9], [8, 7, 10, 0], [8, 7, 10, 4], [8, 8, 0, 0], [8, 8, 0, 2], [8, 8, 0, 4], [8, 8, 0, 5], [8, 8, 0, 6], [8, 8, 0, 9], [8, 8, 1, 2], [8, 8, 1, 4], [8, 8, 1, 9], [8, 8, 2, 0], [8, 8, 3, 2], [8, 8, 3, 9], [8, 8, 4, 4], [8, 8, 4, 5], [8, 8, 4, 6], [8, 8, 5, 4], [8, 8, 5, 5], [8, 8, 5, 6], [8, 8, 6, 0], [8, 8, 6, 5], [8, 8, 6, 6], [8, 8, 7, 0], [8, 8, 7, 2], [8, 8, 7, 9], [8, 8, 8, 0], [8, 8, 8, 2], [8, 8, 8, 4], [8, 8, 8, 5], [8, 8, 8, 6], [8, 8, 8, 9], [8, 8, 9, 2], [8, 8, 9, 5], [8, 8, 9, 6], [8, 8, 9, 9], [8, 8, 10, 0], [8, 8, 10, 4], [8, 9, 0, 2], [8, 9, 0, 5], [8, 9, 0, 6], [8, 9, 0, 9], [8, 9, 1, 2], [8, 9, 1, 4], [8, 9, 1, 9], [8, 9, 3, 2], [8, 9, 3, 9], [8, 9, 4, 4], [8, 9, 4, 5], [8, 9, 4, 6], [8, 9, 5, 4], [8, 9, 5, 5], [8, 9, 5, 6], [8, 9, 6, 5], [8, 9, 6, 6], [8, 9, 7, 2], [8, 9, 7, 9], [8, 9, 8, 2], [8, 9, 8, 4], [8, 9, 8, 5], [8, 9, 8, 6], [8, 9, 8, 9], [8, 9, 9, 2], [8, 9, 9, 5], [8, 9, 9, 6], [8, 9, 9, 9], [8, 10, 0, 0], [8, 10, 0, 4], [8, 10, 2, 0], [8, 10, 6, 0], [8, 10, 7, 0], [8, 10, 8, 0], [8, 10, 10, 0], [8, 10, 10, 4], [9, 0, 0, 1], [9, 0, 0, 2], [9, 0, 0, 4], [9, 0, 0, 5], [9, 0, 0, 6], [9, 0, 0, 9], [9, 0, 0, 10], [9, 0, 1, 2], [9, 0, 1, 4], [9, 0, 1, 9], [9, 0, 2, 1], [9, 0, 2, 10], [9, 0, 3, 1], [9, 0, 3, 2], [9, 0, 3, 9], [9, 0, 3, 10], [9, 0, 4, 4], [9, 0, 4, 5], [9, 0, 4, 6], [9, 0, 5, 1], [9, 0, 5, 4], [9, 0, 5, 5], [9, 0, 5, 6], [9, 0, 5, 10], [9, 0, 6, 5], [9, 0, 6, 6], [9, 0, 7, 2], [9, 0, 7, 9], [9, 0, 8, 2], [9, 0, 8, 4], [9, 0, 8, 5], [9, 0, 8, 6], [9, 0, 8, 9], [9, 0, 9, 1], [9, 0, 9, 2], [9, 0, 9, 4], [9, 0, 9, 5], [9, 0, 9, 6], [9, 0, 9, 9], [9, 0, 9, 10], [9, 0, 10, 1], [9, 0, 10, 10], [9, 1, 0, 2], [9, 1, 0, 9], [9, 1, 1, 2], [9, 1, 1, 4], [9, 1, 1, 9], [9, 1, 3, 2], [9, 1, 3, 9], [9, 1, 7, 2], [9, 1, 7, 9], [9, 1, 8, 2], [9, 1, 8, 4], [9, 1, 8, 9], [9, 1, 9, 2], [9, 1, 9, 9], [9, 2, 0, 1], [9, 2, 0, 4], [9, 2, 0, 10], [9, 2, 2, 1], [9, 2, 2, 10], [9, 2, 3, 1], [9, 2, 3, 10], [9, 2, 5, 1], [9, 2, 5, 10], [9, 2, 9, 1], [9, 2, 9, 4], [9, 2, 9, 10], [9, 2, 10, 1], [9, 2, 10, 10], [9, 3, 0, 1], [9, 3, 0, 2], [9, 3, 0, 4], [9, 3, 0, 9], [9, 3, 0, 10], [9, 3, 1, 2], [9, 3, 1, 4], [9, 3, 1, 9], [9, 3, 2, 1], [9, 3, 2, 10], [9, 3, 3, 1], [9, 3, 3, 2], [9, 3, 3, 9], [9, 3, 3, 10], [9, 3, 5, 1], [9, 3, 5, 10], [9, 3, 7, 2], [9, 3, 7, 9], [9, 3, 8, 2], [9, 3, 8, 4], [9, 3, 8, 9], [9, 3, 9, 1], [9, 3, 9, 2], [9, 3, 9, 4], [9, 3, 9, 9], [9, 3, 9, 10], [9, 3, 10, 1], [9, 3, 10, 10], [9, 4, 0, 5], [9, 4, 0, 6], [9, 4, 4, 4], [9, 4, 4, 5], [9, 4, 4, 6], [9, 4, 5, 4], [9, 4, 5, 5], [9, 4, 5, 6], [9, 4, 6, 5], [9, 4, 6, 6], [9, 4, 8, 5], [9, 4, 8, 6], [9, 4, 9, 5], [9, 4, 9, 6], [9, 5, 0, 1], [9, 5, 0, 4], [9, 5, 0, 5], [9, 5, 0, 6], [9, 5, 0, 10], [9, 5, 2, 1], [9, 5, 2, 10], [9, 5, 3, 1], [9, 5, 3, 10], [9, 5, 4, 4], [9, 5, 4, 5], [9, 5, 4, 6], [9, 5, 5, 1], [9, 5, 5, 4], [9, 5, 5, 5], [9, 5, 5, 6], [9, 5, 5, 10], [9, 5, 6, 5], [9, 5, 6, 6], [9, 5, 8, 5], [9, 5, 8, 6], [9, 5, 9, 1], [9, 5, 9, 4], [9, 5, 9, 5], [9, 5, 9, 6], [9, 5, 9, 10], [9, 5, 10, 1], [9, 5, 10, 10], [9, 6, 0, 5], [9, 6, 0, 6], [9, 6, 4, 4], [9, 6, 4, 5], [9, 6, 4, 6], [9, 6, 5, 4], [9, 6, 5, 5], [9, 6, 5, 6], [9, 6, 6, 5], [9, 6, 6, 6], [9, 6, 8, 5], [9, 6, 8, 6], [9, 6, 9, 5], [9, 6, 9, 6], [9, 7, 0, 2], [9, 7, 0, 9], [9, 7, 1, 2], [9, 7, 1, 4], [9, 7, 1, 9], [9, 7, 3, 2], [9, 7, 3, 9], [9, 7, 7, 2], [9, 7, 7, 9], [9, 7, 8, 2], [9, 7, 8, 4], [9, 7, 8, 9], [9, 7, 9, 2], [9, 7, 9, 9], [9, 8, 0, 2], [9, 8, 0, 4], [9, 8, 0, 5], [9, 8, 0, 6], [9, 8, 0, 9], [9, 8, 1, 2], [9, 8, 1, 4], [9, 8, 1, 9], [9, 8, 3, 2], [9, 8, 3, 9], [9, 8, 4, 4], [9, 8, 4, 5], [9, 8, 4, 6], [9, 8, 5, 4], [9, 8, 5, 5], [9, 8, 5, 6], [9, 8, 6, 5], [9, 8, 6, 6], [9, 8, 7, 2], [9, 8, 7, 9], [9, 8, 8, 2], [9, 8, 8, 4], [9, 8, 8, 5], [9, 8, 8, 6], [9, 8, 8, 9], [9, 8, 9, 2], [9, 8, 9, 5], [9, 8, 9, 6], [9, 8, 9, 9], [9, 9, 0, 1], [9, 9, 0, 2], [9, 9, 0, 4], [9, 9, 0, 5], [9, 9, 0, 6], [9, 9, 0, 9], [9, 9, 0, 10], [9, 9, 1, 2], [9, 9, 1, 4], [9, 9, 1, 9], [9, 9, 2, 1], [9, 9, 2, 10], [9, 9, 3, 1], [9, 9, 3, 2], [9, 9, 3, 9], [9, 9, 3, 10], [9, 9, 4, 4], [9, 9, 4, 5], [9, 9, 4, 6], [9, 9, 5, 1], [9, 9, 5, 4], [9, 9, 5, 5], [9, 9, 5, 6], [9, 9, 5, 10], [9, 9, 6, 5], [9, 9, 6, 6], [9, 9, 7, 2], [9, 9, 7, 9], [9, 9, 8, 2], [9, 9, 8, 4], [9, 9, 8, 5], [9, 9, 8, 6], [9, 9, 8, 9], [9, 9, 9, 1], [9, 9, 9, 2], [9, 9, 9, 4], [9, 9, 9, 5], [9, 9, 9, 6], [9, 9, 9, 9], [9, 9, 9, 10], [9, 9, 10, 1], [9, 9, 10, 10], [9, 10, 0, 1], [9, 10, 0, 4], [9, 10, 0, 10], [9, 10, 2, 1], [9, 10, 2, 10], [9, 10, 3, 1], [9, 10, 3, 10], [9, 10, 5, 1], [9, 10, 5, 10], [9, 10, 9, 1], [9, 10, 9, 4], [9, 10, 9, 10], [9, 10, 10, 1], [9, 10, 10, 10], [10, 0, 0, 0], [10, 0, 0, 1], [10, 0, 0, 4], [10, 0, 0, 7], [10, 0, 0, 10], [10, 0, 1, 4], [10, 0, 1, 7], [10, 0, 2, 0], [10, 0, 2, 1], [10, 0, 2, 10], [10, 0, 3, 1], [10, 0, 3, 4], [10, 0, 3, 7], [10, 0, 3, 10], [10, 0, 4, 4], [10, 0, 4, 7], [10, 0, 5, 1], [10, 0, 5, 10], [10, 0, 6, 0], [10, 0, 6, 4], [10, 0, 6, 7], [10, 0, 7, 0], [10, 0, 8, 0], [10, 0, 9, 1], [10, 0, 9, 4], [10, 0, 9, 10], [10, 0, 10, 0], [10, 0, 10, 1], [10, 0, 10, 4], [10, 0, 10, 7], [10, 0, 10, 10], [10, 1, 0, 4], [10, 1, 0, 7], [10, 1, 1, 4], [10, 1, 1, 7], [10, 1, 3, 4], [10, 1, 3, 7], [10, 1, 4, 4], [10, 1, 4, 7], [10, 1, 6, 4], [10, 1, 6, 7], [10, 1, 10, 4], [10, 1, 10, 7], [10, 2, 0, 0], [10, 2, 0, 1], [10, 2, 0, 4], [10, 2, 0, 10], [10, 2, 2, 0], [10, 2, 2, 1], [10, 2, 2, 10], [10, 2, 3, 1], [10, 2, 3, 10], [10, 2, 5, 1], [10, 2, 5, 10], [10, 2, 6, 0], [10, 2, 7, 0], [10, 2, 8, 0], [10, 2, 9, 1], [10, 2, 9, 4], [10, 2, 9, 10], [10, 2, 10, 0], [10, 2, 10, 1], [10, 2, 10, 4], [10, 2, 10, 10], [10, 3, 0, 1], [10, 3, 0, 4], [10, 3, 0, 7], [10, 3, 0, 10], [10, 3, 1, 4], [10, 3, 1, 7], [10, 3, 2, 1], [10, 3, 2, 10], [10, 3, 3, 1], [10, 3, 3, 4], [10, 3, 3, 7], [10, 3, 3, 10], [10, 3, 4, 4], [10, 3, 4, 7], [10, 3, 5, 1], [10, 3, 5, 10], [10, 3, 6, 4], [10, 3, 6, 7], [10, 3, 9, 1], [10, 3, 9, 4], [10, 3, 9, 10], [10, 3, 10, 1], [10, 3, 10, 4], [10, 3, 10, 7], [10, 3, 10, 10], [10, 4, 0, 4], [10, 4, 0, 7], [10, 4, 1, 4], [10, 4, 1, 7], [10, 4, 3, 4], [10, 4, 3, 7], [10, 4, 4, 4], [10, 4, 4, 7], [10, 4, 6, 4], [10, 4, 6, 7], [10, 4, 10, 4], [10, 4, 10, 7], [10, 5, 0, 1], [10, 5, 0, 4], [10, 5, 0, 10], [10, 5, 2, 1], [10, 5, 2, 10], [10, 5, 3, 1], [10, 5, 3, 10], [10, 5, 5, 1], [10, 5, 5, 10], [10, 5, 9, 1], [10, 5, 9, 4], [10, 5, 9, 10], [10, 5, 10, 1], [10, 5, 10, 10], [10, 6, 0, 0], [10, 6, 0, 4], [10, 6, 0, 7], [10, 6, 1, 4], [10, 6, 1, 7], [10, 6, 2, 0], [10, 6, 3, 4], [10, 6, 3, 7], [10, 6, 4, 4], [10, 6, 4, 7], [10, 6, 6, 0], [10, 6, 6, 4], [10, 6, 6, 7], [10, 6, 7, 0], [10, 6, 8, 0], [10, 6, 10, 0], [10, 6, 10, 4], [10, 6, 10, 7], [10, 7, 0, 0], [10, 7, 0, 4], [10, 7, 2, 0], [10, 7, 6, 0], [10, 7, 7, 0], [10, 7, 8, 0], [10, 7, 10, 0], [10, 7, 10, 4], [10, 8, 0, 0], [10, 8, 0, 4], [10, 8, 2, 0], [10, 8, 6, 0], [10, 8, 7, 0], [10, 8, 8, 0], [10, 8, 10, 0], [10, 8, 10, 4], [10, 9, 0, 1], [10, 9, 0, 4], [10, 9, 0, 10], [10, 9, 2, 1], [10, 9, 2, 10], [10, 9, 3, 1], [10, 9, 3, 10], [10, 9, 5, 1], [10, 9, 5, 10], [10, 9, 9, 1], [10, 9, 9, 4], [10, 9, 9, 10], [10, 9, 10, 1], [10, 9, 10, 10], [10, 10, 0, 0], [10, 10, 0, 1], [10, 10, 0, 4], [10, 10, 0, 7], [10, 10, 0, 10], [10, 10, 1, 4], [10, 10, 1, 7], [10, 10, 2, 0], [10, 10, 2, 1], [10, 10, 2, 10], [10, 10, 3, 1], [10, 10, 3, 4], [10, 10, 3, 7], [10, 10, 3, 10], [10, 10, 4, 4], [10, 10, 4, 7], [10, 10, 5, 1], [10, 10, 5, 10], [10, 10, 6, 0], [10, 10, 6, 4], [10, 10, 6, 7], [10, 10, 7, 0], [10, 10, 8, 0], [10, 10, 9, 1], [10, 10, 9, 4], [10, 10, 9, 10], [10, 10, 10, 0], [10, 10, 10, 1], [10, 10, 10, 4], [10, 10, 10, 7], [10, 10, 10, 10]]} +RLMATH_EOF diff --git a/tasks/optimize-ae-p1-ff-kakeya-d4-p11/tests/check.py b/tasks/optimize-ae-p1-ff-kakeya-d4-p11/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..dac5049b59a505ff843bc5e086d0c1c303695b2a --- /dev/null +++ b/tasks/optimize-ae-p1-ff-kakeya-d4-p11/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-p11/tests/instance.json b/tasks/optimize-ae-p1-ff-kakeya-d4-p11/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3db38a33343f825287150f97043163f568fb44e2 --- /dev/null +++ b/tasks/optimize-ae-p1-ff-kakeya-d4-p11/tests/instance.json @@ -0,0 +1 @@ +{"p": 11, "d": 4, "direction": "minimize", "best_known": 2687, "baseline": 14641, "family": "ae_p1_ff_kakeya", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p1-ff-kakeya-d4-p11/tests/test.sh b/tasks/optimize-ae-p1-ff-kakeya-d4-p11/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-ae-p1-ff-kakeya-d4-p11/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-nikodym-d3-p31/environment/Dockerfile b/tasks/optimize-ae-p1-ff-nikodym-d3-p31/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-ae-p1-ff-nikodym-d3-p31/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-nikodym-d3-p31/environment/instance.json b/tasks/optimize-ae-p1-ff-nikodym-d3-p31/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9b5812e5c0e10f30d29b040b4610c82bada84f37 --- /dev/null +++ b/tasks/optimize-ae-p1-ff-nikodym-d3-p31/environment/instance.json @@ -0,0 +1 @@ +{"p": 31, "direction": "minimize", "family": "ae_p1_ff_nikodym", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p1-ff-nikodym-d3-p31/solution/solve.sh b/tasks/optimize-ae-p1-ff-nikodym-d3-p31/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6208af00e6ca51f0807afa230d3e3004505d1d76 --- /dev/null +++ b/tasks/optimize-ae-p1-ff-nikodym-d3-p31/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' +{"removed": [[0, 1, 1], [0, 2, 2], [0, 3, 3], [0, 4, 4], [0, 5, 5], [0, 6, 6], [0, 7, 7], [0, 8, 8], [0, 9, 9], [0, 10, 10], [0, 11, 11], [0, 12, 12], [0, 13, 13], [0, 14, 14], [0, 15, 15], [0, 16, 16], [0, 17, 17], [0, 18, 18], [0, 19, 19], [0, 20, 20], [0, 21, 21], [0, 22, 22], [0, 23, 23], [0, 24, 24], [0, 25, 25], [0, 26, 26], [0, 27, 27], [0, 28, 28], [0, 29, 29], [0, 30, 30], [1, 0, 1], [1, 1, 0], [1, 1, 1], [2, 0, 2], [2, 1, 2], [2, 1, 4], [2, 1, 8], [2, 1, 16], [2, 2, 0], [2, 2, 1], [2, 2, 2], [2, 2, 4], [2, 2, 8], [2, 2, 16], [2, 4, 1], [2, 4, 2], [2, 4, 8], [2, 4, 16], [2, 8, 1], [2, 8, 2], [2, 8, 4], [2, 8, 16], [2, 16, 1], [2, 16, 2], [2, 16, 4], [2, 16, 8], [3, 0, 3], [3, 1, 3], [3, 1, 7], [3, 1, 9], [3, 1, 18], [3, 1, 19], [3, 1, 21], [3, 1, 23], [3, 1, 27], [3, 2, 5], [3, 2, 6], [3, 2, 7], [3, 2, 11], [3, 2, 14], [3, 2, 15], [3, 2, 18], [3, 2, 23], [3, 3, 0], [3, 3, 1], [3, 3, 3], [3, 3, 7], [3, 3, 9], [3, 3, 19], [3, 3, 21], [3, 3, 23], [3, 3, 26], [3, 3, 27], [3, 4, 5], [3, 4, 10], [3, 4, 12], [3, 4, 14], [3, 4, 15], [3, 4, 22], [3, 4, 28], [3, 4, 30], [3, 5, 2], [3, 5, 4], [3, 5, 11], [3, 5, 12], [3, 5, 14], [3, 5, 15], [3, 5, 22], [3, 5, 28], [3, 6, 2], [3, 6, 7], [3, 6, 11], [3, 6, 14], [3, 6, 15], [3, 6, 18], [3, 6, 21], [3, 6, 23], [3, 7, 1], [3, 7, 2], [3, 7, 3], [3, 7, 6], [3, 7, 9], [3, 7, 18], [3, 7, 21], [3, 7, 23], [3, 8, 10], [3, 8, 13], [3, 8, 20], [3, 8, 24], [3, 8, 25], [3, 8, 28], [3, 8, 29], [3, 8, 30], [3, 9, 1], [3, 9, 3], [3, 9, 7], [3, 9, 16], [3, 9, 19], [3, 9, 21], [3, 9, 26], [3, 9, 27], [3, 10, 4], [3, 10, 8], [3, 10, 13], [3, 10, 22], [3, 10, 24], [3, 10, 25], [3, 10, 28], [3, 10, 30], [3, 11, 2], [3, 11, 5], [3, 11, 6], [3, 11, 12], [3, 11, 14], [3, 11, 15], [3, 11, 18], [3, 11, 23], [3, 12, 4], [3, 12, 5], [3, 12, 11], [3, 12, 14], [3, 12, 15], [3, 12, 22], [3, 12, 28], [3, 12, 30], [3, 13, 8], [3, 13, 10], [3, 13, 17], [3, 13, 20], [3, 13, 24], [3, 13, 25], [3, 13, 29], [3, 13, 30], [3, 14, 2], [3, 14, 4], [3, 14, 5], [3, 14, 6], [3, 14, 11], [3, 14, 12], [3, 14, 15], [3, 14, 18], [3, 15, 2], [3, 15, 4], [3, 15, 5], [3, 15, 6], [3, 15, 11], [3, 15, 12], [3, 15, 14], [3, 15, 22], [3, 16, 9], [3, 16, 17], [3, 16, 19], [3, 16, 20], [3, 16, 25], [3, 16, 26], [3, 16, 27], [3, 16, 29], [3, 17, 13], [3, 17, 16], [3, 17, 19], [3, 17, 20], [3, 17, 25], [3, 17, 26], [3, 17, 27], [3, 17, 29], [3, 18, 1], [3, 18, 2], [3, 18, 6], [3, 18, 7], [3, 18, 11], [3, 18, 14], [3, 18, 21], [3, 18, 23], [3, 19, 1], [3, 19, 3], [3, 19, 9], [3, 19, 16], [3, 19, 17], [3, 19, 20], [3, 19, 26], [3, 19, 27], [3, 20, 8], [3, 20, 13], [3, 20, 16], [3, 20, 17], [3, 20, 19], [3, 20, 25], [3, 20, 26], [3, 20, 29], [3, 21, 1], [3, 21, 3], [3, 21, 6], [3, 21, 7], [3, 21, 9], [3, 21, 18], [3, 21, 23], [3, 21, 27], [3, 22, 4], [3, 22, 5], [3, 22, 10], [3, 22, 12], [3, 22, 15], [3, 22, 24], [3, 22, 28], [3, 22, 30], [3, 23, 1], [3, 23, 2], [3, 23, 3], [3, 23, 6], [3, 23, 7], [3, 23, 11], [3, 23, 18], [3, 23, 21], [3, 24, 8], [3, 24, 10], [3, 24, 13], [3, 24, 22], [3, 24, 25], [3, 24, 28], [3, 24, 29], [3, 24, 30], [3, 25, 8], [3, 25, 10], [3, 25, 13], [3, 25, 16], [3, 25, 17], [3, 25, 20], [3, 25, 24], [3, 25, 29], [3, 26, 3], [3, 26, 9], [3, 26, 16], [3, 26, 17], [3, 26, 19], [3, 26, 20], [3, 26, 27], [3, 26, 29], [3, 27, 1], [3, 27, 3], [3, 27, 9], [3, 27, 16], [3, 27, 17], [3, 27, 19], [3, 27, 21], [3, 27, 26], [3, 28, 4], [3, 28, 5], [3, 28, 8], [3, 28, 10], [3, 28, 12], [3, 28, 22], [3, 28, 24], [3, 28, 30], [3, 29, 8], [3, 29, 13], [3, 29, 16], [3, 29, 17], [3, 29, 20], [3, 29, 24], [3, 29, 25], [3, 29, 26], [3, 30, 4], [3, 30, 8], [3, 30, 10], [3, 30, 12], [3, 30, 13], [3, 30, 22], [3, 30, 24], [3, 30, 28], [4, 0, 4], [4, 1, 2], [4, 1, 4], [4, 1, 8], [4, 1, 16], [4, 2, 1], [4, 2, 4], [4, 2, 8], [4, 2, 16], [4, 4, 0], [4, 4, 1], [4, 4, 2], [4, 4, 4], [4, 4, 8], [4, 4, 16], [4, 8, 1], [4, 8, 2], [4, 8, 4], [4, 8, 16], [4, 16, 1], [4, 16, 2], [4, 16, 4], [4, 16, 8], [5, 0, 5], [5, 1, 1], [5, 1, 5], [5, 1, 25], [5, 5, 0], [5, 5, 1], [5, 5, 5], [5, 5, 25], [5, 25, 1], [5, 25, 5], [5, 25, 25], [6, 0, 6], [6, 1, 5], [6, 1, 6], [6, 1, 25], [6, 1, 26], [6, 1, 30], [6, 5, 1], [6, 5, 6], [6, 5, 25], [6, 5, 26], [6, 5, 30], [6, 6, 0], [6, 6, 1], [6, 6, 5], [6, 6, 6], [6, 6, 25], [6, 6, 26], [6, 6, 30], [6, 25, 1], [6, 25, 5], [6, 25, 6], [6, 25, 26], [6, 25, 30], [6, 26, 1], [6, 26, 5], [6, 26, 6], [6, 26, 25], [6, 26, 30], [6, 30, 1], [6, 30, 5], [6, 30, 6], [6, 30, 25], [6, 30, 26], [7, 0, 7], [7, 1, 2], [7, 1, 7], [7, 1, 9], [7, 1, 14], [7, 1, 16], [7, 1, 18], [7, 1, 19], [7, 1, 20], [7, 2, 1], [7, 2, 4], [7, 2, 5], [7, 2, 7], [7, 2, 9], [7, 2, 14], [7, 2, 18], [7, 2, 28], [7, 4, 2], [7, 4, 5], [7, 4, 8], [7, 4, 10], [7, 4, 14], [7, 4, 18], [7, 4, 25], [7, 4, 28], [7, 5, 2], [7, 5, 4], [7, 5, 7], [7, 5, 8], [7, 5, 10], [7, 5, 14], [7, 5, 18], [7, 5, 28], [7, 7, 0], [7, 7, 1], [7, 7, 2], [7, 7, 5], [7, 7, 7], [7, 7, 9], [7, 7, 14], [7, 7, 16], [7, 7, 18], [7, 7, 19], [7, 8, 4], [7, 8, 5], [7, 8, 10], [7, 8, 16], [7, 8, 19], [7, 8, 20], [7, 8, 25], [7, 8, 28], [7, 9, 1], [7, 9, 2], [7, 9, 7], [7, 9, 16], [7, 9, 18], [7, 9, 19], [7, 9, 20], [7, 9, 25], [7, 10, 4], [7, 10, 5], [7, 10, 8], [7, 10, 14], [7, 10, 16], [7, 10, 20], [7, 10, 25], [7, 10, 28], [7, 14, 1], [7, 14, 2], [7, 14, 4], [7, 14, 5], [7, 14, 7], [7, 14, 10], [7, 14, 18], [7, 14, 28], [7, 16, 1], [7, 16, 7], [7, 16, 8], [7, 16, 9], [7, 16, 10], [7, 16, 19], [7, 16, 20], [7, 16, 25], [7, 18, 1], [7, 18, 2], [7, 18, 4], [7, 18, 5], [7, 18, 7], [7, 18, 9], [7, 18, 14], [7, 18, 19], [7, 19, 1], [7, 19, 7], [7, 19, 8], [7, 19, 9], [7, 19, 16], [7, 19, 18], [7, 19, 20], [7, 19, 25], [7, 20, 1], [7, 20, 8], [7, 20, 9], [7, 20, 10], [7, 20, 16], [7, 20, 19], [7, 20, 25], [7, 20, 28], [7, 25, 4], [7, 25, 8], [7, 25, 9], [7, 25, 10], [7, 25, 16], [7, 25, 19], [7, 25, 20], [7, 25, 28], [7, 28, 2], [7, 28, 4], [7, 28, 5], [7, 28, 8], [7, 28, 10], [7, 28, 14], [7, 28, 20], [7, 28, 25], [8, 0, 8], [8, 1, 2], [8, 1, 4], [8, 1, 8], [8, 1, 16], [8, 2, 1], [8, 2, 4], [8, 2, 8], [8, 2, 16], [8, 4, 1], [8, 4, 2], [8, 4, 8], [8, 4, 16], [8, 8, 0], [8, 8, 1], [8, 8, 2], [8, 8, 4], [8, 8, 8], [8, 8, 16], [8, 16, 1], [8, 16, 2], [8, 16, 4], [8, 16, 8], [9, 0, 9], [9, 1, 2], [9, 1, 7], [9, 1, 9], [9, 1, 14], [9, 1, 16], [9, 1, 18], [9, 1, 19], [9, 1, 20], [9, 2, 1], [9, 2, 4], [9, 2, 5], [9, 2, 7], [9, 2, 9], [9, 2, 14], [9, 2, 18], [9, 2, 28], [9, 4, 2], [9, 4, 5], [9, 4, 8], [9, 4, 10], [9, 4, 14], [9, 4, 18], [9, 4, 25], [9, 4, 28], [9, 5, 2], [9, 5, 4], [9, 5, 7], [9, 5, 8], [9, 5, 10], [9, 5, 14], [9, 5, 18], [9, 5, 28], [9, 7, 1], [9, 7, 2], [9, 7, 5], [9, 7, 9], [9, 7, 14], [9, 7, 16], [9, 7, 18], [9, 7, 19], [9, 8, 4], [9, 8, 5], [9, 8, 10], [9, 8, 16], [9, 8, 19], [9, 8, 20], [9, 8, 25], [9, 8, 28], [9, 9, 0], [9, 9, 1], [9, 9, 2], [9, 9, 7], [9, 9, 9], [9, 9, 16], [9, 9, 18], [9, 9, 19], [9, 9, 20], [9, 9, 25], [9, 10, 4], [9, 10, 5], [9, 10, 8], [9, 10, 14], [9, 10, 16], [9, 10, 20], [9, 10, 25], [9, 10, 28], [9, 14, 1], [9, 14, 2], [9, 14, 4], [9, 14, 5], [9, 14, 7], [9, 14, 10], [9, 14, 18], [9, 14, 28], [9, 16, 1], [9, 16, 7], [9, 16, 8], [9, 16, 9], [9, 16, 10], [9, 16, 19], [9, 16, 20], [9, 16, 25], [9, 18, 1], [9, 18, 2], [9, 18, 4], [9, 18, 5], [9, 18, 7], [9, 18, 9], [9, 18, 14], [9, 18, 19], [9, 19, 1], [9, 19, 7], [9, 19, 8], [9, 19, 9], [9, 19, 16], [9, 19, 18], [9, 19, 20], [9, 19, 25], [9, 20, 1], [9, 20, 8], [9, 20, 9], [9, 20, 10], [9, 20, 16], [9, 20, 19], [9, 20, 25], [9, 20, 28], [9, 25, 4], [9, 25, 8], [9, 25, 9], [9, 25, 10], [9, 25, 16], [9, 25, 19], [9, 25, 20], [9, 25, 28], [9, 28, 2], [9, 28, 4], [9, 28, 5], [9, 28, 8], [9, 28, 10], [9, 28, 14], [9, 28, 20], [9, 28, 25], [10, 0, 10], [10, 1, 4], [10, 1, 7], [10, 1, 8], [10, 1, 9], [10, 1, 10], [10, 1, 18], [10, 1, 19], [10, 1, 28], [10, 2, 5], [10, 2, 7], [10, 2, 8], [10, 2, 14], [10, 2, 16], [10, 2, 18], [10, 2, 20], [10, 2, 25], [10, 4, 1], [10, 4, 5], [10, 4, 9], [10, 4, 10], [10, 4, 14], [10, 4, 16], [10, 4, 19], [10, 4, 28], [10, 5, 2], [10, 5, 4], [10, 5, 9], [10, 5, 14], [10, 5, 16], [10, 5, 19], [10, 5, 20], [10, 5, 28], [10, 7, 1], [10, 7, 2], [10, 7, 8], [10, 7, 9], [10, 7, 10], [10, 7, 18], [10, 7, 25], [10, 7, 28], [10, 8, 1], [10, 8, 2], [10, 8, 7], [10, 8, 10], [10, 8, 18], [10, 8, 20], [10, 8, 25], [10, 8, 28], [10, 9, 1], [10, 9, 4], [10, 9, 5], [10, 9, 7], [10, 9, 10], [10, 9, 16], [10, 9, 19], [10, 9, 28], [10, 10, 0], [10, 10, 1], [10, 10, 4], [10, 10, 7], [10, 10, 8], [10, 10, 9], [10, 10, 10], [10, 10, 18], [10, 10, 25], [10, 10, 28], [10, 14, 2], [10, 14, 4], [10, 14, 5], [10, 14, 16], [10, 14, 18], [10, 14, 19], [10, 14, 20], [10, 14, 25], [10, 16, 2], [10, 16, 4], [10, 16, 5], [10, 16, 9], [10, 16, 14], [10, 16, 19], [10, 16, 20], [10, 16, 25], [10, 18, 1], [10, 18, 2], [10, 18, 7], [10, 18, 8], [10, 18, 10], [10, 18, 14], [10, 18, 20], [10, 18, 25], [10, 19, 1], [10, 19, 4], [10, 19, 5], [10, 19, 9], [10, 19, 14], [10, 19, 16], [10, 19, 20], [10, 19, 28], [10, 20, 2], [10, 20, 5], [10, 20, 8], [10, 20, 14], [10, 20, 16], [10, 20, 18], [10, 20, 19], [10, 20, 25], [10, 25, 2], [10, 25, 7], [10, 25, 8], [10, 25, 10], [10, 25, 14], [10, 25, 16], [10, 25, 18], [10, 25, 20], [10, 28, 1], [10, 28, 4], [10, 28, 5], [10, 28, 7], [10, 28, 8], [10, 28, 9], [10, 28, 10], [10, 28, 19], [11, 0, 11], [11, 1, 7], [11, 1, 9], [11, 1, 10], [11, 1, 11], [11, 1, 15], [11, 1, 17], [11, 1, 28], [11, 1, 29], [11, 2, 3], [11, 2, 14], [11, 2, 18], [11, 2, 20], [11, 2, 22], [11, 2, 25], [11, 2, 27], [11, 2, 30], [11, 3, 2], [11, 3, 14], [11, 3, 20], [11, 3, 21], [11, 3, 22], [11, 3, 25], [11, 3, 27], [11, 3, 30], [11, 4, 5], [11, 4, 6], [11, 4, 9], [11, 4, 13], [11, 4, 19], [11, 4, 23], [11, 4, 28], [11, 4, 29], [11, 5, 4], [11, 5, 13], [11, 5, 14], [11, 5, 16], [11, 5, 19], [11, 5, 21], [11, 5, 23], [11, 5, 24], [11, 6, 4], [11, 6, 9], [11, 6, 11], [11, 6, 13], [11, 6, 19], [11, 6, 23], [11, 6, 28], [11, 6, 29], [11, 7, 1], [11, 7, 8], [11, 7, 10], [11, 7, 12], [11, 7, 15], [11, 7, 17], [11, 7, 18], [11, 7, 26], [11, 8, 7], [11, 8, 10], [11, 8, 12], [11, 8, 15], [11, 8, 18], [11, 8, 25], [11, 8, 26], [11, 8, 27], [11, 9, 1], [11, 9, 4], [11, 9, 6], [11, 9, 11], [11, 9, 13], [11, 9, 19], [11, 9, 28], [11, 9, 29], [11, 10, 1], [11, 10, 7], [11, 10, 8], [11, 10, 11], [11, 10, 15], [11, 10, 17], [11, 10, 26], [11, 10, 28], [11, 11, 0], [11, 11, 1], [11, 11, 6], [11, 11, 9], [11, 11, 10], [11, 11, 11], [11, 11, 15], [11, 11, 17], [11, 11, 28], [11, 11, 29], [11, 12, 7], [11, 12, 8], [11, 12, 15], [11, 12, 18], [11, 12, 22], [11, 12, 25], [11, 12, 26], [11, 12, 27], [11, 13, 4], [11, 13, 5], [11, 13, 6], [11, 13, 9], [11, 13, 19], [11, 13, 23], [11, 13, 24], [11, 13, 29], [11, 14, 2], [11, 14, 3], [11, 14, 5], [11, 14, 16], [11, 14, 20], [11, 14, 21], [11, 14, 24], [11, 14, 30], [11, 15, 1], [11, 15, 7], [11, 15, 8], [11, 15, 10], [11, 15, 11], [11, 15, 12], [11, 15, 17], [11, 15, 26], [11, 16, 5], [11, 16, 14], [11, 16, 19], [11, 16, 20], [11, 16, 21], [11, 16, 23], [11, 16, 24], [11, 16, 30], [11, 17, 1], [11, 17, 7], [11, 17, 10], [11, 17, 11], [11, 17, 15], [11, 17, 26], [11, 17, 28], [11, 17, 29], [11, 18, 2], [11, 18, 7], [11, 18, 8], [11, 18, 12], [11, 18, 22], [11, 18, 25], [11, 18, 26], [11, 18, 27], [11, 19, 4], [11, 19, 5], [11, 19, 6], [11, 19, 9], [11, 19, 13], [11, 19, 16], [11, 19, 23], [11, 19, 24], [11, 20, 2], [11, 20, 3], [11, 20, 14], [11, 20, 16], [11, 20, 21], [11, 20, 22], [11, 20, 25], [11, 20, 30], [11, 21, 3], [11, 21, 5], [11, 21, 14], [11, 21, 16], [11, 21, 20], [11, 21, 23], [11, 21, 24], [11, 21, 30], [11, 22, 2], [11, 22, 3], [11, 22, 12], [11, 22, 18], [11, 22, 20], [11, 22, 25], [11, 22, 27], [11, 22, 30], [11, 23, 4], [11, 23, 5], [11, 23, 6], [11, 23, 13], [11, 23, 16], [11, 23, 19], [11, 23, 21], [11, 23, 24], [11, 24, 5], [11, 24, 13], [11, 24, 14], [11, 24, 16], [11, 24, 19], [11, 24, 21], [11, 24, 23], [11, 24, 30], [11, 25, 2], [11, 25, 3], [11, 25, 8], [11, 25, 12], [11, 25, 18], [11, 25, 20], [11, 25, 22], [11, 25, 27], [11, 26, 7], [11, 26, 8], [11, 26, 10], [11, 26, 12], [11, 26, 15], [11, 26, 17], [11, 26, 18], [11, 26, 27], [11, 27, 2], [11, 27, 3], [11, 27, 8], [11, 27, 12], [11, 27, 18], [11, 27, 22], [11, 27, 25], [11, 27, 26], [11, 28, 1], [11, 28, 4], [11, 28, 6], [11, 28, 9], [11, 28, 10], [11, 28, 11], [11, 28, 17], [11, 28, 29], [11, 29, 1], [11, 29, 4], [11, 29, 6], [11, 29, 9], [11, 29, 11], [11, 29, 13], [11, 29, 17], [11, 29, 28], [11, 30, 2], [11, 30, 3], [11, 30, 14], [11, 30, 16], [11, 30, 20], [11, 30, 21], [11, 30, 22], [11, 30, 24], [12, 0, 12], [12, 1, 10], [12, 1, 12], [12, 1, 13], [12, 1, 14], [12, 1, 20], [12, 1, 23], [12, 1, 27], [12, 1, 28], [12, 2, 9], [12, 2, 15], [12, 2, 20], [12, 2, 23], [12, 2, 24], [12, 2, 25], [12, 2, 26], [12, 2, 28], [12, 3, 5], [12, 3, 7], [12, 3, 8], [12, 3, 11], [12, 3, 19], [12, 3, 22], [12, 3, 29], [12, 3, 30], [12, 4, 9], [12, 4, 15], [12, 4, 17], [12, 4, 18], [12, 4, 19], [12, 4, 21], [12, 4, 25], [12, 4, 30], [12, 5, 3], [12, 5, 7], [12, 5, 8], [12, 5, 11], [12, 5, 16], [12, 5, 19], [12, 5, 22], [12, 5, 29], [12, 6, 7], [12, 6, 10], [12, 6, 13], [12, 6, 14], [12, 6, 16], [12, 6, 22], [12, 6, 27], [12, 6, 29], [12, 7, 3], [12, 7, 5], [12, 7, 6], [12, 7, 8], [12, 7, 10], [12, 7, 16], [12, 7, 22], [12, 7, 29], [12, 8, 3], [12, 8, 5], [12, 8, 7], [12, 8, 11], [12, 8, 18], [12, 8, 19], [12, 8, 29], [12, 8, 30], [12, 9, 2], [12, 9, 4], [12, 9, 15], [12, 9, 21], [12, 9, 24], [12, 9, 25], [12, 9, 26], [12, 9, 28], [12, 10, 1], [12, 10, 6], [12, 10, 7], [12, 10, 13], [12, 10, 14], [12, 10, 16], [12, 10, 22], [12, 10, 27], [12, 11, 3], [12, 11, 5], [12, 11, 8], [12, 11, 17], [12, 11, 18], [12, 11, 19], [12, 11, 29], [12, 11, 30], [12, 12, 0], [12, 12, 1], [12, 12, 12], [12, 12, 13], [12, 12, 14], [12, 12, 20], [12, 12, 23], [12, 12, 26], [12, 12, 27], [12, 12, 28], [12, 13, 1], [12, 13, 6], [12, 13, 10], [12, 13, 12], [12, 13, 14], [12, 13, 20], [12, 13, 23], [12, 13, 27], [12, 14, 1], [12, 14, 6], [12, 14, 10], [12, 14, 12], [12, 14, 13], [12, 14, 16], [12, 14, 20], [12, 14, 27], [12, 15, 2], [12, 15, 4], [12, 15, 9], [12, 15, 17], [12, 15, 21], [12, 15, 24], [12, 15, 25], [12, 15, 26], [12, 16, 5], [12, 16, 6], [12, 16, 7], [12, 16, 10], [12, 16, 14], [12, 16, 22], [12, 16, 27], [12, 16, 29], [12, 17, 4], [12, 17, 11], [12, 17, 15], [12, 17, 18], [12, 17, 19], [12, 17, 21], [12, 17, 25], [12, 17, 30], [12, 18, 4], [12, 18, 8], [12, 18, 11], [12, 18, 17], [12, 18, 19], [12, 18, 21], [12, 18, 25], [12, 18, 30], [12, 19, 3], [12, 19, 4], [12, 19, 5], [12, 19, 8], [12, 19, 11], [12, 19, 17], [12, 19, 18], [12, 19, 30], [12, 20, 1], [12, 20, 2], [12, 20, 12], [12, 20, 13], [12, 20, 14], [12, 20, 23], [12, 20, 26], [12, 20, 28], [12, 21, 4], [12, 21, 9], [12, 21, 15], [12, 21, 17], [12, 21, 18], [12, 21, 24], [12, 21, 25], [12, 21, 30], [12, 22, 3], [12, 22, 5], [12, 22, 6], [12, 22, 7], [12, 22, 10], [12, 22, 16], [12, 22, 27], [12, 22, 29], [12, 23, 1], [12, 23, 2], [12, 23, 12], [12, 23, 13], [12, 23, 20], [12, 23, 24], [12, 23, 26], [12, 23, 28], [12, 24, 2], [12, 24, 9], [12, 24, 15], [12, 24, 21], [12, 24, 23], [12, 24, 25], [12, 24, 26], [12, 24, 28], [12, 25, 2], [12, 25, 4], [12, 25, 9], [12, 25, 15], [12, 25, 17], [12, 25, 18], [12, 25, 21], [12, 25, 24], [12, 26, 2], [12, 26, 9], [12, 26, 12], [12, 26, 15], [12, 26, 20], [12, 26, 23], [12, 26, 24], [12, 26, 28], [12, 27, 1], [12, 27, 6], [12, 27, 10], [12, 27, 12], [12, 27, 13], [12, 27, 14], [12, 27, 16], [12, 27, 22], [12, 28, 1], [12, 28, 2], [12, 28, 9], [12, 28, 12], [12, 28, 20], [12, 28, 23], [12, 28, 24], [12, 28, 26], [12, 29, 3], [12, 29, 5], [12, 29, 6], [12, 29, 7], [12, 29, 8], [12, 29, 11], [12, 29, 16], [12, 29, 22], [12, 30, 3], [12, 30, 4], [12, 30, 8], [12, 30, 11], [12, 30, 17], [12, 30, 18], [12, 30, 19], [12, 30, 21], [13, 0, 13], [13, 1, 10], [13, 1, 12], [13, 1, 13], [13, 1, 14], [13, 1, 20], [13, 1, 23], [13, 1, 27], [13, 1, 28], [13, 2, 9], [13, 2, 15], [13, 2, 20], [13, 2, 23], [13, 2, 24], [13, 2, 25], [13, 2, 26], [13, 2, 28], [13, 3, 5], [13, 3, 7], [13, 3, 8], [13, 3, 11], [13, 3, 19], [13, 3, 22], [13, 3, 29], [13, 3, 30], [13, 4, 9], [13, 4, 15], [13, 4, 17], [13, 4, 18], [13, 4, 19], [13, 4, 21], [13, 4, 25], [13, 4, 30], [13, 5, 3], [13, 5, 7], [13, 5, 8], [13, 5, 11], [13, 5, 16], [13, 5, 19], [13, 5, 22], [13, 5, 29], [13, 6, 7], [13, 6, 10], [13, 6, 13], [13, 6, 14], [13, 6, 16], [13, 6, 22], [13, 6, 27], [13, 6, 29], [13, 7, 3], [13, 7, 5], [13, 7, 6], [13, 7, 8], [13, 7, 10], [13, 7, 16], [13, 7, 22], [13, 7, 29], [13, 8, 3], [13, 8, 5], [13, 8, 7], [13, 8, 11], [13, 8, 18], [13, 8, 19], [13, 8, 29], [13, 8, 30], [13, 9, 2], [13, 9, 4], [13, 9, 15], [13, 9, 21], [13, 9, 24], [13, 9, 25], [13, 9, 26], [13, 9, 28], [13, 10, 1], [13, 10, 6], [13, 10, 7], [13, 10, 13], [13, 10, 14], [13, 10, 16], [13, 10, 22], [13, 10, 27], [13, 11, 3], [13, 11, 5], [13, 11, 8], [13, 11, 17], [13, 11, 18], [13, 11, 19], [13, 11, 29], [13, 11, 30], [13, 12, 1], [13, 12, 13], [13, 12, 14], [13, 12, 20], [13, 12, 23], [13, 12, 26], [13, 12, 27], [13, 12, 28], [13, 13, 0], [13, 13, 1], [13, 13, 6], [13, 13, 10], [13, 13, 12], [13, 13, 13], [13, 13, 14], [13, 13, 20], [13, 13, 23], [13, 13, 27], [13, 14, 1], [13, 14, 6], [13, 14, 10], [13, 14, 12], [13, 14, 13], [13, 14, 16], [13, 14, 20], [13, 14, 27], [13, 15, 2], [13, 15, 4], [13, 15, 9], [13, 15, 17], [13, 15, 21], [13, 15, 24], [13, 15, 25], [13, 15, 26], [13, 16, 5], [13, 16, 6], [13, 16, 7], [13, 16, 10], [13, 16, 14], [13, 16, 22], [13, 16, 27], [13, 16, 29], [13, 17, 4], [13, 17, 11], [13, 17, 15], [13, 17, 18], [13, 17, 19], [13, 17, 21], [13, 17, 25], [13, 17, 30], [13, 18, 4], [13, 18, 8], [13, 18, 11], [13, 18, 17], [13, 18, 19], [13, 18, 21], [13, 18, 25], [13, 18, 30], [13, 19, 3], [13, 19, 4], [13, 19, 5], [13, 19, 8], [13, 19, 11], [13, 19, 17], [13, 19, 18], [13, 19, 30], [13, 20, 1], [13, 20, 2], [13, 20, 12], [13, 20, 13], [13, 20, 14], [13, 20, 23], [13, 20, 26], [13, 20, 28], [13, 21, 4], [13, 21, 9], [13, 21, 15], [13, 21, 17], [13, 21, 18], [13, 21, 24], [13, 21, 25], [13, 21, 30], [13, 22, 3], [13, 22, 5], [13, 22, 6], [13, 22, 7], [13, 22, 10], [13, 22, 16], [13, 22, 27], [13, 22, 29], [13, 23, 1], [13, 23, 2], [13, 23, 12], [13, 23, 13], [13, 23, 20], [13, 23, 24], [13, 23, 26], [13, 23, 28], [13, 24, 2], [13, 24, 9], [13, 24, 15], [13, 24, 21], [13, 24, 23], [13, 24, 25], [13, 24, 26], [13, 24, 28], [13, 25, 2], [13, 25, 4], [13, 25, 9], [13, 25, 15], [13, 25, 17], [13, 25, 18], [13, 25, 21], [13, 25, 24], [13, 26, 2], [13, 26, 9], [13, 26, 12], [13, 26, 15], [13, 26, 20], [13, 26, 23], [13, 26, 24], [13, 26, 28], [13, 27, 1], [13, 27, 6], [13, 27, 10], [13, 27, 12], [13, 27, 13], [13, 27, 14], [13, 27, 16], [13, 27, 22], [13, 28, 1], [13, 28, 2], [13, 28, 9], [13, 28, 12], [13, 28, 20], [13, 28, 23], [13, 28, 24], [13, 28, 26], [13, 29, 3], [13, 29, 5], [13, 29, 6], [13, 29, 7], [13, 29, 8], [13, 29, 11], [13, 29, 16], [13, 29, 22], [13, 30, 3], [13, 30, 4], [13, 30, 8], [13, 30, 11], [13, 30, 17], [13, 30, 18], [13, 30, 19], [13, 30, 21], [14, 0, 14], [14, 1, 2], [14, 1, 7], [14, 1, 9], [14, 1, 10], [14, 1, 14], [14, 1, 16], [14, 1, 20], [14, 1, 28], [14, 2, 1], [14, 2, 4], [14, 2, 9], [14, 2, 14], [14, 2, 18], [14, 2, 20], [14, 2, 25], [14, 2, 28], [14, 4, 2], [14, 4, 5], [14, 4, 8], [14, 4, 9], [14, 4, 18], [14, 4, 19], [14, 4, 25], [14, 4, 28], [14, 5, 4], [14, 5, 7], [14, 5, 8], [14, 5, 10], [14, 5, 14], [14, 5, 16], [14, 5, 18], [14, 5, 19], [14, 7, 1], [14, 7, 5], [14, 7, 8], [14, 7, 10], [14, 7, 14], [14, 7, 16], [14, 7, 18], [14, 7, 19], [14, 8, 4], [14, 8, 5], [14, 8, 7], [14, 8, 10], [14, 8, 16], [14, 8, 18], [14, 8, 19], [14, 8, 25], [14, 9, 1], [14, 9, 2], [14, 9, 4], [14, 9, 18], [14, 9, 19], [14, 9, 20], [14, 9, 25], [14, 9, 28], [14, 10, 1], [14, 10, 5], [14, 10, 7], [14, 10, 8], [14, 10, 14], [14, 10, 16], [14, 10, 20], [14, 10, 28], [14, 14, 0], [14, 14, 1], [14, 14, 2], [14, 14, 5], [14, 14, 7], [14, 14, 10], [14, 14, 14], [14, 14, 16], [14, 14, 20], [14, 14, 28], [14, 16, 1], [14, 16, 5], [14, 16, 7], [14, 16, 8], [14, 16, 10], [14, 16, 14], [14, 16, 19], [14, 16, 20], [14, 18, 2], [14, 18, 4], [14, 18, 5], [14, 18, 7], [14, 18, 8], [14, 18, 9], [14, 18, 19], [14, 18, 25], [14, 19, 4], [14, 19, 5], [14, 19, 7], [14, 19, 8], [14, 19, 9], [14, 19, 16], [14, 19, 18], [14, 19, 25], [14, 20, 1], [14, 20, 2], [14, 20, 9], [14, 20, 10], [14, 20, 14], [14, 20, 16], [14, 20, 25], [14, 20, 28], [14, 25, 2], [14, 25, 4], [14, 25, 8], [14, 25, 9], [14, 25, 18], [14, 25, 19], [14, 25, 20], [14, 25, 28], [14, 28, 1], [14, 28, 2], [14, 28, 4], [14, 28, 9], [14, 28, 10], [14, 28, 14], [14, 28, 20], [14, 28, 25], [15, 0, 15], [15, 1, 2], [15, 1, 4], [15, 1, 8], [15, 1, 15], [15, 1, 16], [15, 1, 23], [15, 1, 27], [15, 1, 29], [15, 2, 1], [15, 2, 4], [15, 2, 8], [15, 2, 15], [15, 2, 16], [15, 2, 23], [15, 2, 27], [15, 2, 30], [15, 4, 1], [15, 4, 2], [15, 4, 8], [15, 4, 15], [15, 4, 16], [15, 4, 23], [15, 4, 29], [15, 4, 30], [15, 8, 1], [15, 8, 2], [15, 8, 4], [15, 8, 15], [15, 8, 16], [15, 8, 27], [15, 8, 29], [15, 8, 30], [15, 15, 0], [15, 15, 1], [15, 15, 2], [15, 15, 4], [15, 15, 8], [15, 15, 15], [15, 15, 23], [15, 15, 27], [15, 15, 29], [15, 15, 30], [15, 16, 1], [15, 16, 2], [15, 16, 4], [15, 16, 8], [15, 16, 23], [15, 16, 27], [15, 16, 29], [15, 16, 30], [15, 23, 1], [15, 23, 2], [15, 23, 4], [15, 23, 15], [15, 23, 16], [15, 23, 27], [15, 23, 29], [15, 23, 30], [15, 27, 1], [15, 27, 2], [15, 27, 8], [15, 27, 15], [15, 27, 16], [15, 27, 23], [15, 27, 29], [15, 27, 30], [15, 29, 1], [15, 29, 4], [15, 29, 8], [15, 29, 15], [15, 29, 16], [15, 29, 23], [15, 29, 27], [15, 29, 30], [15, 30, 2], [15, 30, 4], [15, 30, 8], [15, 30, 15], [15, 30, 16], [15, 30, 23], [15, 30, 27], [15, 30, 29], [16, 0, 16], [16, 1, 2], [16, 1, 4], [16, 1, 8], [16, 1, 16], [16, 2, 1], [16, 2, 4], [16, 2, 8], [16, 2, 16], [16, 4, 1], [16, 4, 2], [16, 4, 8], [16, 4, 16], [16, 8, 1], [16, 8, 2], [16, 8, 4], [16, 8, 16], [16, 16, 0], [16, 16, 1], [16, 16, 2], [16, 16, 4], [16, 16, 8], [16, 16, 16], [17, 0, 17], [17, 1, 7], [17, 1, 9], [17, 1, 10], [17, 1, 11], [17, 1, 15], [17, 1, 17], [17, 1, 28], [17, 1, 29], [17, 2, 3], [17, 2, 14], [17, 2, 18], [17, 2, 20], [17, 2, 22], [17, 2, 25], [17, 2, 27], [17, 2, 30], [17, 3, 2], [17, 3, 14], [17, 3, 20], [17, 3, 21], [17, 3, 22], [17, 3, 25], [17, 3, 27], [17, 3, 30], [17, 4, 5], [17, 4, 6], [17, 4, 9], [17, 4, 13], [17, 4, 19], [17, 4, 23], [17, 4, 28], [17, 4, 29], [17, 5, 4], [17, 5, 13], [17, 5, 14], [17, 5, 16], [17, 5, 19], [17, 5, 21], [17, 5, 23], [17, 5, 24], [17, 6, 4], [17, 6, 9], [17, 6, 11], [17, 6, 13], [17, 6, 19], [17, 6, 23], [17, 6, 28], [17, 6, 29], [17, 7, 1], [17, 7, 8], [17, 7, 10], [17, 7, 12], [17, 7, 15], [17, 7, 17], [17, 7, 18], [17, 7, 26], [17, 8, 7], [17, 8, 10], [17, 8, 12], [17, 8, 15], [17, 8, 18], [17, 8, 25], [17, 8, 26], [17, 8, 27], [17, 9, 1], [17, 9, 4], [17, 9, 6], [17, 9, 11], [17, 9, 13], [17, 9, 19], [17, 9, 28], [17, 9, 29], [17, 10, 1], [17, 10, 7], [17, 10, 8], [17, 10, 11], [17, 10, 15], [17, 10, 17], [17, 10, 26], [17, 10, 28], [17, 11, 1], [17, 11, 6], [17, 11, 9], [17, 11, 10], [17, 11, 15], [17, 11, 17], [17, 11, 28], [17, 11, 29], [17, 12, 7], [17, 12, 8], [17, 12, 15], [17, 12, 18], [17, 12, 22], [17, 12, 25], [17, 12, 26], [17, 12, 27], [17, 13, 4], [17, 13, 5], [17, 13, 6], [17, 13, 9], [17, 13, 19], [17, 13, 23], [17, 13, 24], [17, 13, 29], [17, 14, 2], [17, 14, 3], [17, 14, 5], [17, 14, 16], [17, 14, 20], [17, 14, 21], [17, 14, 24], [17, 14, 30], [17, 15, 1], [17, 15, 7], [17, 15, 8], [17, 15, 10], [17, 15, 11], [17, 15, 12], [17, 15, 17], [17, 15, 26], [17, 16, 5], [17, 16, 14], [17, 16, 19], [17, 16, 20], [17, 16, 21], [17, 16, 23], [17, 16, 24], [17, 16, 30], [17, 17, 0], [17, 17, 1], [17, 17, 7], [17, 17, 10], [17, 17, 11], [17, 17, 15], [17, 17, 17], [17, 17, 26], [17, 17, 28], [17, 17, 29], [17, 18, 2], [17, 18, 7], [17, 18, 8], [17, 18, 12], [17, 18, 22], [17, 18, 25], [17, 18, 26], [17, 18, 27], [17, 19, 4], [17, 19, 5], [17, 19, 6], [17, 19, 9], [17, 19, 13], [17, 19, 16], [17, 19, 23], [17, 19, 24], [17, 20, 2], [17, 20, 3], [17, 20, 14], [17, 20, 16], [17, 20, 21], [17, 20, 22], [17, 20, 25], [17, 20, 30], [17, 21, 3], [17, 21, 5], [17, 21, 14], [17, 21, 16], [17, 21, 20], [17, 21, 23], [17, 21, 24], [17, 21, 30], [17, 22, 2], [17, 22, 3], [17, 22, 12], [17, 22, 18], [17, 22, 20], [17, 22, 25], [17, 22, 27], [17, 22, 30], [17, 23, 4], [17, 23, 5], [17, 23, 6], [17, 23, 13], [17, 23, 16], [17, 23, 19], [17, 23, 21], [17, 23, 24], [17, 24, 5], [17, 24, 13], [17, 24, 14], [17, 24, 16], [17, 24, 19], [17, 24, 21], [17, 24, 23], [17, 24, 30], [17, 25, 2], [17, 25, 3], [17, 25, 8], [17, 25, 12], [17, 25, 18], [17, 25, 20], [17, 25, 22], [17, 25, 27], [17, 26, 7], [17, 26, 8], [17, 26, 10], [17, 26, 12], [17, 26, 15], [17, 26, 17], [17, 26, 18], [17, 26, 27], [17, 27, 2], [17, 27, 3], [17, 27, 8], [17, 27, 12], [17, 27, 18], [17, 27, 22], [17, 27, 25], [17, 27, 26], [17, 28, 1], [17, 28, 4], [17, 28, 6], [17, 28, 9], [17, 28, 10], [17, 28, 11], [17, 28, 17], [17, 28, 29], [17, 29, 1], [17, 29, 4], [17, 29, 6], [17, 29, 9], [17, 29, 11], [17, 29, 13], [17, 29, 17], [17, 29, 28], [17, 30, 2], [17, 30, 3], [17, 30, 14], [17, 30, 16], [17, 30, 20], [17, 30, 21], [17, 30, 22], [17, 30, 24], [18, 0, 18], [18, 1, 4], [18, 1, 8], [18, 1, 10], [18, 1, 14], [18, 1, 18], [18, 1, 19], [18, 1, 20], [18, 1, 28], [18, 2, 5], [18, 2, 7], [18, 2, 8], [18, 2, 9], [18, 2, 16], [18, 2, 20], [18, 2, 25], [18, 2, 28], [18, 4, 1], [18, 4, 9], [18, 4, 10], [18, 4, 14], [18, 4, 16], [18, 4, 18], [18, 4, 19], [18, 4, 25], [18, 5, 2], [18, 5, 7], [18, 5, 8], [18, 5, 9], [18, 5, 16], [18, 5, 19], [18, 5, 20], [18, 5, 28], [18, 7, 2], [18, 7, 5], [18, 7, 8], [18, 7, 9], [18, 7, 10], [18, 7, 16], [18, 7, 25], [18, 7, 28], [18, 8, 1], [18, 8, 2], [18, 8, 5], [18, 8, 7], [18, 8, 18], [18, 8, 19], [18, 8, 20], [18, 8, 28], [18, 9, 2], [18, 9, 4], [18, 9, 5], [18, 9, 7], [18, 9, 10], [18, 9, 16], [18, 9, 25], [18, 9, 28], [18, 10, 1], [18, 10, 4], [18, 10, 7], [18, 10, 9], [18, 10, 14], [18, 10, 16], [18, 10, 18], [18, 10, 25], [18, 14, 1], [18, 14, 4], [18, 14, 10], [18, 14, 16], [18, 14, 18], [18, 14, 19], [18, 14, 20], [18, 14, 25], [18, 16, 2], [18, 16, 4], [18, 16, 5], [18, 16, 7], [18, 16, 9], [18, 16, 10], [18, 16, 14], [18, 16, 25], [18, 18, 0], [18, 18, 1], [18, 18, 4], [18, 18, 8], [18, 18, 10], [18, 18, 14], [18, 18, 18], [18, 18, 19], [18, 18, 20], [18, 18, 25], [18, 19, 1], [18, 19, 4], [18, 19, 5], [18, 19, 8], [18, 19, 14], [18, 19, 18], [18, 19, 20], [18, 19, 28], [18, 20, 1], [18, 20, 2], [18, 20, 5], [18, 20, 8], [18, 20, 14], [18, 20, 18], [18, 20, 19], [18, 20, 28], [18, 25, 2], [18, 25, 4], [18, 25, 7], [18, 25, 9], [18, 25, 10], [18, 25, 14], [18, 25, 16], [18, 25, 18], [18, 28, 1], [18, 28, 2], [18, 28, 5], [18, 28, 7], [18, 28, 8], [18, 28, 9], [18, 28, 19], [18, 28, 20], [19, 0, 19], [19, 1, 4], [19, 1, 8], [19, 1, 10], [19, 1, 14], [19, 1, 18], [19, 1, 19], [19, 1, 20], [19, 1, 28], [19, 2, 5], [19, 2, 7], [19, 2, 8], [19, 2, 9], [19, 2, 16], [19, 2, 20], [19, 2, 25], [19, 2, 28], [19, 4, 1], [19, 4, 9], [19, 4, 10], [19, 4, 14], [19, 4, 16], [19, 4, 18], [19, 4, 19], [19, 4, 25], [19, 5, 2], [19, 5, 7], [19, 5, 8], [19, 5, 9], [19, 5, 16], [19, 5, 19], [19, 5, 20], [19, 5, 28], [19, 7, 2], [19, 7, 5], [19, 7, 8], [19, 7, 9], [19, 7, 10], [19, 7, 16], [19, 7, 25], [19, 7, 28], [19, 8, 1], [19, 8, 2], [19, 8, 5], [19, 8, 7], [19, 8, 18], [19, 8, 19], [19, 8, 20], [19, 8, 28], [19, 9, 2], [19, 9, 4], [19, 9, 5], [19, 9, 7], [19, 9, 10], [19, 9, 16], [19, 9, 25], [19, 9, 28], [19, 10, 1], [19, 10, 4], [19, 10, 7], [19, 10, 9], [19, 10, 14], [19, 10, 16], [19, 10, 18], [19, 10, 25], [19, 14, 1], [19, 14, 4], [19, 14, 10], [19, 14, 16], [19, 14, 18], [19, 14, 19], [19, 14, 20], [19, 14, 25], [19, 16, 2], [19, 16, 4], [19, 16, 5], [19, 16, 7], [19, 16, 9], [19, 16, 10], [19, 16, 14], [19, 16, 25], [19, 18, 1], [19, 18, 4], [19, 18, 8], [19, 18, 10], [19, 18, 14], [19, 18, 19], [19, 18, 20], [19, 18, 25], [19, 19, 0], [19, 19, 1], [19, 19, 4], [19, 19, 5], [19, 19, 8], [19, 19, 14], [19, 19, 18], [19, 19, 19], [19, 19, 20], [19, 19, 28], [19, 20, 1], [19, 20, 2], [19, 20, 5], [19, 20, 8], [19, 20, 14], [19, 20, 18], [19, 20, 19], [19, 20, 28], [19, 25, 2], [19, 25, 4], [19, 25, 7], [19, 25, 9], [19, 25, 10], [19, 25, 14], [19, 25, 16], [19, 25, 18], [19, 28, 1], [19, 28, 2], [19, 28, 5], [19, 28, 7], [19, 28, 8], [19, 28, 9], [19, 28, 19], [19, 28, 20], [20, 0, 20], [20, 1, 2], [20, 1, 7], [20, 1, 9], [20, 1, 10], [20, 1, 14], [20, 1, 16], [20, 1, 20], [20, 1, 28], [20, 2, 1], [20, 2, 4], [20, 2, 9], [20, 2, 14], [20, 2, 18], [20, 2, 20], [20, 2, 25], [20, 2, 28], [20, 4, 2], [20, 4, 5], [20, 4, 8], [20, 4, 9], [20, 4, 18], [20, 4, 19], [20, 4, 25], [20, 4, 28], [20, 5, 4], [20, 5, 7], [20, 5, 8], [20, 5, 10], [20, 5, 14], [20, 5, 16], [20, 5, 18], [20, 5, 19], [20, 7, 1], [20, 7, 5], [20, 7, 8], [20, 7, 10], [20, 7, 14], [20, 7, 16], [20, 7, 18], [20, 7, 19], [20, 8, 4], [20, 8, 5], [20, 8, 7], [20, 8, 10], [20, 8, 16], [20, 8, 18], [20, 8, 19], [20, 8, 25], [20, 9, 1], [20, 9, 2], [20, 9, 4], [20, 9, 18], [20, 9, 19], [20, 9, 20], [20, 9, 25], [20, 9, 28], [20, 10, 1], [20, 10, 5], [20, 10, 7], [20, 10, 8], [20, 10, 14], [20, 10, 16], [20, 10, 20], [20, 10, 28], [20, 14, 1], [20, 14, 2], [20, 14, 5], [20, 14, 7], [20, 14, 10], [20, 14, 16], [20, 14, 20], [20, 14, 28], [20, 16, 1], [20, 16, 5], [20, 16, 7], [20, 16, 8], [20, 16, 10], [20, 16, 14], [20, 16, 19], [20, 16, 20], [20, 18, 2], [20, 18, 4], [20, 18, 5], [20, 18, 7], [20, 18, 8], [20, 18, 9], [20, 18, 19], [20, 18, 25], [20, 19, 4], [20, 19, 5], [20, 19, 7], [20, 19, 8], [20, 19, 9], [20, 19, 16], [20, 19, 18], [20, 19, 25], [20, 20, 0], [20, 20, 1], [20, 20, 2], [20, 20, 9], [20, 20, 10], [20, 20, 14], [20, 20, 16], [20, 20, 20], [20, 20, 25], [20, 20, 28], [20, 25, 2], [20, 25, 4], [20, 25, 8], [20, 25, 9], [20, 25, 18], [20, 25, 19], [20, 25, 20], [20, 25, 28], [20, 28, 1], [20, 28, 2], [20, 28, 4], [20, 28, 9], [20, 28, 10], [20, 28, 14], [20, 28, 20], [20, 28, 25], [21, 0, 21], [21, 1, 3], [21, 1, 7], [21, 1, 9], [21, 1, 18], [21, 1, 19], [21, 1, 21], [21, 1, 23], [21, 1, 27], [21, 2, 5], [21, 2, 6], [21, 2, 7], [21, 2, 11], [21, 2, 14], [21, 2, 15], [21, 2, 18], [21, 2, 23], [21, 3, 1], [21, 3, 7], [21, 3, 9], [21, 3, 19], [21, 3, 21], [21, 3, 23], [21, 3, 26], [21, 3, 27], [21, 4, 5], [21, 4, 10], [21, 4, 12], [21, 4, 14], [21, 4, 15], [21, 4, 22], [21, 4, 28], [21, 4, 30], [21, 5, 2], [21, 5, 4], [21, 5, 11], [21, 5, 12], [21, 5, 14], [21, 5, 15], [21, 5, 22], [21, 5, 28], [21, 6, 2], [21, 6, 7], [21, 6, 11], [21, 6, 14], [21, 6, 15], [21, 6, 18], [21, 6, 21], [21, 6, 23], [21, 7, 1], [21, 7, 2], [21, 7, 3], [21, 7, 6], [21, 7, 9], [21, 7, 18], [21, 7, 21], [21, 7, 23], [21, 8, 10], [21, 8, 13], [21, 8, 20], [21, 8, 24], [21, 8, 25], [21, 8, 28], [21, 8, 29], [21, 8, 30], [21, 9, 1], [21, 9, 3], [21, 9, 7], [21, 9, 16], [21, 9, 19], [21, 9, 21], [21, 9, 26], [21, 9, 27], [21, 10, 4], [21, 10, 8], [21, 10, 13], [21, 10, 22], [21, 10, 24], [21, 10, 25], [21, 10, 28], [21, 10, 30], [21, 11, 2], [21, 11, 5], [21, 11, 6], [21, 11, 12], [21, 11, 14], [21, 11, 15], [21, 11, 18], [21, 11, 23], [21, 12, 4], [21, 12, 5], [21, 12, 11], [21, 12, 14], [21, 12, 15], [21, 12, 22], [21, 12, 28], [21, 12, 30], [21, 13, 8], [21, 13, 10], [21, 13, 17], [21, 13, 20], [21, 13, 24], [21, 13, 25], [21, 13, 29], [21, 13, 30], [21, 14, 2], [21, 14, 4], [21, 14, 5], [21, 14, 6], [21, 14, 11], [21, 14, 12], [21, 14, 15], [21, 14, 18], [21, 15, 2], [21, 15, 4], [21, 15, 5], [21, 15, 6], [21, 15, 11], [21, 15, 12], [21, 15, 14], [21, 15, 22], [21, 16, 9], [21, 16, 17], [21, 16, 19], [21, 16, 20], [21, 16, 25], [21, 16, 26], [21, 16, 27], [21, 16, 29], [21, 17, 13], [21, 17, 16], [21, 17, 19], [21, 17, 20], [21, 17, 25], [21, 17, 26], [21, 17, 27], [21, 17, 29], [21, 18, 1], [21, 18, 2], [21, 18, 6], [21, 18, 7], [21, 18, 11], [21, 18, 14], [21, 18, 21], [21, 18, 23], [21, 19, 1], [21, 19, 3], [21, 19, 9], [21, 19, 16], [21, 19, 17], [21, 19, 20], [21, 19, 26], [21, 19, 27], [21, 20, 8], [21, 20, 13], [21, 20, 16], [21, 20, 17], [21, 20, 19], [21, 20, 25], [21, 20, 26], [21, 20, 29], [21, 21, 0], [21, 21, 1], [21, 21, 3], [21, 21, 6], [21, 21, 7], [21, 21, 9], [21, 21, 18], [21, 21, 21], [21, 21, 23], [21, 21, 27], [21, 22, 4], [21, 22, 5], [21, 22, 10], [21, 22, 12], [21, 22, 15], [21, 22, 24], [21, 22, 28], [21, 22, 30], [21, 23, 1], [21, 23, 2], [21, 23, 3], [21, 23, 6], [21, 23, 7], [21, 23, 11], [21, 23, 18], [21, 23, 21], [21, 24, 8], [21, 24, 10], [21, 24, 13], [21, 24, 22], [21, 24, 25], [21, 24, 28], [21, 24, 29], [21, 24, 30], [21, 25, 8], [21, 25, 10], [21, 25, 13], [21, 25, 16], [21, 25, 17], [21, 25, 20], [21, 25, 24], [21, 25, 29], [21, 26, 3], [21, 26, 9], [21, 26, 16], [21, 26, 17], [21, 26, 19], [21, 26, 20], [21, 26, 27], [21, 26, 29], [21, 27, 1], [21, 27, 3], [21, 27, 9], [21, 27, 16], [21, 27, 17], [21, 27, 19], [21, 27, 21], [21, 27, 26], [21, 28, 4], [21, 28, 5], [21, 28, 8], [21, 28, 10], [21, 28, 12], [21, 28, 22], [21, 28, 24], [21, 28, 30], [21, 29, 8], [21, 29, 13], [21, 29, 16], [21, 29, 17], [21, 29, 20], [21, 29, 24], [21, 29, 25], [21, 29, 26], [21, 30, 4], [21, 30, 8], [21, 30, 10], [21, 30, 12], [21, 30, 13], [21, 30, 22], [21, 30, 24], [21, 30, 28], [22, 0, 22], [22, 1, 14], [22, 1, 15], [22, 1, 18], [22, 1, 19], [22, 1, 20], [22, 1, 22], [22, 1, 24], [22, 1, 29], [22, 2, 5], [22, 2, 7], [22, 2, 9], [22, 2, 13], [22, 2, 17], [22, 2, 27], [22, 2, 28], [22, 2, 30], [22, 3, 4], [22, 3, 10], [22, 3, 11], [22, 3, 14], [22, 3, 23], [22, 3, 25], [22, 3, 26], [22, 3, 29], [22, 4, 3], [22, 4, 10], [22, 4, 14], [22, 4, 18], [22, 4, 23], [22, 4, 25], [22, 4, 26], [22, 4, 29], [22, 5, 2], [22, 5, 7], [22, 5, 8], [22, 5, 13], [22, 5, 17], [22, 5, 21], [22, 5, 27], [22, 5, 28], [22, 6, 8], [22, 6, 15], [22, 6, 19], [22, 6, 20], [22, 6, 21], [22, 6, 22], [22, 6, 27], [22, 6, 28], [22, 7, 2], [22, 7, 5], [22, 7, 9], [22, 7, 12], [22, 7, 13], [22, 7, 16], [22, 7, 17], [22, 7, 30], [22, 8, 5], [22, 8, 6], [22, 8, 15], [22, 8, 19], [22, 8, 20], [22, 8, 21], [22, 8, 27], [22, 8, 28], [22, 9, 2], [22, 9, 7], [22, 9, 11], [22, 9, 12], [22, 9, 13], [22, 9, 16], [22, 9, 25], [22, 9, 30], [22, 10, 3], [22, 10, 4], [22, 10, 11], [22, 10, 14], [22, 10, 16], [22, 10, 23], [22, 10, 25], [22, 10, 26], [22, 11, 3], [22, 11, 9], [22, 11, 10], [22, 11, 12], [22, 11, 16], [22, 11, 23], [22, 11, 25], [22, 11, 30], [22, 12, 7], [22, 12, 9], [22, 12, 11], [22, 12, 13], [22, 12, 16], [22, 12, 23], [22, 12, 25], [22, 12, 30], [22, 13, 2], [22, 13, 5], [22, 13, 7], [22, 13, 9], [22, 13, 12], [22, 13, 17], [22, 13, 27], [22, 13, 30], [22, 14, 1], [22, 14, 3], [22, 14, 4], [22, 14, 10], [22, 14, 18], [22, 14, 24], [22, 14, 26], [22, 14, 29], [22, 15, 1], [22, 15, 6], [22, 15, 8], [22, 15, 19], [22, 15, 20], [22, 15, 21], [22, 15, 22], [22, 15, 24], [22, 16, 7], [22, 16, 9], [22, 16, 10], [22, 16, 11], [22, 16, 12], [22, 16, 23], [22, 16, 25], [22, 16, 30], [22, 17, 2], [22, 17, 5], [22, 17, 7], [22, 17, 13], [22, 17, 21], [22, 17, 27], [22, 17, 28], [22, 17, 30], [22, 18, 1], [22, 18, 4], [22, 18, 14], [22, 18, 19], [22, 18, 22], [22, 18, 24], [22, 18, 26], [22, 18, 29], [22, 19, 1], [22, 19, 6], [22, 19, 8], [22, 19, 15], [22, 19, 18], [22, 19, 20], [22, 19, 22], [22, 19, 24], [22, 20, 1], [22, 20, 6], [22, 20, 8], [22, 20, 15], [22, 20, 19], [22, 20, 21], [22, 20, 22], [22, 20, 28], [22, 21, 5], [22, 21, 6], [22, 21, 8], [22, 21, 15], [22, 21, 17], [22, 21, 20], [22, 21, 27], [22, 21, 28], [22, 22, 0], [22, 22, 1], [22, 22, 6], [22, 22, 15], [22, 22, 18], [22, 22, 19], [22, 22, 20], [22, 22, 22], [22, 22, 24], [22, 22, 29], [22, 23, 3], [22, 23, 4], [22, 23, 10], [22, 23, 11], [22, 23, 12], [22, 23, 16], [22, 23, 25], [22, 23, 26], [22, 24, 1], [22, 24, 14], [22, 24, 15], [22, 24, 18], [22, 24, 19], [22, 24, 22], [22, 24, 26], [22, 24, 29], [22, 25, 3], [22, 25, 4], [22, 25, 9], [22, 25, 10], [22, 25, 11], [22, 25, 12], [22, 25, 16], [22, 25, 23], [22, 26, 3], [22, 26, 4], [22, 26, 10], [22, 26, 14], [22, 26, 18], [22, 26, 23], [22, 26, 24], [22, 26, 29], [22, 27, 2], [22, 27, 5], [22, 27, 6], [22, 27, 8], [22, 27, 13], [22, 27, 17], [22, 27, 21], [22, 27, 28], [22, 28, 2], [22, 28, 5], [22, 28, 6], [22, 28, 8], [22, 28, 17], [22, 28, 20], [22, 28, 21], [22, 28, 27], [22, 29, 1], [22, 29, 3], [22, 29, 4], [22, 29, 14], [22, 29, 18], [22, 29, 22], [22, 29, 24], [22, 29, 26], [22, 30, 2], [22, 30, 7], [22, 30, 9], [22, 30, 11], [22, 30, 12], [22, 30, 13], [22, 30, 16], [22, 30, 17], [23, 0, 23], [23, 1, 2], [23, 1, 4], [23, 1, 8], [23, 1, 15], [23, 1, 16], [23, 1, 23], [23, 1, 27], [23, 1, 29], [23, 2, 1], [23, 2, 4], [23, 2, 8], [23, 2, 15], [23, 2, 16], [23, 2, 23], [23, 2, 27], [23, 2, 30], [23, 4, 1], [23, 4, 2], [23, 4, 8], [23, 4, 15], [23, 4, 16], [23, 4, 23], [23, 4, 29], [23, 4, 30], [23, 8, 1], [23, 8, 2], [23, 8, 4], [23, 8, 15], [23, 8, 16], [23, 8, 27], [23, 8, 29], [23, 8, 30], [23, 15, 1], [23, 15, 2], [23, 15, 4], [23, 15, 8], [23, 15, 23], [23, 15, 27], [23, 15, 29], [23, 15, 30], [23, 16, 1], [23, 16, 2], [23, 16, 4], [23, 16, 8], [23, 16, 23], [23, 16, 27], [23, 16, 29], [23, 16, 30], [23, 23, 0], [23, 23, 1], [23, 23, 2], [23, 23, 4], [23, 23, 15], [23, 23, 16], [23, 23, 23], [23, 23, 27], [23, 23, 29], [23, 23, 30], [23, 27, 1], [23, 27, 2], [23, 27, 8], [23, 27, 15], [23, 27, 16], [23, 27, 23], [23, 27, 29], [23, 27, 30], [23, 29, 1], [23, 29, 4], [23, 29, 8], [23, 29, 15], [23, 29, 16], [23, 29, 23], [23, 29, 27], [23, 29, 30], [23, 30, 2], [23, 30, 4], [23, 30, 8], [23, 30, 15], [23, 30, 16], [23, 30, 23], [23, 30, 27], [23, 30, 29], [24, 0, 24], [24, 1, 14], [24, 1, 15], [24, 1, 18], [24, 1, 19], [24, 1, 20], [24, 1, 22], [24, 1, 24], [24, 1, 29], [24, 2, 5], [24, 2, 7], [24, 2, 9], [24, 2, 13], [24, 2, 17], [24, 2, 27], [24, 2, 28], [24, 2, 30], [24, 3, 4], [24, 3, 10], [24, 3, 11], [24, 3, 14], [24, 3, 23], [24, 3, 25], [24, 3, 26], [24, 3, 29], [24, 4, 3], [24, 4, 10], [24, 4, 14], [24, 4, 18], [24, 4, 23], [24, 4, 25], [24, 4, 26], [24, 4, 29], [24, 5, 2], [24, 5, 7], [24, 5, 8], [24, 5, 13], [24, 5, 17], [24, 5, 21], [24, 5, 27], [24, 5, 28], [24, 6, 8], [24, 6, 15], [24, 6, 19], [24, 6, 20], [24, 6, 21], [24, 6, 22], [24, 6, 27], [24, 6, 28], [24, 7, 2], [24, 7, 5], [24, 7, 9], [24, 7, 12], [24, 7, 13], [24, 7, 16], [24, 7, 17], [24, 7, 30], [24, 8, 5], [24, 8, 6], [24, 8, 15], [24, 8, 19], [24, 8, 20], [24, 8, 21], [24, 8, 27], [24, 8, 28], [24, 9, 2], [24, 9, 7], [24, 9, 11], [24, 9, 12], [24, 9, 13], [24, 9, 16], [24, 9, 25], [24, 9, 30], [24, 10, 3], [24, 10, 4], [24, 10, 11], [24, 10, 14], [24, 10, 16], [24, 10, 23], [24, 10, 25], [24, 10, 26], [24, 11, 3], [24, 11, 9], [24, 11, 10], [24, 11, 12], [24, 11, 16], [24, 11, 23], [24, 11, 25], [24, 11, 30], [24, 12, 7], [24, 12, 9], [24, 12, 11], [24, 12, 13], [24, 12, 16], [24, 12, 23], [24, 12, 25], [24, 12, 30], [24, 13, 2], [24, 13, 5], [24, 13, 7], [24, 13, 9], [24, 13, 12], [24, 13, 17], [24, 13, 27], [24, 13, 30], [24, 14, 1], [24, 14, 3], [24, 14, 4], [24, 14, 10], [24, 14, 18], [24, 14, 24], [24, 14, 26], [24, 14, 29], [24, 15, 1], [24, 15, 6], [24, 15, 8], [24, 15, 19], [24, 15, 20], [24, 15, 21], [24, 15, 22], [24, 15, 24], [24, 16, 7], [24, 16, 9], [24, 16, 10], [24, 16, 11], [24, 16, 12], [24, 16, 23], [24, 16, 25], [24, 16, 30], [24, 17, 2], [24, 17, 5], [24, 17, 7], [24, 17, 13], [24, 17, 21], [24, 17, 27], [24, 17, 28], [24, 17, 30], [24, 18, 1], [24, 18, 4], [24, 18, 14], [24, 18, 19], [24, 18, 22], [24, 18, 24], [24, 18, 26], [24, 18, 29], [24, 19, 1], [24, 19, 6], [24, 19, 8], [24, 19, 15], [24, 19, 18], [24, 19, 20], [24, 19, 22], [24, 19, 24], [24, 20, 1], [24, 20, 6], [24, 20, 8], [24, 20, 15], [24, 20, 19], [24, 20, 21], [24, 20, 22], [24, 20, 28], [24, 21, 5], [24, 21, 6], [24, 21, 8], [24, 21, 15], [24, 21, 17], [24, 21, 20], [24, 21, 27], [24, 21, 28], [24, 22, 1], [24, 22, 6], [24, 22, 15], [24, 22, 18], [24, 22, 19], [24, 22, 20], [24, 22, 24], [24, 22, 29], [24, 23, 3], [24, 23, 4], [24, 23, 10], [24, 23, 11], [24, 23, 12], [24, 23, 16], [24, 23, 25], [24, 23, 26], [24, 24, 0], [24, 24, 1], [24, 24, 14], [24, 24, 15], [24, 24, 18], [24, 24, 19], [24, 24, 22], [24, 24, 24], [24, 24, 26], [24, 24, 29], [24, 25, 3], [24, 25, 4], [24, 25, 9], [24, 25, 10], [24, 25, 11], [24, 25, 12], [24, 25, 16], [24, 25, 23], [24, 26, 3], [24, 26, 4], [24, 26, 10], [24, 26, 14], [24, 26, 18], [24, 26, 23], [24, 26, 24], [24, 26, 29], [24, 27, 2], [24, 27, 5], [24, 27, 6], [24, 27, 8], [24, 27, 13], [24, 27, 17], [24, 27, 21], [24, 27, 28], [24, 28, 2], [24, 28, 5], [24, 28, 6], [24, 28, 8], [24, 28, 17], [24, 28, 20], [24, 28, 21], [24, 28, 27], [24, 29, 1], [24, 29, 3], [24, 29, 4], [24, 29, 14], [24, 29, 18], [24, 29, 22], [24, 29, 24], [24, 29, 26], [24, 30, 2], [24, 30, 7], [24, 30, 9], [24, 30, 11], [24, 30, 12], [24, 30, 13], [24, 30, 16], [24, 30, 17], [25, 0, 25], [25, 1, 1], [25, 1, 5], [25, 1, 25], [25, 5, 1], [25, 5, 5], [25, 5, 25], [25, 25, 0], [25, 25, 1], [25, 25, 5], [25, 25, 25], [26, 0, 26], [26, 1, 5], [26, 1, 6], [26, 1, 25], [26, 1, 26], [26, 1, 30], [26, 5, 1], [26, 5, 6], [26, 5, 25], [26, 5, 26], [26, 5, 30], [26, 6, 1], [26, 6, 5], [26, 6, 25], [26, 6, 26], [26, 6, 30], [26, 25, 1], [26, 25, 5], [26, 25, 6], [26, 25, 26], [26, 25, 30], [26, 26, 0], [26, 26, 1], [26, 26, 5], [26, 26, 6], [26, 26, 25], [26, 26, 26], [26, 26, 30], [26, 30, 1], [26, 30, 5], [26, 30, 6], [26, 30, 25], [26, 30, 26], [27, 0, 27], [27, 1, 2], [27, 1, 4], [27, 1, 8], [27, 1, 15], [27, 1, 16], [27, 1, 23], [27, 1, 27], [27, 1, 29], [27, 2, 1], [27, 2, 4], [27, 2, 8], [27, 2, 15], [27, 2, 16], [27, 2, 23], [27, 2, 27], [27, 2, 30], [27, 4, 1], [27, 4, 2], [27, 4, 8], [27, 4, 15], [27, 4, 16], [27, 4, 23], [27, 4, 29], [27, 4, 30], [27, 8, 1], [27, 8, 2], [27, 8, 4], [27, 8, 15], [27, 8, 16], [27, 8, 27], [27, 8, 29], [27, 8, 30], [27, 15, 1], [27, 15, 2], [27, 15, 4], [27, 15, 8], [27, 15, 23], [27, 15, 27], [27, 15, 29], [27, 15, 30], [27, 16, 1], [27, 16, 2], [27, 16, 4], [27, 16, 8], [27, 16, 23], [27, 16, 27], [27, 16, 29], [27, 16, 30], [27, 23, 1], [27, 23, 2], [27, 23, 4], [27, 23, 15], [27, 23, 16], [27, 23, 27], [27, 23, 29], [27, 23, 30], [27, 27, 0], [27, 27, 1], [27, 27, 2], [27, 27, 8], [27, 27, 15], [27, 27, 16], [27, 27, 23], [27, 27, 27], [27, 27, 29], [27, 27, 30], [27, 29, 1], [27, 29, 4], [27, 29, 8], [27, 29, 15], [27, 29, 16], [27, 29, 23], [27, 29, 27], [27, 29, 30], [27, 30, 2], [27, 30, 4], [27, 30, 8], [27, 30, 15], [27, 30, 16], [27, 30, 23], [27, 30, 27], [27, 30, 29], [28, 0, 28], [28, 1, 4], [28, 1, 7], [28, 1, 8], [28, 1, 9], [28, 1, 10], [28, 1, 18], [28, 1, 19], [28, 1, 28], [28, 2, 5], [28, 2, 7], [28, 2, 8], [28, 2, 14], [28, 2, 16], [28, 2, 18], [28, 2, 20], [28, 2, 25], [28, 4, 1], [28, 4, 5], [28, 4, 9], [28, 4, 10], [28, 4, 14], [28, 4, 16], [28, 4, 19], [28, 4, 28], [28, 5, 2], [28, 5, 4], [28, 5, 9], [28, 5, 14], [28, 5, 16], [28, 5, 19], [28, 5, 20], [28, 5, 28], [28, 7, 1], [28, 7, 2], [28, 7, 8], [28, 7, 9], [28, 7, 10], [28, 7, 18], [28, 7, 25], [28, 7, 28], [28, 8, 1], [28, 8, 2], [28, 8, 7], [28, 8, 10], [28, 8, 18], [28, 8, 20], [28, 8, 25], [28, 8, 28], [28, 9, 1], [28, 9, 4], [28, 9, 5], [28, 9, 7], [28, 9, 10], [28, 9, 16], [28, 9, 19], [28, 9, 28], [28, 10, 1], [28, 10, 4], [28, 10, 7], [28, 10, 8], [28, 10, 9], [28, 10, 18], [28, 10, 25], [28, 10, 28], [28, 14, 2], [28, 14, 4], [28, 14, 5], [28, 14, 16], [28, 14, 18], [28, 14, 19], [28, 14, 20], [28, 14, 25], [28, 16, 2], [28, 16, 4], [28, 16, 5], [28, 16, 9], [28, 16, 14], [28, 16, 19], [28, 16, 20], [28, 16, 25], [28, 18, 1], [28, 18, 2], [28, 18, 7], [28, 18, 8], [28, 18, 10], [28, 18, 14], [28, 18, 20], [28, 18, 25], [28, 19, 1], [28, 19, 4], [28, 19, 5], [28, 19, 9], [28, 19, 14], [28, 19, 16], [28, 19, 20], [28, 19, 28], [28, 20, 2], [28, 20, 5], [28, 20, 8], [28, 20, 14], [28, 20, 16], [28, 20, 18], [28, 20, 19], [28, 20, 25], [28, 25, 2], [28, 25, 7], [28, 25, 8], [28, 25, 10], [28, 25, 14], [28, 25, 16], [28, 25, 18], [28, 25, 20], [28, 28, 0], [28, 28, 1], [28, 28, 4], [28, 28, 5], [28, 28, 7], [28, 28, 8], [28, 28, 9], [28, 28, 10], [28, 28, 19], [28, 28, 28], [29, 0, 29], [29, 1, 2], [29, 1, 4], [29, 1, 8], [29, 1, 15], [29, 1, 16], [29, 1, 23], [29, 1, 27], [29, 1, 29], [29, 2, 1], [29, 2, 4], [29, 2, 8], [29, 2, 15], [29, 2, 16], [29, 2, 23], [29, 2, 27], [29, 2, 30], [29, 4, 1], [29, 4, 2], [29, 4, 8], [29, 4, 15], [29, 4, 16], [29, 4, 23], [29, 4, 29], [29, 4, 30], [29, 8, 1], [29, 8, 2], [29, 8, 4], [29, 8, 15], [29, 8, 16], [29, 8, 27], [29, 8, 29], [29, 8, 30], [29, 15, 1], [29, 15, 2], [29, 15, 4], [29, 15, 8], [29, 15, 23], [29, 15, 27], [29, 15, 29], [29, 15, 30], [29, 16, 1], [29, 16, 2], [29, 16, 4], [29, 16, 8], [29, 16, 23], [29, 16, 27], [29, 16, 29], [29, 16, 30], [29, 23, 1], [29, 23, 2], [29, 23, 4], [29, 23, 15], [29, 23, 16], [29, 23, 27], [29, 23, 29], [29, 23, 30], [29, 27, 1], [29, 27, 2], [29, 27, 8], [29, 27, 15], [29, 27, 16], [29, 27, 23], [29, 27, 29], [29, 27, 30], [29, 29, 0], [29, 29, 1], [29, 29, 4], [29, 29, 8], [29, 29, 15], [29, 29, 16], [29, 29, 23], [29, 29, 27], [29, 29, 29], [29, 29, 30], [29, 30, 2], [29, 30, 4], [29, 30, 8], [29, 30, 15], [29, 30, 16], [29, 30, 23], [29, 30, 27], [29, 30, 29], [30, 0, 30], [30, 1, 1], [30, 1, 30], [30, 30, 0], [30, 30, 1], [30, 30, 30]]} +RLMATH_EOF diff --git a/tasks/optimize-ae-p1-ff-nikodym-d3-p31/tests/check.py b/tasks/optimize-ae-p1-ff-nikodym-d3-p31/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..6345846c9b9114bf209db5350d6863485823b433 --- /dev/null +++ b/tasks/optimize-ae-p1-ff-nikodym-d3-p31/tests/check.py @@ -0,0 +1,47 @@ +"""Finite-field Nikodym set N in F_p^3, submitted as its complement. Score = |N| (minimize). + +Every point x of F_p^3 needs a direction v != 0 with x + t v in N for all t != 0 (x itself may lie outside N). +Upstream (AlphaEvolve `finite_field_nikodym.ipynb`) deduplicated silently; here the complement list must be +duplicate-free and in range. All p^2 + p + 1 projective directions are checked, vectorised over all points. +""" +import itertools + +import numpy as np + +from run import Invalid, int_list + + +def check(inst, ans): + p, d = inst["p"], 3 + rem = ans.get("removed") + if not isinstance(rem, list): + raise Invalid("removed must be a list") + if len(rem) >= p ** d: + raise Invalid("cannot remove every point") + w = np.array([p * p, p, 1], dtype=np.int64) + R = np.array([int_list(x, d, 0, p - 1, "point") for x in rem], dtype=np.int64).reshape(-1, d) + codes_r = R @ w + if len(np.unique(codes_r)) != len(codes_r): + raise Invalid("duplicate removed points") + in_n = np.ones(p ** d, dtype=bool) + in_n[codes_r] = False + X = np.stack(np.unravel_index(np.arange(p ** d), (p,) * d), axis=1).astype(np.int64) + good = np.zeros(p ** d, dtype=bool) + need = p - 1 + in_n.astype(np.int64) # points of N on the line through x, other than x, must number p-1 + done = False + for i in range(d): + for tail in itertools.product(range(p), repeat=d - 1 - i): + v = np.array([0] * i + [1] + list(tail), dtype=np.int64) + lid = ((X - X[:, i:i + 1] * v) % p) @ w + cnt = np.bincount(lid[in_n], minlength=p ** d) + good |= cnt[lid] == need + if good.all(): + done = True + break + if done: + break + if not done: + x = np.flatnonzero(~good)[0] + raise Invalid(f"point {X[x].tolist()} lies on no punctured line inside N") + size = p ** d - len(rem) + return size, {"size": size} diff --git a/tasks/optimize-ae-p1-ff-nikodym-d3-p31/tests/instance.json b/tasks/optimize-ae-p1-ff-nikodym-d3-p31/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..43e1d7a00b79ad8ae4d63a6a111991713fccd151 --- /dev/null +++ b/tasks/optimize-ae-p1-ff-nikodym-d3-p31/tests/instance.json @@ -0,0 +1 @@ +{"p": 31, "direction": "minimize", "baseline": 29791, "best_known": 26312, "family": "ae_p1_ff_nikodym", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p1-ff-nikodym-d3-p31/tests/run.py b/tasks/optimize-ae-p1-ff-nikodym-d3-p31/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-ae-p1-ff-nikodym-d3-p31/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-nikodym-d3-p31/tests/test.sh b/tasks/optimize-ae-p1-ff-nikodym-d3-p31/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-ae-p1-ff-nikodym-d3-p31/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-p41-sphere-max-volume-n64/environment/Dockerfile b/tasks/optimize-ae-p41-sphere-max-volume-n64/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-ae-p41-sphere-max-volume-n64/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-p41-sphere-max-volume-n64/environment/instance.json b/tasks/optimize-ae-p41-sphere-max-volume-n64/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..aea8d52c8de66d60a960fc26751ffe8b267b17dd --- /dev/null +++ b/tasks/optimize-ae-p41-sphere-max-volume-n64/environment/instance.json @@ -0,0 +1 @@ +{"n": 64, "direction": "maximize", "family": "ae_p41_sphere_max_volume", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p41-sphere-max-volume-n64/solution/solve.sh b/tasks/optimize-ae-p41-sphere-max-volume-n64/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9558cffdaea813a288291372d5c2d220b8b30a21 --- /dev/null +++ b/tasks/optimize-ae-p41-sphere-max-volume-n64/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.090848689496488, -0.241284522750016, 0.966192679902962], [-0.228079190781828, 0.06988139946377, 0.971131542449987], [0.260846738027148, 0.150966851030895, 0.953503009513033], [-0.26099385231698, -0.425233557784018, 0.866636388796991], [-0.094135409388959, 0.49316386633258, 0.864828263670351], [0.494250024270261, -0.273012920138339, 0.825336815455595], [-0.604499211758648, -0.117182847317133, 0.78793964443847], [0.383021660312376, 0.527350781106219, 0.758416482810211], [0.150684916897249, -0.635135751881764, 0.757559656067596], [-0.540614809012303, 0.370175374327176, 0.755450739968085], [0.686243895163223, 0.12355318070819, 0.716801177376333], [-0.558825171264714, -0.547556447298386, 0.622813266543779], [0.044299628090199, 0.796623786321728, 0.602849969741646], [0.547874382905262, -0.615576976577141, 0.566479166840515], [-0.841560735614163, 0.103729197676364, 0.530109216880792], [0.705171855109702, 0.513586352886807, 0.488837102611462], [-0.192888572165722, -0.821084043298853, 0.537228994533874], [-0.408459020139983, 0.746144580185557, 0.525765626801529], [0.840402562993678, -0.263470013133341, 0.473610688533498], [-0.844971155641916, -0.352018770573238, 0.402624553768485], [0.389841309180384, 0.846155517290712, 0.363379408077854], [0.278221592017667, -0.892311144673144, 0.355490600195361], [-0.803804655778054, 0.484529772541303, 0.345150655324014], [0.933828614638621, 0.198307030670056, 0.297722085289183], [-0.570883463037686, -0.782673948626155, 0.248019277017014], [-0.103194602677907, 0.970490613891388, 0.217942291276535], [0.736365356632229, -0.651809823214746, 0.181411179128111], [-0.990890031946633, -0.001504050933586, 0.134665074980821], [0.730052419165492, 0.677651142064695, 0.088387753275138], [-0.097065598815942, -0.990939277520915, 0.092831125129611], [-0.587631409130069, 0.805443334175906, 0.077138592386759], [0.980446113507186, -0.194450996857831, 0.030236208916633], [-0.85927247658435, -0.510623719244365, -0.030236208916632], [0.285011532227652, 0.955415126561138, -0.077138592386761], [0.422329187283706, -0.901676460697215, -0.092831125129609], [-0.91440368071395, 0.395036091728027, -0.088387753275139], [0.93453829434007, 0.329398685474552, -0.13466507498082], [-0.476503392438502, -0.860252579817084, -0.18141117912811], [-0.226732283026419, 0.949259516416223, -0.217942291276537], [0.799429985120893, -0.547172858535186, -0.248019277017013], [-0.946455090106074, -0.124837183336386, -0.297722085289184], [0.595921017563706, 0.725085626636773, -0.345150655324014], [0.035646911618175, -0.933999855923345, -0.355490600195359], [-0.649969231627727, 0.667454420707699, -0.363379408077856], [0.914013842468927, -0.049720865619141, -0.402624553768483], [-0.704221603420348, -0.528928018716064, -0.473610688533498], [0.135916797283276, 0.839700619203208, -0.52576562680153], [0.455946659225831, -0.70957568403443, -0.537228994533872], [-0.836176356562657, 0.24869135054527, -0.488837102611464], [0.758644053050202, 0.378739249285834, -0.53010921688079], [-0.310924006455829, -0.763169454148377, -0.566479166840515], [-0.307716990552917, 0.736126461762889, -0.602849969741648], [0.709567727779584, -0.329571349954434, -0.622813266543777], [-0.688118772613396, -0.112643805373108, -0.716801177376334], [0.386010219178084, 0.529424489584456, -0.755450739968084], [0.070005939253657, -0.649001183333251, -0.757559656067596], [-0.537105399517184, 0.36921840204853, -0.758416482810214], [0.608937533257487, 0.091357524662537, -0.787939644438469], [-0.374744137371059, -0.422357635848623, -0.825336815455595], [-0.075912397836151, 0.496295660077428, -0.864828263670352], [0.387986490231072, -0.313700259819924, -0.866636388796989], [-0.296281717317708, 0.055219152771986, -0.953503009513035], [0.191662332408925, 0.142017877727701, -0.971131542449987], [-0.005081365076123, -0.2577709933854, -0.966192679902962]]} +RLMATH_EOF diff --git a/tasks/optimize-ae-p41-sphere-max-volume-n64/tests/check.py b/tasks/optimize-ae-p41-sphere-max-volume-n64/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..58b6521809868700c39ccbae7ef07cd7c99c8d83 --- /dev/null +++ b/tasks/optimize-ae-p41-sphere-max-volume-n64/tests/check.py @@ -0,0 +1,23 @@ +"""n points on the unit sphere maximizing the volume of their convex hull (AlphaEvolve problem 41). + +Upstream bug fixed: the notebook summed |det|/6 of origin-pyramids over (QJ-joggled) hull facets, which +over-counts whenever the origin lies outside the hull (e.g. all points in one hemisphere). We use the exact +hull volume (scipy ConvexHull.volume) of the normalized points, without joggling.""" +import numpy as np +from scipy.spatial import ConvexHull + +from run import Invalid, float_matrix + + +def check(inst, ans): + n = inst["n"] + p = np.array(float_matrix(ans.get("points"), n, 3, "points")) + nr = np.linalg.norm(p, axis=1) + if (nr < 1e-9).any() or (nr > 1e9).any(): + raise Invalid("every point needs a non-zero, finite norm (it is projected to the unit sphere)") + p = p / nr[:, None] + try: + v = ConvexHull(p).volume + except Exception as e: # degenerate (coplanar) input + raise Invalid(f"degenerate hull: {type(e).__name__}") + return float(v), {} diff --git a/tasks/optimize-ae-p41-sphere-max-volume-n64/tests/instance.json b/tasks/optimize-ae-p41-sphere-max-volume-n64/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8d3522ccd580f19fc9070c3a2c62e623f2694cd6 --- /dev/null +++ b/tasks/optimize-ae-p41-sphere-max-volume-n64/tests/instance.json @@ -0,0 +1 @@ +{"n": 64, "direction": "maximize", "best_known": 3.836635206435, "baseline": 2.0908119877402633, "family": "ae_p41_sphere_max_volume", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p41-sphere-max-volume-n64/tests/run.py b/tasks/optimize-ae-p41-sphere-max-volume-n64/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-ae-p41-sphere-max-volume-n64/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-p41-sphere-max-volume-n64/tests/test.sh b/tasks/optimize-ae-p41-sphere-max-volume-n64/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-ae-p41-sphere-max-volume-n64/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-ea-hadamard-det-n51/environment/Dockerfile b/tasks/optimize-ea-hadamard-det-n51/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-ea-hadamard-det-n51/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-ea-hadamard-det-n51/environment/instance.json b/tasks/optimize-ea-hadamard-det-n51/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..61382319f6784839c698a34658e2b47b68556dfe --- /dev/null +++ b/tasks/optimize-ea-hadamard-det-n51/environment/instance.json @@ -0,0 +1 @@ +{"n": 51, "direction": "maximize", "family": "ea_hadamard_det_51", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ea-hadamard-det-n51/solution/solve.sh b/tasks/optimize-ea-hadamard-det-n51/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ee9fc8423a2696678fa5c6e72a12db574cb847bd --- /dev/null +++ b/tasks/optimize-ea-hadamard-det-n51/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' +{"matrix": [[-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, 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, 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, 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, -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, -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, -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, -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, -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, 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, 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, -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, 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, -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, -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, 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, -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, -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, 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, -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, -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, -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, -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, -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, -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, 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, -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, 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, 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, -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, 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, -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, 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, -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, -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, -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, -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, -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, 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, -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, 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/optimize-ea-hadamard-det-n51/tests/check.py b/tasks/optimize-ea-hadamard-det-n51/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..6a99b17f74a9b1cf69051abae394fa0d82d1aaef --- /dev/null +++ b/tasks/optimize-ea-hadamard-det-n51/tests/check.py @@ -0,0 +1,48 @@ +"""Hadamard maximal determinant, order 51 (EinsteinArena hadamard-det-51, MIT). + +Score = log10 |det A| computed from the exact integer determinant (fraction-free Bareiss). +Audit of the upstream verifier (sympy det_bareis, exact): sound. Change: a singular matrix is +rejected as invalid instead of scoring 0.0 (log10 of 0 is undefined). +""" +import math + +from run import Invalid, int_list + + +def _det_bareiss(m): + a = [row[:] for row in m] + n = len(a) + sign, prev = 1, 1 + for k in range(n - 1): + if a[k][k] == 0: + for r in range(k + 1, n): + if a[r][k] != 0: + a[k], a[r] = a[r], a[k] + sign = -sign + break + else: + return 0 + akk, rowk = a[k][k], a[k] + for i in range(k + 1, n): + aik, rowi = a[i][k], a[i] + a[i] = rowi[:k + 1] + [(rowi[j] * akk - aik * rowk[j]) // prev for j in range(k + 1, n)] + prev = akk + return sign * a[n - 1][n - 1] + + +def check(inst, ans): + n = inst["n"] + m = ans.get("matrix") + if not isinstance(m, list) or len(m) != n: + raise Invalid(f"matrix must be a list of {n} rows") + rows = [] + for r in m: + int_list(r, n, -1, 1, "matrix row") + if any(x == 0 for x in r): + raise Invalid("entries must be exactly 1 or -1") + rows.append(list(r)) + d = abs(_det_bareiss(rows)) + if d == 0: + raise Invalid("matrix is singular") + e = len(str(d)) - 1 + return e + math.log10(d / 10 ** e), {"det_over_2^50": str(d >> 50) if d % (1 << 50) == 0 else None} diff --git a/tasks/optimize-ea-hadamard-det-n51/tests/instance.json b/tasks/optimize-ea-hadamard-det-n51/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..724380bf9c9d45a45493f53e7c804412ad3a758e --- /dev/null +++ b/tasks/optimize-ea-hadamard-det-n51/tests/instance.json @@ -0,0 +1 @@ +{"n": 51, "direction": "maximize", "best_known": 43.301336781918444, "baseline": 16.741695863227573, "family": "ea_hadamard_det_51", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ea-hadamard-det-n51/tests/run.py b/tasks/optimize-ea-hadamard-det-n51/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-ea-hadamard-det-n51/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-ea-hadamard-det-n51/tests/test.sh b/tasks/optimize-ea-hadamard-det-n51/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-ea-hadamard-det-n51/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-ea-sidon-45-set/environment/Dockerfile b/tasks/optimize-ea-sidon-45-set/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-ea-sidon-45-set/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-ea-sidon-45-set/environment/instance.json b/tasks/optimize-ea-sidon-45-set/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5b3128a3fb938591cd522240e8998ede175c3f2e --- /dev/null +++ b/tasks/optimize-ea-sidon-45-set/environment/instance.json @@ -0,0 +1 @@ +{"min_size": 4, "max_size": 18, "max_abs": 1000000000, "direction": "minimize", "family": "ea_sidon_45_set", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ea-sidon-45-set/solution/solve.sh b/tasks/optimize-ea-sidon-45-set/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c0ecaa066564c69c383d13211bea5b8fa21f11b4 --- /dev/null +++ b/tasks/optimize-ea-sidon-45-set/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' +{"elements": [0, 136, 200, 243, 246, 249, 272, 286, 298, 323, 400, 528, 596, 1056]} +RLMATH_EOF diff --git a/tasks/optimize-ea-sidon-45-set/tests/check.py b/tasks/optimize-ea-sidon-45-set/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e49bea61dabe094f78326b2c4f7e5b4844a19c10 --- /dev/null +++ b/tasks/optimize-ea-sidon-45-set/tests/check.py @@ -0,0 +1,44 @@ +"""Sidon subsets of (4,5)-sets (EinsteinArena sidon-45-set, MIT). Score h(A)/|A| (minimize). + +Audit: upstream verifier is exact (all 4-subsets, exhaustive search for the largest Sidon subset); sound. +Re-implemented with a branch-and-bound for h(A) (same value).""" +from itertools import combinations + +from run import Invalid, int_list + + +def _max_sidon(a): + # largest Sidon subset (all sums x+y, x<=y distinct) by DFS with pruning + n = len(a) + best = [0] + + def rec(i, chosen, sums): + if len(chosen) + (n - i) <= best[0]: + return + if i == n: + best[0] = max(best[0], len(chosen)) + return + x = a[i] + new = [x + y for y in chosen] + [2 * x] + if len(set(new)) == len(new) and not any(s in sums for s in new): + rec(i + 1, chosen + [x], sums | set(new)) + rec(i + 1, chosen, sums) + + rec(0, [], frozenset()) + return best[0] + + +def check(inst, ans): + e = ans.get("elements") + lo, hi, bound = inst["min_size"], inst["max_size"], inst["max_abs"] + if not isinstance(e, list) or not lo <= len(e) <= hi: + raise Invalid(f"elements must be a list of {lo}..{hi} integers") + int_list(e, None, -bound, bound, "elements") + if len(set(e)) != len(e): + raise Invalid("elements must be distinct") + a = sorted(e) + for four in combinations(a, 4): + if len({four[j] - four[i] for i in range(4) for j in range(i + 1, 4)}) < 5: + raise Invalid(f"{four} has fewer than 5 distinct differences: not a (4,5)-set") + h = _max_sidon(a) + return h / len(a), {"h": h, "size": len(a)} diff --git a/tasks/optimize-ea-sidon-45-set/tests/instance.json b/tasks/optimize-ea-sidon-45-set/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5034bfb8233780bf6c27f38c1910347f7c05109f --- /dev/null +++ b/tasks/optimize-ea-sidon-45-set/tests/instance.json @@ -0,0 +1 @@ +{"min_size": 4, "max_size": 18, "max_abs": 1000000000, "direction": "minimize", "best_known": 0.5714285714285714, "baseline": 1.0, "family": "ea_sidon_45_set", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ea-sidon-45-set/tests/run.py b/tasks/optimize-ea-sidon-45-set/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-ea-sidon-45-set/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-ea-sidon-45-set/tests/test.sh b/tasks/optimize-ea-sidon-45-set/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-ea-sidon-45-set/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-udg-girth-n30/environment/Dockerfile b/tasks/optimize-finch-udg-girth-n30/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-finch-udg-girth-n30/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-udg-girth-n30/environment/instance.json b/tasks/optimize-finch-udg-girth-n30/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..77db5da59dad057157287bf866fb85dc9f9437dc --- /dev/null +++ b/tasks/optimize-finch-udg-girth-n30/environment/instance.json @@ -0,0 +1 @@ +{"n": 30, "direction": "maximize", "family": "finch_udg_girth_30", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-finch-udg-girth-n30/solution/solve.sh b/tasks/optimize-finch-udg-girth-n30/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..76b032e14ee0cf5695137481dd19600393d199d2 --- /dev/null +++ b/tasks/optimize-finch-udg-girth-n30/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"], ["sqrt(3)/2", "1/2"], ["sqrt(3)/2", "-1/2"], ["sqrt(3)", "0"], ["5*sqrt(3)/12 - sqrt(11)/12", "sqrt(33)/12 + 5/12"], ["5*sqrt(3)/12 + sqrt(11)/12", "sqrt(33)/12 - 5/12"], ["5*sqrt(3)/6", "sqrt(33)/6"], ["10", "0"], ["13", "0"], ["16", "0"], ["19", "0"], ["22", "0"], ["25", "0"], ["28", "0"], ["31", "0"], ["34", "0"], ["37", "0"], ["40", "0"], ["43", "0"], ["46", "0"], ["49", "0"], ["52", "0"], ["55", "0"], ["58", "0"], ["61", "0"], ["64", "0"], ["67", "0"], ["70", "0"], ["73", "0"], ["76", "0"]]} +RLMATH_EOF diff --git a/tasks/optimize-finch-udg-girth-n30/tests/check.py b/tasks/optimize-finch-udg-girth-n30/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d13a1b2900cd4570249465104956f57af9929f7e --- /dev/null +++ b/tasks/optimize-finch-udg-girth-n30/tests/check.py @@ -0,0 +1,198 @@ +"""Erdos #705: 4-chromatic unit-distance graph on 30 points with large girth (Finch/EFT skydiscover +erdos_705_unit_distance_high_girth, Apache-2.0). + +Upstream bugs fixed: (1) edges were |d - 1| < 1e-6 in float64, so near-unit "fake" edges produced graphs +that are not unit-distance graphs; here coordinates are exact real algebraic numbers (integers, rationals, ++ - * /, integer powers, sqrt; or JSON numbers taken at their exact binary value) and a pair is an edge +iff its distance is exactly 1 (numerical 60-digit screen, then an exact minimal-polynomial test); +(2) non-3-colourability was decided by a backtracking search with a 5 s wall-clock deadline (result +depended on machine speed); here the search is exact (DSatur branch and bound, no deadline).""" +import math +import re +from collections import deque + +import sympy as sp + +from run import Invalid + +TOK = re.compile(r"\s*(?:(\d+(?:\.\d+)?)|(sqrt)|([-+*/^()]))") +MAXLEN, MAXSQRT = 160, 3 + + +def _parse(s): + if not isinstance(s, str) or not 1 <= len(s) <= MAXLEN: + raise Invalid(f"coordinate expressions must be strings of 1..{MAXLEN} characters") + toks, pos = [], 0 + s = s.strip() + while pos < len(s): + m = TOK.match(s, pos) + if not m or m.end() == pos: + raise Invalid(f"cannot parse coordinate {s!r}") + toks.append(m.group(1) and ("num", m.group(1)) or m.group(2) and ("sqrt", None) or ("op", m.group(3))) + pos = m.end() + toks.append(("end", None)) + i = [0] + nsqrt = [0] + + def peek(): + return toks[i[0]] + + def take(kind, val=None): + t = toks[i[0]] + if t[0] != kind or (val is not None and t[1] != val): + raise Invalid(f"cannot parse coordinate {s!r}") + i[0] += 1 + return t + + def expr(): + v = term() + while peek() in (("op", "+"), ("op", "-")): + op = take("op")[1] + w = term() + v = v + w if op == "+" else v - w + return v + + def term(): + v = factor() + while peek() in (("op", "*"), ("op", "/")): + op = take("op")[1] + w = factor() + if op == "/": + if w == 0: + raise Invalid("division by zero") + v = v / w + else: + v = v * w + return v + + def factor(): + if peek() in (("op", "-"), ("op", "+")): + op = take("op")[1] + v = factor() + return -v if op == "-" else v + v = atom() + if peek() == ("op", "^"): + take("op", "^") + t = take("num")[1] + if "." in t or int(t) > 8: + raise Invalid("exponents must be integers 0..8") + v = v ** int(t) + return v + + def atom(): + t = peek() + if t[0] == "num": + take("num") + return sp.Rational(t[1]) + if t[0] == "sqrt": + take("sqrt") + nsqrt[0] += 1 + if nsqrt[0] > MAXSQRT: + raise Invalid(f"at most {MAXSQRT} sqrt per coordinate") + take("op", "(") + a = expr() + take("op", ")") + av = sp.N(a, 60) + if av < -sp.Rational(1, 10 ** 40): + raise Invalid("sqrt of a negative number") + if abs(av) < sp.Rational(1, 10 ** 40) and _is_zero(a): + return sp.Integer(0) + if av < 0: + raise Invalid("sqrt of a negative number") + return sp.sqrt(a) + if t == ("op", "("): + take("op", "(") + v = expr() + take("op", ")") + return v + raise Invalid(f"cannot parse coordinate {s!r}") + + v = expr() + take("end") + return v + + +def _is_zero(e): + x = sp.Symbol("x") + return sp.minimal_polynomial(e, x) == x + + +def _coord(c): + if isinstance(c, bool): + raise Invalid("coordinates must be numbers or expression strings") + if isinstance(c, int): + return sp.Integer(c) + if isinstance(c, float): + if not math.isfinite(c): + raise Invalid("non-finite coordinate") + return sp.Rational(c) + return _parse(c) + + +def _three_colourable(adj): + n = len(adj) + col = [-1] * n + + def rec(k): + if k == n: + return True + # DSatur: most constrained uncoloured vertex + v = max((u for u in range(n) if col[u] < 0), + key=lambda u: (len({col[w] for w in adj[u] if col[w] >= 0}), len(adj[u]))) + used = {col[w] for w in adj[v] if col[w] >= 0} + for c in range(3): + if c not in used: + col[v] = c + if rec(k + 1): + return True + col[v] = -1 + return False + + return rec(0) + + +def _girth(adj): + n, best = len(adj), math.inf + for s in range(n): + dist, par = [-1] * n, [-1] * n + dist[s] = 0 + q = deque([s]) + while q: + u = q.popleft() + for v in adj[u]: + if dist[v] < 0: + dist[v], par[v] = dist[u] + 1, u + q.append(v) + elif par[u] != v: + best = min(best, dist[u] + dist[v] + 1) + return best + + +def check(inst, ans): + n = inst["n"] + pts = ans.get("points") + if not isinstance(pts, list) or len(pts) != n: + raise Invalid(f"points must be a list of exactly {n} pairs") + P = [] + for p in pts: + if not isinstance(p, list) or len(p) != 2: + raise Invalid("each point is [x, y]") + P.append((_coord(p[0]), _coord(p[1]))) + num = [(sp.N(x, 60), sp.N(y, 60)) for x, y in P] + adj = [set() for _ in range(n)] + tiny = sp.Rational(1, 10 ** 25) + for i in range(n): + for j in range(i + 1, n): + d2n = (num[i][0] - num[j][0]) ** 2 + (num[i][1] - num[j][1]) ** 2 + if abs(d2n) < tiny and _is_zero((P[i][0] - P[j][0]) ** 2 + (P[i][1] - P[j][1]) ** 2): + raise Invalid(f"points {i} and {j} coincide") + if abs(d2n - 1) < tiny and _is_zero(sp.expand((P[i][0] - P[j][0]) ** 2 + (P[i][1] - P[j][1]) ** 2 - 1)): + adj[i].add(j) + adj[j].add(i) + edges = sum(len(a) for a in adj) // 2 + if edges == 0: + raise Invalid("the unit-distance graph has no edges") + if _three_colourable(adj): + raise Invalid("the unit-distance graph is 3-colourable (chromatic number <= 3)") + g = _girth(adj) + return float(g), {"edges": edges} diff --git a/tasks/optimize-finch-udg-girth-n30/tests/instance.json b/tasks/optimize-finch-udg-girth-n30/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4b6630b6c77d0966923a4640083660ebcb744a97 --- /dev/null +++ b/tasks/optimize-finch-udg-girth-n30/tests/instance.json @@ -0,0 +1 @@ +{"n": 30, "direction": "maximize", "best_known": 4, "baseline": 3.0, "family": "finch_udg_girth_30", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-finch-udg-girth-n30/tests/run.py b/tasks/optimize-finch-udg-girth-n30/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-finch-udg-girth-n30/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-udg-girth-n30/tests/test.sh b/tasks/optimize-finch-udg-girth-n30/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-finch-udg-girth-n30/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-fs-cycle-indep-c9-n6/environment/Dockerfile b/tasks/optimize-fs-cycle-indep-c9-n6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-fs-cycle-indep-c9-n6/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-fs-cycle-indep-c9-n6/environment/instance.json b/tasks/optimize-fs-cycle-indep-c9-n6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b6c2e6af38fb727f6c34a04e26055b434a5855b0 --- /dev/null +++ b/tasks/optimize-fs-cycle-indep-c9-n6/environment/instance.json @@ -0,0 +1 @@ +{"m": 9, "n": 6, "direction": "maximize", "family": "fs_cycle_independent_set", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-fs-cycle-indep-c9-n6/solution/solve.sh b/tasks/optimize-fs-cycle-indep-c9-n6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6990ffafa01bffb452f79a50e8f7886c82aaf954 --- /dev/null +++ b/tasks/optimize-fs-cycle-indep-c9-n6/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' +{"vertices": [[0, 0, 4, 0, 0, 2], [0, 0, 4, 0, 1, 6], [0, 0, 4, 0, 2, 1], [0, 0, 4, 0, 3, 5], [0, 0, 4, 0, 4, 0], [0, 0, 4, 0, 5, 4], [0, 0, 4, 0, 6, 8], [0, 0, 4, 0, 7, 3], [0, 0, 4, 0, 8, 7], [0, 0, 4, 1, 0, 4], [0, 0, 4, 1, 1, 8], [0, 0, 4, 1, 2, 3], [0, 0, 4, 1, 3, 7], [0, 0, 4, 1, 4, 2], [0, 0, 4, 1, 5, 6], [0, 0, 4, 1, 6, 1], [0, 0, 4, 1, 7, 5], [0, 0, 4, 1, 8, 0], [0, 0, 4, 2, 0, 6], [0, 0, 4, 2, 1, 1], [0, 0, 4, 2, 2, 5], [0, 0, 4, 2, 3, 0], [0, 0, 4, 2, 4, 4], [0, 0, 4, 2, 5, 8], [0, 0, 4, 2, 6, 3], [0, 0, 4, 2, 7, 7], [0, 0, 4, 2, 8, 2], [0, 0, 4, 3, 0, 8], [0, 0, 4, 3, 1, 3], [0, 0, 4, 3, 2, 7], [0, 0, 4, 3, 3, 2], [0, 0, 4, 3, 4, 6], [0, 0, 4, 3, 5, 1], [0, 0, 4, 3, 6, 5], [0, 0, 4, 3, 7, 0], [0, 0, 4, 3, 8, 4], [0, 0, 4, 4, 0, 1], [0, 0, 4, 4, 1, 5], [0, 0, 4, 4, 2, 0], [0, 0, 4, 4, 3, 4], [0, 0, 4, 4, 4, 8], [0, 0, 4, 4, 5, 3], [0, 0, 4, 4, 6, 7], [0, 0, 4, 4, 7, 2], [0, 0, 4, 4, 8, 6], [0, 0, 4, 5, 0, 3], [0, 0, 4, 5, 1, 7], [0, 0, 4, 5, 2, 2], [0, 0, 4, 5, 3, 6], [0, 0, 4, 5, 4, 1], [0, 0, 4, 5, 5, 5], [0, 0, 4, 5, 6, 0], [0, 0, 4, 5, 7, 4], [0, 0, 4, 5, 8, 8], [0, 0, 4, 6, 0, 5], [0, 0, 4, 6, 1, 0], [0, 0, 4, 6, 2, 4], [0, 0, 4, 6, 3, 8], [0, 0, 4, 6, 4, 3], [0, 0, 4, 6, 5, 7], [0, 0, 4, 6, 6, 2], [0, 0, 4, 6, 7, 6], [0, 0, 4, 6, 8, 1], [0, 0, 4, 7, 0, 7], [0, 0, 4, 7, 1, 2], [0, 0, 4, 7, 2, 6], [0, 0, 4, 7, 3, 1], [0, 0, 4, 7, 4, 5], [0, 0, 4, 7, 5, 0], [0, 0, 4, 7, 6, 4], [0, 0, 4, 7, 7, 8], [0, 0, 4, 7, 8, 3], [0, 0, 4, 8, 0, 0], [0, 0, 4, 8, 1, 4], [0, 0, 4, 8, 2, 8], [0, 0, 4, 8, 3, 3], [0, 0, 4, 8, 4, 7], [0, 0, 4, 8, 5, 2], [0, 0, 4, 8, 6, 6], [0, 0, 4, 8, 7, 1], [0, 0, 4, 8, 8, 5], [0, 1, 8, 0, 0, 2], [0, 1, 8, 0, 1, 6], [0, 1, 8, 0, 2, 1], [0, 1, 8, 0, 3, 5], [0, 1, 8, 0, 4, 0], [0, 1, 8, 0, 5, 4], [0, 1, 8, 0, 6, 8], [0, 1, 8, 0, 7, 3], [0, 1, 8, 0, 8, 7], [0, 1, 8, 1, 0, 4], [0, 1, 8, 1, 1, 8], [0, 1, 8, 1, 2, 3], [0, 1, 8, 1, 3, 7], [0, 1, 8, 1, 4, 2], [0, 1, 8, 1, 5, 6], [0, 1, 8, 1, 6, 1], [0, 1, 8, 1, 7, 5], [0, 1, 8, 1, 8, 0], [0, 1, 8, 2, 0, 6], [0, 1, 8, 2, 1, 1], [0, 1, 8, 2, 2, 5], [0, 1, 8, 2, 3, 0], [0, 1, 8, 2, 4, 4], [0, 1, 8, 2, 5, 8], [0, 1, 8, 2, 6, 3], [0, 1, 8, 2, 7, 7], [0, 1, 8, 2, 8, 2], [0, 1, 8, 3, 0, 8], [0, 1, 8, 3, 1, 3], [0, 1, 8, 3, 2, 7], [0, 1, 8, 3, 3, 2], [0, 1, 8, 3, 4, 6], [0, 1, 8, 3, 5, 1], [0, 1, 8, 3, 6, 5], [0, 1, 8, 3, 7, 0], [0, 1, 8, 3, 8, 4], [0, 1, 8, 4, 0, 1], [0, 1, 8, 4, 1, 5], [0, 1, 8, 4, 2, 0], [0, 1, 8, 4, 3, 4], [0, 1, 8, 4, 4, 8], [0, 1, 8, 4, 5, 3], [0, 1, 8, 4, 6, 7], [0, 1, 8, 4, 7, 2], [0, 1, 8, 4, 8, 6], [0, 1, 8, 5, 0, 3], [0, 1, 8, 5, 1, 7], [0, 1, 8, 5, 2, 2], [0, 1, 8, 5, 3, 6], [0, 1, 8, 5, 4, 1], [0, 1, 8, 5, 5, 5], [0, 1, 8, 5, 6, 0], [0, 1, 8, 5, 7, 4], [0, 1, 8, 5, 8, 8], [0, 1, 8, 6, 0, 5], [0, 1, 8, 6, 1, 0], [0, 1, 8, 6, 2, 4], [0, 1, 8, 6, 3, 8], [0, 1, 8, 6, 4, 3], [0, 1, 8, 6, 5, 7], [0, 1, 8, 6, 6, 2], [0, 1, 8, 6, 7, 6], [0, 1, 8, 6, 8, 1], [0, 1, 8, 7, 0, 7], [0, 1, 8, 7, 1, 2], [0, 1, 8, 7, 2, 6], [0, 1, 8, 7, 3, 1], [0, 1, 8, 7, 4, 5], [0, 1, 8, 7, 5, 0], [0, 1, 8, 7, 6, 4], [0, 1, 8, 7, 7, 8], [0, 1, 8, 7, 8, 3], [0, 1, 8, 8, 0, 0], [0, 1, 8, 8, 1, 4], [0, 1, 8, 8, 2, 8], [0, 1, 8, 8, 3, 3], [0, 1, 8, 8, 4, 7], [0, 1, 8, 8, 5, 2], [0, 1, 8, 8, 6, 6], [0, 1, 8, 8, 7, 1], [0, 1, 8, 8, 8, 5], [0, 2, 3, 0, 0, 2], [0, 2, 3, 0, 1, 6], [0, 2, 3, 0, 2, 1], [0, 2, 3, 0, 3, 5], [0, 2, 3, 0, 4, 0], [0, 2, 3, 0, 5, 4], [0, 2, 3, 0, 6, 8], [0, 2, 3, 0, 7, 3], [0, 2, 3, 0, 8, 7], [0, 2, 3, 1, 0, 4], [0, 2, 3, 1, 1, 8], [0, 2, 3, 1, 2, 3], [0, 2, 3, 1, 3, 7], [0, 2, 3, 1, 4, 2], [0, 2, 3, 1, 5, 6], [0, 2, 3, 1, 6, 1], [0, 2, 3, 1, 7, 5], [0, 2, 3, 1, 8, 0], [0, 2, 3, 2, 0, 6], [0, 2, 3, 2, 1, 1], [0, 2, 3, 2, 2, 5], [0, 2, 3, 2, 3, 0], [0, 2, 3, 2, 4, 4], [0, 2, 3, 2, 5, 8], [0, 2, 3, 2, 6, 3], [0, 2, 3, 2, 7, 7], [0, 2, 3, 2, 8, 2], [0, 2, 3, 3, 0, 8], [0, 2, 3, 3, 1, 3], [0, 2, 3, 3, 2, 7], [0, 2, 3, 3, 3, 2], [0, 2, 3, 3, 4, 6], [0, 2, 3, 3, 5, 1], [0, 2, 3, 3, 6, 5], [0, 2, 3, 3, 7, 0], [0, 2, 3, 3, 8, 4], [0, 2, 3, 4, 0, 1], [0, 2, 3, 4, 1, 5], [0, 2, 3, 4, 2, 0], [0, 2, 3, 4, 3, 4], [0, 2, 3, 4, 4, 8], [0, 2, 3, 4, 5, 3], [0, 2, 3, 4, 6, 7], [0, 2, 3, 4, 7, 2], [0, 2, 3, 4, 8, 6], [0, 2, 3, 5, 0, 3], [0, 2, 3, 5, 1, 7], [0, 2, 3, 5, 2, 2], [0, 2, 3, 5, 3, 6], [0, 2, 3, 5, 4, 1], [0, 2, 3, 5, 5, 5], [0, 2, 3, 5, 6, 0], [0, 2, 3, 5, 7, 4], [0, 2, 3, 5, 8, 8], [0, 2, 3, 6, 0, 5], [0, 2, 3, 6, 1, 0], [0, 2, 3, 6, 2, 4], [0, 2, 3, 6, 3, 8], [0, 2, 3, 6, 4, 3], [0, 2, 3, 6, 5, 7], [0, 2, 3, 6, 6, 2], [0, 2, 3, 6, 7, 6], [0, 2, 3, 6, 8, 1], [0, 2, 3, 7, 0, 7], [0, 2, 3, 7, 1, 2], [0, 2, 3, 7, 2, 6], [0, 2, 3, 7, 3, 1], [0, 2, 3, 7, 4, 5], [0, 2, 3, 7, 5, 0], [0, 2, 3, 7, 6, 4], [0, 2, 3, 7, 7, 8], [0, 2, 3, 7, 8, 3], [0, 2, 3, 8, 0, 0], [0, 2, 3, 8, 1, 4], [0, 2, 3, 8, 2, 8], [0, 2, 3, 8, 3, 3], [0, 2, 3, 8, 4, 7], [0, 2, 3, 8, 5, 2], [0, 2, 3, 8, 6, 6], [0, 2, 3, 8, 7, 1], [0, 2, 3, 8, 8, 5], [0, 3, 7, 0, 0, 2], [0, 3, 7, 0, 1, 6], [0, 3, 7, 0, 2, 1], [0, 3, 7, 0, 3, 5], [0, 3, 7, 0, 4, 0], [0, 3, 7, 0, 5, 4], [0, 3, 7, 0, 6, 8], [0, 3, 7, 0, 7, 3], [0, 3, 7, 0, 8, 7], [0, 3, 7, 1, 0, 4], [0, 3, 7, 1, 1, 8], [0, 3, 7, 1, 2, 3], [0, 3, 7, 1, 3, 7], [0, 3, 7, 1, 4, 2], [0, 3, 7, 1, 5, 6], [0, 3, 7, 1, 6, 1], [0, 3, 7, 1, 7, 5], [0, 3, 7, 1, 8, 0], [0, 3, 7, 2, 0, 6], [0, 3, 7, 2, 1, 1], [0, 3, 7, 2, 2, 5], [0, 3, 7, 2, 3, 0], [0, 3, 7, 2, 4, 4], [0, 3, 7, 2, 5, 8], [0, 3, 7, 2, 6, 3], [0, 3, 7, 2, 7, 7], [0, 3, 7, 2, 8, 2], [0, 3, 7, 3, 0, 8], [0, 3, 7, 3, 1, 3], [0, 3, 7, 3, 2, 7], [0, 3, 7, 3, 3, 2], [0, 3, 7, 3, 4, 6], [0, 3, 7, 3, 5, 1], [0, 3, 7, 3, 6, 5], [0, 3, 7, 3, 7, 0], [0, 3, 7, 3, 8, 4], [0, 3, 7, 4, 0, 1], [0, 3, 7, 4, 1, 5], [0, 3, 7, 4, 2, 0], [0, 3, 7, 4, 3, 4], [0, 3, 7, 4, 4, 8], [0, 3, 7, 4, 5, 3], [0, 3, 7, 4, 6, 7], [0, 3, 7, 4, 7, 2], [0, 3, 7, 4, 8, 6], [0, 3, 7, 5, 0, 3], [0, 3, 7, 5, 1, 7], [0, 3, 7, 5, 2, 2], [0, 3, 7, 5, 3, 6], [0, 3, 7, 5, 4, 1], [0, 3, 7, 5, 5, 5], [0, 3, 7, 5, 6, 0], [0, 3, 7, 5, 7, 4], [0, 3, 7, 5, 8, 8], [0, 3, 7, 6, 0, 5], [0, 3, 7, 6, 1, 0], [0, 3, 7, 6, 2, 4], [0, 3, 7, 6, 3, 8], [0, 3, 7, 6, 4, 3], [0, 3, 7, 6, 5, 7], [0, 3, 7, 6, 6, 2], [0, 3, 7, 6, 7, 6], [0, 3, 7, 6, 8, 1], [0, 3, 7, 7, 0, 7], [0, 3, 7, 7, 1, 2], [0, 3, 7, 7, 2, 6], [0, 3, 7, 7, 3, 1], [0, 3, 7, 7, 4, 5], [0, 3, 7, 7, 5, 0], [0, 3, 7, 7, 6, 4], [0, 3, 7, 7, 7, 8], [0, 3, 7, 7, 8, 3], [0, 3, 7, 8, 0, 0], [0, 3, 7, 8, 1, 4], [0, 3, 7, 8, 2, 8], [0, 3, 7, 8, 3, 3], [0, 3, 7, 8, 4, 7], [0, 3, 7, 8, 5, 2], [0, 3, 7, 8, 6, 6], [0, 3, 7, 8, 7, 1], [0, 3, 7, 8, 8, 5], [0, 4, 2, 0, 0, 2], [0, 4, 2, 0, 1, 6], [0, 4, 2, 0, 2, 1], [0, 4, 2, 0, 3, 5], [0, 4, 2, 0, 4, 0], [0, 4, 2, 0, 5, 4], [0, 4, 2, 0, 6, 8], [0, 4, 2, 0, 7, 3], [0, 4, 2, 0, 8, 7], [0, 4, 2, 1, 0, 4], [0, 4, 2, 1, 1, 8], [0, 4, 2, 1, 2, 3], [0, 4, 2, 1, 3, 7], [0, 4, 2, 1, 4, 2], [0, 4, 2, 1, 5, 6], [0, 4, 2, 1, 6, 1], [0, 4, 2, 1, 7, 5], [0, 4, 2, 1, 8, 0], [0, 4, 2, 2, 0, 6], [0, 4, 2, 2, 1, 1], [0, 4, 2, 2, 2, 5], [0, 4, 2, 2, 3, 0], [0, 4, 2, 2, 4, 4], [0, 4, 2, 2, 5, 8], [0, 4, 2, 2, 6, 3], [0, 4, 2, 2, 7, 7], [0, 4, 2, 2, 8, 2], [0, 4, 2, 3, 0, 8], [0, 4, 2, 3, 1, 3], [0, 4, 2, 3, 2, 7], [0, 4, 2, 3, 3, 2], [0, 4, 2, 3, 4, 6], [0, 4, 2, 3, 5, 1], [0, 4, 2, 3, 6, 5], [0, 4, 2, 3, 7, 0], [0, 4, 2, 3, 8, 4], [0, 4, 2, 4, 0, 1], [0, 4, 2, 4, 1, 5], [0, 4, 2, 4, 2, 0], [0, 4, 2, 4, 3, 4], [0, 4, 2, 4, 4, 8], [0, 4, 2, 4, 5, 3], [0, 4, 2, 4, 6, 7], [0, 4, 2, 4, 7, 2], [0, 4, 2, 4, 8, 6], [0, 4, 2, 5, 0, 3], [0, 4, 2, 5, 1, 7], [0, 4, 2, 5, 2, 2], [0, 4, 2, 5, 3, 6], [0, 4, 2, 5, 4, 1], [0, 4, 2, 5, 5, 5], [0, 4, 2, 5, 6, 0], [0, 4, 2, 5, 7, 4], [0, 4, 2, 5, 8, 8], [0, 4, 2, 6, 0, 5], [0, 4, 2, 6, 1, 0], [0, 4, 2, 6, 2, 4], [0, 4, 2, 6, 3, 8], [0, 4, 2, 6, 4, 3], [0, 4, 2, 6, 5, 7], [0, 4, 2, 6, 6, 2], [0, 4, 2, 6, 7, 6], [0, 4, 2, 6, 8, 1], [0, 4, 2, 7, 0, 7], [0, 4, 2, 7, 1, 2], [0, 4, 2, 7, 2, 6], [0, 4, 2, 7, 3, 1], [0, 4, 2, 7, 4, 5], [0, 4, 2, 7, 5, 0], [0, 4, 2, 7, 6, 4], [0, 4, 2, 7, 7, 8], [0, 4, 2, 7, 8, 3], [0, 4, 2, 8, 0, 0], [0, 4, 2, 8, 1, 4], [0, 4, 2, 8, 2, 8], [0, 4, 2, 8, 3, 3], [0, 4, 2, 8, 4, 7], [0, 4, 2, 8, 5, 2], [0, 4, 2, 8, 6, 6], [0, 4, 2, 8, 7, 1], [0, 4, 2, 8, 8, 5], [0, 5, 6, 0, 0, 2], [0, 5, 6, 0, 1, 6], [0, 5, 6, 0, 2, 1], [0, 5, 6, 0, 3, 5], [0, 5, 6, 0, 4, 0], [0, 5, 6, 0, 5, 4], [0, 5, 6, 0, 6, 8], [0, 5, 6, 0, 7, 3], [0, 5, 6, 0, 8, 7], [0, 5, 6, 1, 0, 4], [0, 5, 6, 1, 1, 8], [0, 5, 6, 1, 2, 3], [0, 5, 6, 1, 3, 7], [0, 5, 6, 1, 4, 2], [0, 5, 6, 1, 5, 6], [0, 5, 6, 1, 6, 1], [0, 5, 6, 1, 7, 5], [0, 5, 6, 1, 8, 0], [0, 5, 6, 2, 0, 6], [0, 5, 6, 2, 1, 1], [0, 5, 6, 2, 2, 5], [0, 5, 6, 2, 3, 0], [0, 5, 6, 2, 4, 4], [0, 5, 6, 2, 5, 8], [0, 5, 6, 2, 6, 3], [0, 5, 6, 2, 7, 7], [0, 5, 6, 2, 8, 2], [0, 5, 6, 3, 0, 8], [0, 5, 6, 3, 1, 3], [0, 5, 6, 3, 2, 7], [0, 5, 6, 3, 3, 2], [0, 5, 6, 3, 4, 6], [0, 5, 6, 3, 5, 1], [0, 5, 6, 3, 6, 5], [0, 5, 6, 3, 7, 0], [0, 5, 6, 3, 8, 4], [0, 5, 6, 4, 0, 1], [0, 5, 6, 4, 1, 5], [0, 5, 6, 4, 2, 0], [0, 5, 6, 4, 3, 4], [0, 5, 6, 4, 4, 8], [0, 5, 6, 4, 5, 3], [0, 5, 6, 4, 6, 7], [0, 5, 6, 4, 7, 2], [0, 5, 6, 4, 8, 6], [0, 5, 6, 5, 0, 3], [0, 5, 6, 5, 1, 7], [0, 5, 6, 5, 2, 2], [0, 5, 6, 5, 3, 6], [0, 5, 6, 5, 4, 1], [0, 5, 6, 5, 5, 5], [0, 5, 6, 5, 6, 0], [0, 5, 6, 5, 7, 4], [0, 5, 6, 5, 8, 8], [0, 5, 6, 6, 0, 5], [0, 5, 6, 6, 1, 0], [0, 5, 6, 6, 2, 4], [0, 5, 6, 6, 3, 8], [0, 5, 6, 6, 4, 3], [0, 5, 6, 6, 5, 7], [0, 5, 6, 6, 6, 2], [0, 5, 6, 6, 7, 6], [0, 5, 6, 6, 8, 1], [0, 5, 6, 7, 0, 7], [0, 5, 6, 7, 1, 2], [0, 5, 6, 7, 2, 6], [0, 5, 6, 7, 3, 1], [0, 5, 6, 7, 4, 5], [0, 5, 6, 7, 5, 0], [0, 5, 6, 7, 6, 4], [0, 5, 6, 7, 7, 8], [0, 5, 6, 7, 8, 3], [0, 5, 6, 8, 0, 0], [0, 5, 6, 8, 1, 4], [0, 5, 6, 8, 2, 8], [0, 5, 6, 8, 3, 3], [0, 5, 6, 8, 4, 7], [0, 5, 6, 8, 5, 2], [0, 5, 6, 8, 6, 6], [0, 5, 6, 8, 7, 1], [0, 5, 6, 8, 8, 5], [0, 6, 1, 0, 0, 2], [0, 6, 1, 0, 1, 6], [0, 6, 1, 0, 2, 1], [0, 6, 1, 0, 3, 5], [0, 6, 1, 0, 4, 0], [0, 6, 1, 0, 5, 4], [0, 6, 1, 0, 6, 8], [0, 6, 1, 0, 7, 3], [0, 6, 1, 0, 8, 7], [0, 6, 1, 1, 0, 4], [0, 6, 1, 1, 1, 8], [0, 6, 1, 1, 2, 3], [0, 6, 1, 1, 3, 7], [0, 6, 1, 1, 4, 2], [0, 6, 1, 1, 5, 6], [0, 6, 1, 1, 6, 1], [0, 6, 1, 1, 7, 5], [0, 6, 1, 1, 8, 0], [0, 6, 1, 2, 0, 6], [0, 6, 1, 2, 1, 1], [0, 6, 1, 2, 2, 5], [0, 6, 1, 2, 3, 0], [0, 6, 1, 2, 4, 4], [0, 6, 1, 2, 5, 8], [0, 6, 1, 2, 6, 3], [0, 6, 1, 2, 7, 7], [0, 6, 1, 2, 8, 2], [0, 6, 1, 3, 0, 8], [0, 6, 1, 3, 1, 3], [0, 6, 1, 3, 2, 7], [0, 6, 1, 3, 3, 2], [0, 6, 1, 3, 4, 6], [0, 6, 1, 3, 5, 1], [0, 6, 1, 3, 6, 5], [0, 6, 1, 3, 7, 0], [0, 6, 1, 3, 8, 4], [0, 6, 1, 4, 0, 1], [0, 6, 1, 4, 1, 5], [0, 6, 1, 4, 2, 0], [0, 6, 1, 4, 3, 4], [0, 6, 1, 4, 4, 8], [0, 6, 1, 4, 5, 3], [0, 6, 1, 4, 6, 7], [0, 6, 1, 4, 7, 2], [0, 6, 1, 4, 8, 6], [0, 6, 1, 5, 0, 3], [0, 6, 1, 5, 1, 7], [0, 6, 1, 5, 2, 2], [0, 6, 1, 5, 3, 6], [0, 6, 1, 5, 4, 1], [0, 6, 1, 5, 5, 5], [0, 6, 1, 5, 6, 0], [0, 6, 1, 5, 7, 4], [0, 6, 1, 5, 8, 8], [0, 6, 1, 6, 0, 5], [0, 6, 1, 6, 1, 0], [0, 6, 1, 6, 2, 4], [0, 6, 1, 6, 3, 8], [0, 6, 1, 6, 4, 3], [0, 6, 1, 6, 5, 7], [0, 6, 1, 6, 6, 2], [0, 6, 1, 6, 7, 6], [0, 6, 1, 6, 8, 1], [0, 6, 1, 7, 0, 7], [0, 6, 1, 7, 1, 2], [0, 6, 1, 7, 2, 6], [0, 6, 1, 7, 3, 1], [0, 6, 1, 7, 4, 5], [0, 6, 1, 7, 5, 0], [0, 6, 1, 7, 6, 4], [0, 6, 1, 7, 7, 8], [0, 6, 1, 7, 8, 3], [0, 6, 1, 8, 0, 0], [0, 6, 1, 8, 1, 4], [0, 6, 1, 8, 2, 8], [0, 6, 1, 8, 3, 3], [0, 6, 1, 8, 4, 7], [0, 6, 1, 8, 5, 2], [0, 6, 1, 8, 6, 6], [0, 6, 1, 8, 7, 1], [0, 6, 1, 8, 8, 5], [0, 7, 5, 0, 0, 2], [0, 7, 5, 0, 1, 6], [0, 7, 5, 0, 2, 1], [0, 7, 5, 0, 3, 5], [0, 7, 5, 0, 4, 0], [0, 7, 5, 0, 5, 4], [0, 7, 5, 0, 6, 8], [0, 7, 5, 0, 7, 3], [0, 7, 5, 0, 8, 7], [0, 7, 5, 1, 0, 4], [0, 7, 5, 1, 1, 8], [0, 7, 5, 1, 2, 3], [0, 7, 5, 1, 3, 7], [0, 7, 5, 1, 4, 2], [0, 7, 5, 1, 5, 6], [0, 7, 5, 1, 6, 1], [0, 7, 5, 1, 7, 5], [0, 7, 5, 1, 8, 0], [0, 7, 5, 2, 0, 6], [0, 7, 5, 2, 1, 1], [0, 7, 5, 2, 2, 5], [0, 7, 5, 2, 3, 0], [0, 7, 5, 2, 4, 4], [0, 7, 5, 2, 5, 8], [0, 7, 5, 2, 6, 3], [0, 7, 5, 2, 7, 7], [0, 7, 5, 2, 8, 2], [0, 7, 5, 3, 0, 8], [0, 7, 5, 3, 1, 3], [0, 7, 5, 3, 2, 7], [0, 7, 5, 3, 3, 2], [0, 7, 5, 3, 4, 6], [0, 7, 5, 3, 5, 1], [0, 7, 5, 3, 6, 5], [0, 7, 5, 3, 7, 0], [0, 7, 5, 3, 8, 4], [0, 7, 5, 4, 0, 1], [0, 7, 5, 4, 1, 5], [0, 7, 5, 4, 2, 0], [0, 7, 5, 4, 3, 4], [0, 7, 5, 4, 4, 8], [0, 7, 5, 4, 5, 3], [0, 7, 5, 4, 6, 7], [0, 7, 5, 4, 7, 2], [0, 7, 5, 4, 8, 6], [0, 7, 5, 5, 0, 3], [0, 7, 5, 5, 1, 7], [0, 7, 5, 5, 2, 2], [0, 7, 5, 5, 3, 6], [0, 7, 5, 5, 4, 1], [0, 7, 5, 5, 5, 5], [0, 7, 5, 5, 6, 0], [0, 7, 5, 5, 7, 4], [0, 7, 5, 5, 8, 8], [0, 7, 5, 6, 0, 5], [0, 7, 5, 6, 1, 0], [0, 7, 5, 6, 2, 4], [0, 7, 5, 6, 3, 8], [0, 7, 5, 6, 4, 3], [0, 7, 5, 6, 5, 7], [0, 7, 5, 6, 6, 2], [0, 7, 5, 6, 7, 6], [0, 7, 5, 6, 8, 1], [0, 7, 5, 7, 0, 7], [0, 7, 5, 7, 1, 2], [0, 7, 5, 7, 2, 6], [0, 7, 5, 7, 3, 1], [0, 7, 5, 7, 4, 5], [0, 7, 5, 7, 5, 0], [0, 7, 5, 7, 6, 4], [0, 7, 5, 7, 7, 8], [0, 7, 5, 7, 8, 3], [0, 7, 5, 8, 0, 0], [0, 7, 5, 8, 1, 4], [0, 7, 5, 8, 2, 8], [0, 7, 5, 8, 3, 3], [0, 7, 5, 8, 4, 7], [0, 7, 5, 8, 5, 2], [0, 7, 5, 8, 6, 6], [0, 7, 5, 8, 7, 1], [0, 7, 5, 8, 8, 5], [0, 8, 0, 0, 0, 2], [0, 8, 0, 0, 1, 6], [0, 8, 0, 0, 2, 1], [0, 8, 0, 0, 3, 5], [0, 8, 0, 0, 4, 0], [0, 8, 0, 0, 5, 4], [0, 8, 0, 0, 6, 8], [0, 8, 0, 0, 7, 3], [0, 8, 0, 0, 8, 7], [0, 8, 0, 1, 0, 4], [0, 8, 0, 1, 1, 8], [0, 8, 0, 1, 2, 3], [0, 8, 0, 1, 3, 7], [0, 8, 0, 1, 4, 2], [0, 8, 0, 1, 5, 6], [0, 8, 0, 1, 6, 1], [0, 8, 0, 1, 7, 5], [0, 8, 0, 1, 8, 0], [0, 8, 0, 2, 0, 6], [0, 8, 0, 2, 1, 1], [0, 8, 0, 2, 2, 5], [0, 8, 0, 2, 3, 0], [0, 8, 0, 2, 4, 4], [0, 8, 0, 2, 5, 8], [0, 8, 0, 2, 6, 3], [0, 8, 0, 2, 7, 7], [0, 8, 0, 2, 8, 2], [0, 8, 0, 3, 0, 8], [0, 8, 0, 3, 1, 3], [0, 8, 0, 3, 2, 7], [0, 8, 0, 3, 3, 2], [0, 8, 0, 3, 4, 6], [0, 8, 0, 3, 5, 1], [0, 8, 0, 3, 6, 5], [0, 8, 0, 3, 7, 0], [0, 8, 0, 3, 8, 4], [0, 8, 0, 4, 0, 1], [0, 8, 0, 4, 1, 5], [0, 8, 0, 4, 2, 0], [0, 8, 0, 4, 3, 4], [0, 8, 0, 4, 4, 8], [0, 8, 0, 4, 5, 3], [0, 8, 0, 4, 6, 7], [0, 8, 0, 4, 7, 2], [0, 8, 0, 4, 8, 6], [0, 8, 0, 5, 0, 3], [0, 8, 0, 5, 1, 7], [0, 8, 0, 5, 2, 2], [0, 8, 0, 5, 3, 6], [0, 8, 0, 5, 4, 1], [0, 8, 0, 5, 5, 5], [0, 8, 0, 5, 6, 0], [0, 8, 0, 5, 7, 4], [0, 8, 0, 5, 8, 8], [0, 8, 0, 6, 0, 5], [0, 8, 0, 6, 1, 0], [0, 8, 0, 6, 2, 4], [0, 8, 0, 6, 3, 8], [0, 8, 0, 6, 4, 3], [0, 8, 0, 6, 5, 7], [0, 8, 0, 6, 6, 2], [0, 8, 0, 6, 7, 6], [0, 8, 0, 6, 8, 1], [0, 8, 0, 7, 0, 7], [0, 8, 0, 7, 1, 2], [0, 8, 0, 7, 2, 6], [0, 8, 0, 7, 3, 1], [0, 8, 0, 7, 4, 5], [0, 8, 0, 7, 5, 0], [0, 8, 0, 7, 6, 4], [0, 8, 0, 7, 7, 8], [0, 8, 0, 7, 8, 3], [0, 8, 0, 8, 0, 0], [0, 8, 0, 8, 1, 4], [0, 8, 0, 8, 2, 8], [0, 8, 0, 8, 3, 3], [0, 8, 0, 8, 4, 7], [0, 8, 0, 8, 5, 2], [0, 8, 0, 8, 6, 6], [0, 8, 0, 8, 7, 1], [0, 8, 0, 8, 8, 5], [1, 0, 6, 0, 0, 2], [1, 0, 6, 0, 1, 6], [1, 0, 6, 0, 2, 1], [1, 0, 6, 0, 3, 5], [1, 0, 6, 0, 4, 0], [1, 0, 6, 0, 5, 4], [1, 0, 6, 0, 6, 8], [1, 0, 6, 0, 7, 3], [1, 0, 6, 0, 8, 7], [1, 0, 6, 1, 0, 4], [1, 0, 6, 1, 1, 8], [1, 0, 6, 1, 2, 3], [1, 0, 6, 1, 3, 7], [1, 0, 6, 1, 4, 2], [1, 0, 6, 1, 5, 6], [1, 0, 6, 1, 6, 1], [1, 0, 6, 1, 7, 5], [1, 0, 6, 1, 8, 0], [1, 0, 6, 2, 0, 6], [1, 0, 6, 2, 1, 1], [1, 0, 6, 2, 2, 5], [1, 0, 6, 2, 3, 0], [1, 0, 6, 2, 4, 4], [1, 0, 6, 2, 5, 8], [1, 0, 6, 2, 6, 3], [1, 0, 6, 2, 7, 7], [1, 0, 6, 2, 8, 2], [1, 0, 6, 3, 0, 8], [1, 0, 6, 3, 1, 3], [1, 0, 6, 3, 2, 7], [1, 0, 6, 3, 3, 2], [1, 0, 6, 3, 4, 6], [1, 0, 6, 3, 5, 1], [1, 0, 6, 3, 6, 5], [1, 0, 6, 3, 7, 0], [1, 0, 6, 3, 8, 4], [1, 0, 6, 4, 0, 1], [1, 0, 6, 4, 1, 5], [1, 0, 6, 4, 2, 0], [1, 0, 6, 4, 3, 4], [1, 0, 6, 4, 4, 8], [1, 0, 6, 4, 5, 3], [1, 0, 6, 4, 6, 7], [1, 0, 6, 4, 7, 2], [1, 0, 6, 4, 8, 6], [1, 0, 6, 5, 0, 3], [1, 0, 6, 5, 1, 7], [1, 0, 6, 5, 2, 2], [1, 0, 6, 5, 3, 6], [1, 0, 6, 5, 4, 1], [1, 0, 6, 5, 5, 5], [1, 0, 6, 5, 6, 0], [1, 0, 6, 5, 7, 4], [1, 0, 6, 5, 8, 8], [1, 0, 6, 6, 0, 5], [1, 0, 6, 6, 1, 0], [1, 0, 6, 6, 2, 4], [1, 0, 6, 6, 3, 8], [1, 0, 6, 6, 4, 3], [1, 0, 6, 6, 5, 7], [1, 0, 6, 6, 6, 2], [1, 0, 6, 6, 7, 6], [1, 0, 6, 6, 8, 1], [1, 0, 6, 7, 0, 7], [1, 0, 6, 7, 1, 2], [1, 0, 6, 7, 2, 6], [1, 0, 6, 7, 3, 1], [1, 0, 6, 7, 4, 5], [1, 0, 6, 7, 5, 0], [1, 0, 6, 7, 6, 4], [1, 0, 6, 7, 7, 8], [1, 0, 6, 7, 8, 3], [1, 0, 6, 8, 0, 0], [1, 0, 6, 8, 1, 4], [1, 0, 6, 8, 2, 8], [1, 0, 6, 8, 3, 3], [1, 0, 6, 8, 4, 7], [1, 0, 6, 8, 5, 2], [1, 0, 6, 8, 6, 6], [1, 0, 6, 8, 7, 1], [1, 0, 6, 8, 8, 5], [1, 1, 1, 0, 0, 2], [1, 1, 1, 0, 1, 6], [1, 1, 1, 0, 2, 1], [1, 1, 1, 0, 3, 5], [1, 1, 1, 0, 4, 0], [1, 1, 1, 0, 5, 4], [1, 1, 1, 0, 6, 8], [1, 1, 1, 0, 7, 3], [1, 1, 1, 0, 8, 7], [1, 1, 1, 1, 0, 4], [1, 1, 1, 1, 1, 8], [1, 1, 1, 1, 2, 3], [1, 1, 1, 1, 3, 7], [1, 1, 1, 1, 4, 2], [1, 1, 1, 1, 5, 6], [1, 1, 1, 1, 6, 1], [1, 1, 1, 1, 7, 5], [1, 1, 1, 1, 8, 0], [1, 1, 1, 2, 0, 6], [1, 1, 1, 2, 1, 1], [1, 1, 1, 2, 2, 5], [1, 1, 1, 2, 3, 0], [1, 1, 1, 2, 4, 4], [1, 1, 1, 2, 5, 8], [1, 1, 1, 2, 6, 3], [1, 1, 1, 2, 7, 7], [1, 1, 1, 2, 8, 2], [1, 1, 1, 3, 0, 8], [1, 1, 1, 3, 1, 3], [1, 1, 1, 3, 2, 7], [1, 1, 1, 3, 3, 2], [1, 1, 1, 3, 4, 6], [1, 1, 1, 3, 5, 1], [1, 1, 1, 3, 6, 5], [1, 1, 1, 3, 7, 0], [1, 1, 1, 3, 8, 4], [1, 1, 1, 4, 0, 1], [1, 1, 1, 4, 1, 5], [1, 1, 1, 4, 2, 0], [1, 1, 1, 4, 3, 4], [1, 1, 1, 4, 4, 8], [1, 1, 1, 4, 5, 3], [1, 1, 1, 4, 6, 7], [1, 1, 1, 4, 7, 2], [1, 1, 1, 4, 8, 6], [1, 1, 1, 5, 0, 3], [1, 1, 1, 5, 1, 7], [1, 1, 1, 5, 2, 2], [1, 1, 1, 5, 3, 6], [1, 1, 1, 5, 4, 1], [1, 1, 1, 5, 5, 5], [1, 1, 1, 5, 6, 0], [1, 1, 1, 5, 7, 4], [1, 1, 1, 5, 8, 8], [1, 1, 1, 6, 0, 5], [1, 1, 1, 6, 1, 0], [1, 1, 1, 6, 2, 4], [1, 1, 1, 6, 3, 8], [1, 1, 1, 6, 4, 3], [1, 1, 1, 6, 5, 7], [1, 1, 1, 6, 6, 2], [1, 1, 1, 6, 7, 6], [1, 1, 1, 6, 8, 1], [1, 1, 1, 7, 0, 7], [1, 1, 1, 7, 1, 2], [1, 1, 1, 7, 2, 6], [1, 1, 1, 7, 3, 1], [1, 1, 1, 7, 4, 5], [1, 1, 1, 7, 5, 0], [1, 1, 1, 7, 6, 4], [1, 1, 1, 7, 7, 8], [1, 1, 1, 7, 8, 3], [1, 1, 1, 8, 0, 0], [1, 1, 1, 8, 1, 4], [1, 1, 1, 8, 2, 8], [1, 1, 1, 8, 3, 3], [1, 1, 1, 8, 4, 7], [1, 1, 1, 8, 5, 2], [1, 1, 1, 8, 6, 6], [1, 1, 1, 8, 7, 1], [1, 1, 1, 8, 8, 5], [1, 2, 5, 0, 0, 2], [1, 2, 5, 0, 1, 6], [1, 2, 5, 0, 2, 1], [1, 2, 5, 0, 3, 5], [1, 2, 5, 0, 4, 0], [1, 2, 5, 0, 5, 4], [1, 2, 5, 0, 6, 8], [1, 2, 5, 0, 7, 3], [1, 2, 5, 0, 8, 7], [1, 2, 5, 1, 0, 4], [1, 2, 5, 1, 1, 8], [1, 2, 5, 1, 2, 3], [1, 2, 5, 1, 3, 7], [1, 2, 5, 1, 4, 2], [1, 2, 5, 1, 5, 6], [1, 2, 5, 1, 6, 1], [1, 2, 5, 1, 7, 5], [1, 2, 5, 1, 8, 0], [1, 2, 5, 2, 0, 6], [1, 2, 5, 2, 1, 1], [1, 2, 5, 2, 2, 5], [1, 2, 5, 2, 3, 0], [1, 2, 5, 2, 4, 4], [1, 2, 5, 2, 5, 8], [1, 2, 5, 2, 6, 3], [1, 2, 5, 2, 7, 7], [1, 2, 5, 2, 8, 2], [1, 2, 5, 3, 0, 8], [1, 2, 5, 3, 1, 3], [1, 2, 5, 3, 2, 7], [1, 2, 5, 3, 3, 2], [1, 2, 5, 3, 4, 6], [1, 2, 5, 3, 5, 1], [1, 2, 5, 3, 6, 5], [1, 2, 5, 3, 7, 0], [1, 2, 5, 3, 8, 4], [1, 2, 5, 4, 0, 1], [1, 2, 5, 4, 1, 5], [1, 2, 5, 4, 2, 0], [1, 2, 5, 4, 3, 4], [1, 2, 5, 4, 4, 8], [1, 2, 5, 4, 5, 3], [1, 2, 5, 4, 6, 7], [1, 2, 5, 4, 7, 2], [1, 2, 5, 4, 8, 6], [1, 2, 5, 5, 0, 3], [1, 2, 5, 5, 1, 7], [1, 2, 5, 5, 2, 2], [1, 2, 5, 5, 3, 6], [1, 2, 5, 5, 4, 1], [1, 2, 5, 5, 5, 5], [1, 2, 5, 5, 6, 0], [1, 2, 5, 5, 7, 4], [1, 2, 5, 5, 8, 8], [1, 2, 5, 6, 0, 5], [1, 2, 5, 6, 1, 0], [1, 2, 5, 6, 2, 4], [1, 2, 5, 6, 3, 8], [1, 2, 5, 6, 4, 3], [1, 2, 5, 6, 5, 7], [1, 2, 5, 6, 6, 2], [1, 2, 5, 6, 7, 6], [1, 2, 5, 6, 8, 1], [1, 2, 5, 7, 0, 7], [1, 2, 5, 7, 1, 2], [1, 2, 5, 7, 2, 6], [1, 2, 5, 7, 3, 1], [1, 2, 5, 7, 4, 5], [1, 2, 5, 7, 5, 0], [1, 2, 5, 7, 6, 4], [1, 2, 5, 7, 7, 8], [1, 2, 5, 7, 8, 3], [1, 2, 5, 8, 0, 0], [1, 2, 5, 8, 1, 4], [1, 2, 5, 8, 2, 8], [1, 2, 5, 8, 3, 3], [1, 2, 5, 8, 4, 7], [1, 2, 5, 8, 5, 2], [1, 2, 5, 8, 6, 6], [1, 2, 5, 8, 7, 1], [1, 2, 5, 8, 8, 5], [1, 3, 0, 0, 0, 2], [1, 3, 0, 0, 1, 6], [1, 3, 0, 0, 2, 1], [1, 3, 0, 0, 3, 5], [1, 3, 0, 0, 4, 0], [1, 3, 0, 0, 5, 4], [1, 3, 0, 0, 6, 8], [1, 3, 0, 0, 7, 3], [1, 3, 0, 0, 8, 7], [1, 3, 0, 1, 0, 4], [1, 3, 0, 1, 1, 8], [1, 3, 0, 1, 2, 3], [1, 3, 0, 1, 3, 7], [1, 3, 0, 1, 4, 2], [1, 3, 0, 1, 5, 6], [1, 3, 0, 1, 6, 1], [1, 3, 0, 1, 7, 5], [1, 3, 0, 1, 8, 0], [1, 3, 0, 2, 0, 6], [1, 3, 0, 2, 1, 1], [1, 3, 0, 2, 2, 5], [1, 3, 0, 2, 3, 0], [1, 3, 0, 2, 4, 4], [1, 3, 0, 2, 5, 8], [1, 3, 0, 2, 6, 3], [1, 3, 0, 2, 7, 7], [1, 3, 0, 2, 8, 2], [1, 3, 0, 3, 0, 8], [1, 3, 0, 3, 1, 3], [1, 3, 0, 3, 2, 7], [1, 3, 0, 3, 3, 2], [1, 3, 0, 3, 4, 6], [1, 3, 0, 3, 5, 1], [1, 3, 0, 3, 6, 5], [1, 3, 0, 3, 7, 0], [1, 3, 0, 3, 8, 4], [1, 3, 0, 4, 0, 1], [1, 3, 0, 4, 1, 5], [1, 3, 0, 4, 2, 0], [1, 3, 0, 4, 3, 4], [1, 3, 0, 4, 4, 8], [1, 3, 0, 4, 5, 3], [1, 3, 0, 4, 6, 7], [1, 3, 0, 4, 7, 2], [1, 3, 0, 4, 8, 6], [1, 3, 0, 5, 0, 3], [1, 3, 0, 5, 1, 7], [1, 3, 0, 5, 2, 2], [1, 3, 0, 5, 3, 6], [1, 3, 0, 5, 4, 1], [1, 3, 0, 5, 5, 5], [1, 3, 0, 5, 6, 0], [1, 3, 0, 5, 7, 4], [1, 3, 0, 5, 8, 8], [1, 3, 0, 6, 0, 5], [1, 3, 0, 6, 1, 0], [1, 3, 0, 6, 2, 4], [1, 3, 0, 6, 3, 8], [1, 3, 0, 6, 4, 3], [1, 3, 0, 6, 5, 7], [1, 3, 0, 6, 6, 2], [1, 3, 0, 6, 7, 6], [1, 3, 0, 6, 8, 1], [1, 3, 0, 7, 0, 7], [1, 3, 0, 7, 1, 2], [1, 3, 0, 7, 2, 6], [1, 3, 0, 7, 3, 1], [1, 3, 0, 7, 4, 5], [1, 3, 0, 7, 5, 0], [1, 3, 0, 7, 6, 4], [1, 3, 0, 7, 7, 8], [1, 3, 0, 7, 8, 3], [1, 3, 0, 8, 0, 0], [1, 3, 0, 8, 1, 4], [1, 3, 0, 8, 2, 8], [1, 3, 0, 8, 3, 3], [1, 3, 0, 8, 4, 7], [1, 3, 0, 8, 5, 2], [1, 3, 0, 8, 6, 6], [1, 3, 0, 8, 7, 1], [1, 3, 0, 8, 8, 5], [1, 4, 4, 0, 0, 2], [1, 4, 4, 0, 1, 6], [1, 4, 4, 0, 2, 1], [1, 4, 4, 0, 3, 5], [1, 4, 4, 0, 4, 0], [1, 4, 4, 0, 5, 4], [1, 4, 4, 0, 6, 8], [1, 4, 4, 0, 7, 3], [1, 4, 4, 0, 8, 7], [1, 4, 4, 1, 0, 4], [1, 4, 4, 1, 1, 8], [1, 4, 4, 1, 2, 3], [1, 4, 4, 1, 3, 7], [1, 4, 4, 1, 4, 2], [1, 4, 4, 1, 5, 6], [1, 4, 4, 1, 6, 1], [1, 4, 4, 1, 7, 5], [1, 4, 4, 1, 8, 0], [1, 4, 4, 2, 0, 6], [1, 4, 4, 2, 1, 1], [1, 4, 4, 2, 2, 5], [1, 4, 4, 2, 3, 0], [1, 4, 4, 2, 4, 4], [1, 4, 4, 2, 5, 8], [1, 4, 4, 2, 6, 3], [1, 4, 4, 2, 7, 7], [1, 4, 4, 2, 8, 2], [1, 4, 4, 3, 0, 8], [1, 4, 4, 3, 1, 3], [1, 4, 4, 3, 2, 7], [1, 4, 4, 3, 3, 2], [1, 4, 4, 3, 4, 6], [1, 4, 4, 3, 5, 1], [1, 4, 4, 3, 6, 5], [1, 4, 4, 3, 7, 0], [1, 4, 4, 3, 8, 4], [1, 4, 4, 4, 0, 1], [1, 4, 4, 4, 1, 5], [1, 4, 4, 4, 2, 0], [1, 4, 4, 4, 3, 4], [1, 4, 4, 4, 4, 8], [1, 4, 4, 4, 5, 3], [1, 4, 4, 4, 6, 7], [1, 4, 4, 4, 7, 2], [1, 4, 4, 4, 8, 6], [1, 4, 4, 5, 0, 3], [1, 4, 4, 5, 1, 7], [1, 4, 4, 5, 2, 2], [1, 4, 4, 5, 3, 6], [1, 4, 4, 5, 4, 1], [1, 4, 4, 5, 5, 5], [1, 4, 4, 5, 6, 0], [1, 4, 4, 5, 7, 4], [1, 4, 4, 5, 8, 8], [1, 4, 4, 6, 0, 5], [1, 4, 4, 6, 1, 0], [1, 4, 4, 6, 2, 4], [1, 4, 4, 6, 3, 8], [1, 4, 4, 6, 4, 3], [1, 4, 4, 6, 5, 7], [1, 4, 4, 6, 6, 2], [1, 4, 4, 6, 7, 6], [1, 4, 4, 6, 8, 1], [1, 4, 4, 7, 0, 7], [1, 4, 4, 7, 1, 2], [1, 4, 4, 7, 2, 6], [1, 4, 4, 7, 3, 1], [1, 4, 4, 7, 4, 5], [1, 4, 4, 7, 5, 0], [1, 4, 4, 7, 6, 4], [1, 4, 4, 7, 7, 8], [1, 4, 4, 7, 8, 3], [1, 4, 4, 8, 0, 0], [1, 4, 4, 8, 1, 4], [1, 4, 4, 8, 2, 8], [1, 4, 4, 8, 3, 3], [1, 4, 4, 8, 4, 7], [1, 4, 4, 8, 5, 2], [1, 4, 4, 8, 6, 6], [1, 4, 4, 8, 7, 1], [1, 4, 4, 8, 8, 5], [1, 5, 8, 0, 0, 2], [1, 5, 8, 0, 1, 6], [1, 5, 8, 0, 2, 1], [1, 5, 8, 0, 3, 5], [1, 5, 8, 0, 4, 0], [1, 5, 8, 0, 5, 4], [1, 5, 8, 0, 6, 8], [1, 5, 8, 0, 7, 3], [1, 5, 8, 0, 8, 7], [1, 5, 8, 1, 0, 4], [1, 5, 8, 1, 1, 8], [1, 5, 8, 1, 2, 3], [1, 5, 8, 1, 3, 7], [1, 5, 8, 1, 4, 2], [1, 5, 8, 1, 5, 6], [1, 5, 8, 1, 6, 1], [1, 5, 8, 1, 7, 5], [1, 5, 8, 1, 8, 0], [1, 5, 8, 2, 0, 6], [1, 5, 8, 2, 1, 1], [1, 5, 8, 2, 2, 5], [1, 5, 8, 2, 3, 0], [1, 5, 8, 2, 4, 4], [1, 5, 8, 2, 5, 8], [1, 5, 8, 2, 6, 3], [1, 5, 8, 2, 7, 7], [1, 5, 8, 2, 8, 2], [1, 5, 8, 3, 0, 8], [1, 5, 8, 3, 1, 3], [1, 5, 8, 3, 2, 7], [1, 5, 8, 3, 3, 2], [1, 5, 8, 3, 4, 6], [1, 5, 8, 3, 5, 1], [1, 5, 8, 3, 6, 5], [1, 5, 8, 3, 7, 0], [1, 5, 8, 3, 8, 4], [1, 5, 8, 4, 0, 1], [1, 5, 8, 4, 1, 5], [1, 5, 8, 4, 2, 0], [1, 5, 8, 4, 3, 4], [1, 5, 8, 4, 4, 8], [1, 5, 8, 4, 5, 3], [1, 5, 8, 4, 6, 7], [1, 5, 8, 4, 7, 2], [1, 5, 8, 4, 8, 6], [1, 5, 8, 5, 0, 3], [1, 5, 8, 5, 1, 7], [1, 5, 8, 5, 2, 2], [1, 5, 8, 5, 3, 6], [1, 5, 8, 5, 4, 1], [1, 5, 8, 5, 5, 5], [1, 5, 8, 5, 6, 0], [1, 5, 8, 5, 7, 4], [1, 5, 8, 5, 8, 8], [1, 5, 8, 6, 0, 5], [1, 5, 8, 6, 1, 0], [1, 5, 8, 6, 2, 4], [1, 5, 8, 6, 3, 8], [1, 5, 8, 6, 4, 3], [1, 5, 8, 6, 5, 7], [1, 5, 8, 6, 6, 2], [1, 5, 8, 6, 7, 6], [1, 5, 8, 6, 8, 1], [1, 5, 8, 7, 0, 7], [1, 5, 8, 7, 1, 2], [1, 5, 8, 7, 2, 6], [1, 5, 8, 7, 3, 1], [1, 5, 8, 7, 4, 5], [1, 5, 8, 7, 5, 0], [1, 5, 8, 7, 6, 4], [1, 5, 8, 7, 7, 8], [1, 5, 8, 7, 8, 3], [1, 5, 8, 8, 0, 0], [1, 5, 8, 8, 1, 4], [1, 5, 8, 8, 2, 8], [1, 5, 8, 8, 3, 3], [1, 5, 8, 8, 4, 7], [1, 5, 8, 8, 5, 2], [1, 5, 8, 8, 6, 6], [1, 5, 8, 8, 7, 1], [1, 5, 8, 8, 8, 5], [1, 6, 3, 0, 0, 2], [1, 6, 3, 0, 1, 6], [1, 6, 3, 0, 2, 1], [1, 6, 3, 0, 3, 5], [1, 6, 3, 0, 4, 0], [1, 6, 3, 0, 5, 4], [1, 6, 3, 0, 6, 8], [1, 6, 3, 0, 7, 3], [1, 6, 3, 0, 8, 7], [1, 6, 3, 1, 0, 4], [1, 6, 3, 1, 1, 8], [1, 6, 3, 1, 2, 3], [1, 6, 3, 1, 3, 7], [1, 6, 3, 1, 4, 2], [1, 6, 3, 1, 5, 6], [1, 6, 3, 1, 6, 1], [1, 6, 3, 1, 7, 5], [1, 6, 3, 1, 8, 0], [1, 6, 3, 2, 0, 6], [1, 6, 3, 2, 1, 1], [1, 6, 3, 2, 2, 5], [1, 6, 3, 2, 3, 0], [1, 6, 3, 2, 4, 4], [1, 6, 3, 2, 5, 8], [1, 6, 3, 2, 6, 3], [1, 6, 3, 2, 7, 7], [1, 6, 3, 2, 8, 2], [1, 6, 3, 3, 0, 8], [1, 6, 3, 3, 1, 3], [1, 6, 3, 3, 2, 7], [1, 6, 3, 3, 3, 2], [1, 6, 3, 3, 4, 6], [1, 6, 3, 3, 5, 1], [1, 6, 3, 3, 6, 5], [1, 6, 3, 3, 7, 0], [1, 6, 3, 3, 8, 4], [1, 6, 3, 4, 0, 1], [1, 6, 3, 4, 1, 5], [1, 6, 3, 4, 2, 0], [1, 6, 3, 4, 3, 4], [1, 6, 3, 4, 4, 8], [1, 6, 3, 4, 5, 3], [1, 6, 3, 4, 6, 7], [1, 6, 3, 4, 7, 2], [1, 6, 3, 4, 8, 6], [1, 6, 3, 5, 0, 3], [1, 6, 3, 5, 1, 7], [1, 6, 3, 5, 2, 2], [1, 6, 3, 5, 3, 6], [1, 6, 3, 5, 4, 1], [1, 6, 3, 5, 5, 5], [1, 6, 3, 5, 6, 0], [1, 6, 3, 5, 7, 4], [1, 6, 3, 5, 8, 8], [1, 6, 3, 6, 0, 5], [1, 6, 3, 6, 1, 0], [1, 6, 3, 6, 2, 4], [1, 6, 3, 6, 3, 8], [1, 6, 3, 6, 4, 3], [1, 6, 3, 6, 5, 7], [1, 6, 3, 6, 6, 2], [1, 6, 3, 6, 7, 6], [1, 6, 3, 6, 8, 1], [1, 6, 3, 7, 0, 7], [1, 6, 3, 7, 1, 2], [1, 6, 3, 7, 2, 6], [1, 6, 3, 7, 3, 1], [1, 6, 3, 7, 4, 5], [1, 6, 3, 7, 5, 0], [1, 6, 3, 7, 6, 4], [1, 6, 3, 7, 7, 8], [1, 6, 3, 7, 8, 3], [1, 6, 3, 8, 0, 0], [1, 6, 3, 8, 1, 4], [1, 6, 3, 8, 2, 8], [1, 6, 3, 8, 3, 3], [1, 6, 3, 8, 4, 7], [1, 6, 3, 8, 5, 2], [1, 6, 3, 8, 6, 6], [1, 6, 3, 8, 7, 1], [1, 6, 3, 8, 8, 5], [1, 7, 7, 0, 0, 2], [1, 7, 7, 0, 1, 6], [1, 7, 7, 0, 2, 1], [1, 7, 7, 0, 3, 5], [1, 7, 7, 0, 4, 0], [1, 7, 7, 0, 5, 4], [1, 7, 7, 0, 6, 8], [1, 7, 7, 0, 7, 3], [1, 7, 7, 0, 8, 7], [1, 7, 7, 1, 0, 4], [1, 7, 7, 1, 1, 8], [1, 7, 7, 1, 2, 3], [1, 7, 7, 1, 3, 7], [1, 7, 7, 1, 4, 2], [1, 7, 7, 1, 5, 6], [1, 7, 7, 1, 6, 1], [1, 7, 7, 1, 7, 5], [1, 7, 7, 1, 8, 0], [1, 7, 7, 2, 0, 6], [1, 7, 7, 2, 1, 1], [1, 7, 7, 2, 2, 5], [1, 7, 7, 2, 3, 0], [1, 7, 7, 2, 4, 4], [1, 7, 7, 2, 5, 8], [1, 7, 7, 2, 6, 3], [1, 7, 7, 2, 7, 7], [1, 7, 7, 2, 8, 2], [1, 7, 7, 3, 0, 8], [1, 7, 7, 3, 1, 3], [1, 7, 7, 3, 2, 7], [1, 7, 7, 3, 3, 2], [1, 7, 7, 3, 4, 6], [1, 7, 7, 3, 5, 1], [1, 7, 7, 3, 6, 5], [1, 7, 7, 3, 7, 0], [1, 7, 7, 3, 8, 4], [1, 7, 7, 4, 0, 1], [1, 7, 7, 4, 1, 5], [1, 7, 7, 4, 2, 0], [1, 7, 7, 4, 3, 4], [1, 7, 7, 4, 4, 8], [1, 7, 7, 4, 5, 3], [1, 7, 7, 4, 6, 7], [1, 7, 7, 4, 7, 2], [1, 7, 7, 4, 8, 6], [1, 7, 7, 5, 0, 3], [1, 7, 7, 5, 1, 7], [1, 7, 7, 5, 2, 2], [1, 7, 7, 5, 3, 6], [1, 7, 7, 5, 4, 1], [1, 7, 7, 5, 5, 5], [1, 7, 7, 5, 6, 0], [1, 7, 7, 5, 7, 4], [1, 7, 7, 5, 8, 8], [1, 7, 7, 6, 0, 5], [1, 7, 7, 6, 1, 0], [1, 7, 7, 6, 2, 4], [1, 7, 7, 6, 3, 8], [1, 7, 7, 6, 4, 3], [1, 7, 7, 6, 5, 7], [1, 7, 7, 6, 6, 2], [1, 7, 7, 6, 7, 6], [1, 7, 7, 6, 8, 1], [1, 7, 7, 7, 0, 7], [1, 7, 7, 7, 1, 2], [1, 7, 7, 7, 2, 6], [1, 7, 7, 7, 3, 1], [1, 7, 7, 7, 4, 5], [1, 7, 7, 7, 5, 0], [1, 7, 7, 7, 6, 4], [1, 7, 7, 7, 7, 8], [1, 7, 7, 7, 8, 3], [1, 7, 7, 8, 0, 0], [1, 7, 7, 8, 1, 4], [1, 7, 7, 8, 2, 8], [1, 7, 7, 8, 3, 3], [1, 7, 7, 8, 4, 7], [1, 7, 7, 8, 5, 2], [1, 7, 7, 8, 6, 6], [1, 7, 7, 8, 7, 1], [1, 7, 7, 8, 8, 5], [1, 8, 2, 0, 0, 2], [1, 8, 2, 0, 1, 6], [1, 8, 2, 0, 2, 1], [1, 8, 2, 0, 3, 5], [1, 8, 2, 0, 4, 0], [1, 8, 2, 0, 5, 4], [1, 8, 2, 0, 6, 8], [1, 8, 2, 0, 7, 3], [1, 8, 2, 0, 8, 7], [1, 8, 2, 1, 0, 4], [1, 8, 2, 1, 1, 8], [1, 8, 2, 1, 2, 3], [1, 8, 2, 1, 3, 7], [1, 8, 2, 1, 4, 2], [1, 8, 2, 1, 5, 6], [1, 8, 2, 1, 6, 1], [1, 8, 2, 1, 7, 5], [1, 8, 2, 1, 8, 0], [1, 8, 2, 2, 0, 6], [1, 8, 2, 2, 1, 1], [1, 8, 2, 2, 2, 5], [1, 8, 2, 2, 3, 0], [1, 8, 2, 2, 4, 4], [1, 8, 2, 2, 5, 8], [1, 8, 2, 2, 6, 3], [1, 8, 2, 2, 7, 7], [1, 8, 2, 2, 8, 2], [1, 8, 2, 3, 0, 8], [1, 8, 2, 3, 1, 3], [1, 8, 2, 3, 2, 7], [1, 8, 2, 3, 3, 2], [1, 8, 2, 3, 4, 6], [1, 8, 2, 3, 5, 1], [1, 8, 2, 3, 6, 5], [1, 8, 2, 3, 7, 0], [1, 8, 2, 3, 8, 4], [1, 8, 2, 4, 0, 1], [1, 8, 2, 4, 1, 5], [1, 8, 2, 4, 2, 0], [1, 8, 2, 4, 3, 4], [1, 8, 2, 4, 4, 8], [1, 8, 2, 4, 5, 3], [1, 8, 2, 4, 6, 7], [1, 8, 2, 4, 7, 2], [1, 8, 2, 4, 8, 6], [1, 8, 2, 5, 0, 3], [1, 8, 2, 5, 1, 7], [1, 8, 2, 5, 2, 2], [1, 8, 2, 5, 3, 6], [1, 8, 2, 5, 4, 1], [1, 8, 2, 5, 5, 5], [1, 8, 2, 5, 6, 0], [1, 8, 2, 5, 7, 4], [1, 8, 2, 5, 8, 8], [1, 8, 2, 6, 0, 5], [1, 8, 2, 6, 1, 0], [1, 8, 2, 6, 2, 4], [1, 8, 2, 6, 3, 8], [1, 8, 2, 6, 4, 3], [1, 8, 2, 6, 5, 7], [1, 8, 2, 6, 6, 2], [1, 8, 2, 6, 7, 6], [1, 8, 2, 6, 8, 1], [1, 8, 2, 7, 0, 7], [1, 8, 2, 7, 1, 2], [1, 8, 2, 7, 2, 6], [1, 8, 2, 7, 3, 1], [1, 8, 2, 7, 4, 5], [1, 8, 2, 7, 5, 0], [1, 8, 2, 7, 6, 4], [1, 8, 2, 7, 7, 8], [1, 8, 2, 7, 8, 3], [1, 8, 2, 8, 0, 0], [1, 8, 2, 8, 1, 4], [1, 8, 2, 8, 2, 8], [1, 8, 2, 8, 3, 3], [1, 8, 2, 8, 4, 7], [1, 8, 2, 8, 5, 2], [1, 8, 2, 8, 6, 6], [1, 8, 2, 8, 7, 1], [1, 8, 2, 8, 8, 5], [2, 0, 8, 0, 0, 2], [2, 0, 8, 0, 1, 6], [2, 0, 8, 0, 2, 1], [2, 0, 8, 0, 3, 5], [2, 0, 8, 0, 4, 0], [2, 0, 8, 0, 5, 4], [2, 0, 8, 0, 6, 8], [2, 0, 8, 0, 7, 3], [2, 0, 8, 0, 8, 7], [2, 0, 8, 1, 0, 4], [2, 0, 8, 1, 1, 8], [2, 0, 8, 1, 2, 3], [2, 0, 8, 1, 3, 7], [2, 0, 8, 1, 4, 2], [2, 0, 8, 1, 5, 6], [2, 0, 8, 1, 6, 1], [2, 0, 8, 1, 7, 5], [2, 0, 8, 1, 8, 0], [2, 0, 8, 2, 0, 6], [2, 0, 8, 2, 1, 1], [2, 0, 8, 2, 2, 5], [2, 0, 8, 2, 3, 0], [2, 0, 8, 2, 4, 4], [2, 0, 8, 2, 5, 8], [2, 0, 8, 2, 6, 3], [2, 0, 8, 2, 7, 7], [2, 0, 8, 2, 8, 2], [2, 0, 8, 3, 0, 8], [2, 0, 8, 3, 1, 3], [2, 0, 8, 3, 2, 7], [2, 0, 8, 3, 3, 2], [2, 0, 8, 3, 4, 6], [2, 0, 8, 3, 5, 1], [2, 0, 8, 3, 6, 5], [2, 0, 8, 3, 7, 0], [2, 0, 8, 3, 8, 4], [2, 0, 8, 4, 0, 1], [2, 0, 8, 4, 1, 5], [2, 0, 8, 4, 2, 0], [2, 0, 8, 4, 3, 4], [2, 0, 8, 4, 4, 8], [2, 0, 8, 4, 5, 3], [2, 0, 8, 4, 6, 7], [2, 0, 8, 4, 7, 2], [2, 0, 8, 4, 8, 6], [2, 0, 8, 5, 0, 3], [2, 0, 8, 5, 1, 7], [2, 0, 8, 5, 2, 2], [2, 0, 8, 5, 3, 6], [2, 0, 8, 5, 4, 1], [2, 0, 8, 5, 5, 5], [2, 0, 8, 5, 6, 0], [2, 0, 8, 5, 7, 4], [2, 0, 8, 5, 8, 8], [2, 0, 8, 6, 0, 5], [2, 0, 8, 6, 1, 0], [2, 0, 8, 6, 2, 4], [2, 0, 8, 6, 3, 8], [2, 0, 8, 6, 4, 3], [2, 0, 8, 6, 5, 7], [2, 0, 8, 6, 6, 2], [2, 0, 8, 6, 7, 6], [2, 0, 8, 6, 8, 1], [2, 0, 8, 7, 0, 7], [2, 0, 8, 7, 1, 2], [2, 0, 8, 7, 2, 6], [2, 0, 8, 7, 3, 1], [2, 0, 8, 7, 4, 5], [2, 0, 8, 7, 5, 0], [2, 0, 8, 7, 6, 4], [2, 0, 8, 7, 7, 8], [2, 0, 8, 7, 8, 3], [2, 0, 8, 8, 0, 0], [2, 0, 8, 8, 1, 4], [2, 0, 8, 8, 2, 8], [2, 0, 8, 8, 3, 3], [2, 0, 8, 8, 4, 7], [2, 0, 8, 8, 5, 2], [2, 0, 8, 8, 6, 6], [2, 0, 8, 8, 7, 1], [2, 0, 8, 8, 8, 5], [2, 1, 3, 0, 0, 2], [2, 1, 3, 0, 1, 6], [2, 1, 3, 0, 2, 1], [2, 1, 3, 0, 3, 5], [2, 1, 3, 0, 4, 0], [2, 1, 3, 0, 5, 4], [2, 1, 3, 0, 6, 8], [2, 1, 3, 0, 7, 3], [2, 1, 3, 0, 8, 7], [2, 1, 3, 1, 0, 4], [2, 1, 3, 1, 1, 8], [2, 1, 3, 1, 2, 3], [2, 1, 3, 1, 3, 7], [2, 1, 3, 1, 4, 2], [2, 1, 3, 1, 5, 6], [2, 1, 3, 1, 6, 1], [2, 1, 3, 1, 7, 5], [2, 1, 3, 1, 8, 0], [2, 1, 3, 2, 0, 6], [2, 1, 3, 2, 1, 1], [2, 1, 3, 2, 2, 5], [2, 1, 3, 2, 3, 0], [2, 1, 3, 2, 4, 4], [2, 1, 3, 2, 5, 8], [2, 1, 3, 2, 6, 3], [2, 1, 3, 2, 7, 7], [2, 1, 3, 2, 8, 2], [2, 1, 3, 3, 0, 8], [2, 1, 3, 3, 1, 3], [2, 1, 3, 3, 2, 7], [2, 1, 3, 3, 3, 2], [2, 1, 3, 3, 4, 6], [2, 1, 3, 3, 5, 1], [2, 1, 3, 3, 6, 5], [2, 1, 3, 3, 7, 0], [2, 1, 3, 3, 8, 4], [2, 1, 3, 4, 0, 1], [2, 1, 3, 4, 1, 5], [2, 1, 3, 4, 2, 0], [2, 1, 3, 4, 3, 4], [2, 1, 3, 4, 4, 8], [2, 1, 3, 4, 5, 3], [2, 1, 3, 4, 6, 7], [2, 1, 3, 4, 7, 2], [2, 1, 3, 4, 8, 6], [2, 1, 3, 5, 0, 3], [2, 1, 3, 5, 1, 7], [2, 1, 3, 5, 2, 2], [2, 1, 3, 5, 3, 6], [2, 1, 3, 5, 4, 1], [2, 1, 3, 5, 5, 5], [2, 1, 3, 5, 6, 0], [2, 1, 3, 5, 7, 4], [2, 1, 3, 5, 8, 8], [2, 1, 3, 6, 0, 5], [2, 1, 3, 6, 1, 0], [2, 1, 3, 6, 2, 4], [2, 1, 3, 6, 3, 8], [2, 1, 3, 6, 4, 3], [2, 1, 3, 6, 5, 7], [2, 1, 3, 6, 6, 2], [2, 1, 3, 6, 7, 6], [2, 1, 3, 6, 8, 1], [2, 1, 3, 7, 0, 7], [2, 1, 3, 7, 1, 2], [2, 1, 3, 7, 2, 6], [2, 1, 3, 7, 3, 1], [2, 1, 3, 7, 4, 5], [2, 1, 3, 7, 5, 0], [2, 1, 3, 7, 6, 4], [2, 1, 3, 7, 7, 8], [2, 1, 3, 7, 8, 3], [2, 1, 3, 8, 0, 0], [2, 1, 3, 8, 1, 4], [2, 1, 3, 8, 2, 8], [2, 1, 3, 8, 3, 3], [2, 1, 3, 8, 4, 7], [2, 1, 3, 8, 5, 2], [2, 1, 3, 8, 6, 6], [2, 1, 3, 8, 7, 1], [2, 1, 3, 8, 8, 5], [2, 2, 7, 0, 0, 2], [2, 2, 7, 0, 1, 6], [2, 2, 7, 0, 2, 1], [2, 2, 7, 0, 3, 5], [2, 2, 7, 0, 4, 0], [2, 2, 7, 0, 5, 4], [2, 2, 7, 0, 6, 8], [2, 2, 7, 0, 7, 3], [2, 2, 7, 0, 8, 7], [2, 2, 7, 1, 0, 4], [2, 2, 7, 1, 1, 8], [2, 2, 7, 1, 2, 3], [2, 2, 7, 1, 3, 7], [2, 2, 7, 1, 4, 2], [2, 2, 7, 1, 5, 6], [2, 2, 7, 1, 6, 1], [2, 2, 7, 1, 7, 5], [2, 2, 7, 1, 8, 0], [2, 2, 7, 2, 0, 6], [2, 2, 7, 2, 1, 1], [2, 2, 7, 2, 2, 5], [2, 2, 7, 2, 3, 0], [2, 2, 7, 2, 4, 4], [2, 2, 7, 2, 5, 8], [2, 2, 7, 2, 6, 3], [2, 2, 7, 2, 7, 7], [2, 2, 7, 2, 8, 2], [2, 2, 7, 3, 0, 8], [2, 2, 7, 3, 1, 3], [2, 2, 7, 3, 2, 7], [2, 2, 7, 3, 3, 2], [2, 2, 7, 3, 4, 6], [2, 2, 7, 3, 5, 1], [2, 2, 7, 3, 6, 5], [2, 2, 7, 3, 7, 0], [2, 2, 7, 3, 8, 4], [2, 2, 7, 4, 0, 1], [2, 2, 7, 4, 1, 5], [2, 2, 7, 4, 2, 0], [2, 2, 7, 4, 3, 4], [2, 2, 7, 4, 4, 8], [2, 2, 7, 4, 5, 3], [2, 2, 7, 4, 6, 7], [2, 2, 7, 4, 7, 2], [2, 2, 7, 4, 8, 6], [2, 2, 7, 5, 0, 3], [2, 2, 7, 5, 1, 7], [2, 2, 7, 5, 2, 2], [2, 2, 7, 5, 3, 6], [2, 2, 7, 5, 4, 1], [2, 2, 7, 5, 5, 5], [2, 2, 7, 5, 6, 0], [2, 2, 7, 5, 7, 4], [2, 2, 7, 5, 8, 8], [2, 2, 7, 6, 0, 5], [2, 2, 7, 6, 1, 0], [2, 2, 7, 6, 2, 4], [2, 2, 7, 6, 3, 8], [2, 2, 7, 6, 4, 3], [2, 2, 7, 6, 5, 7], [2, 2, 7, 6, 6, 2], [2, 2, 7, 6, 7, 6], [2, 2, 7, 6, 8, 1], [2, 2, 7, 7, 0, 7], [2, 2, 7, 7, 1, 2], [2, 2, 7, 7, 2, 6], [2, 2, 7, 7, 3, 1], [2, 2, 7, 7, 4, 5], [2, 2, 7, 7, 5, 0], [2, 2, 7, 7, 6, 4], [2, 2, 7, 7, 7, 8], [2, 2, 7, 7, 8, 3], [2, 2, 7, 8, 0, 0], [2, 2, 7, 8, 1, 4], [2, 2, 7, 8, 2, 8], [2, 2, 7, 8, 3, 3], [2, 2, 7, 8, 4, 7], [2, 2, 7, 8, 5, 2], [2, 2, 7, 8, 6, 6], [2, 2, 7, 8, 7, 1], [2, 2, 7, 8, 8, 5], [2, 3, 2, 0, 0, 2], [2, 3, 2, 0, 1, 6], [2, 3, 2, 0, 2, 1], [2, 3, 2, 0, 3, 5], [2, 3, 2, 0, 4, 0], [2, 3, 2, 0, 5, 4], [2, 3, 2, 0, 6, 8], [2, 3, 2, 0, 7, 3], [2, 3, 2, 0, 8, 7], [2, 3, 2, 1, 0, 4], [2, 3, 2, 1, 1, 8], [2, 3, 2, 1, 2, 3], [2, 3, 2, 1, 3, 7], [2, 3, 2, 1, 4, 2], [2, 3, 2, 1, 5, 6], [2, 3, 2, 1, 6, 1], [2, 3, 2, 1, 7, 5], [2, 3, 2, 1, 8, 0], [2, 3, 2, 2, 0, 6], [2, 3, 2, 2, 1, 1], [2, 3, 2, 2, 2, 5], [2, 3, 2, 2, 3, 0], [2, 3, 2, 2, 4, 4], [2, 3, 2, 2, 5, 8], [2, 3, 2, 2, 6, 3], [2, 3, 2, 2, 7, 7], [2, 3, 2, 2, 8, 2], [2, 3, 2, 3, 0, 8], [2, 3, 2, 3, 1, 3], [2, 3, 2, 3, 2, 7], [2, 3, 2, 3, 3, 2], [2, 3, 2, 3, 4, 6], [2, 3, 2, 3, 5, 1], [2, 3, 2, 3, 6, 5], [2, 3, 2, 3, 7, 0], [2, 3, 2, 3, 8, 4], [2, 3, 2, 4, 0, 1], [2, 3, 2, 4, 1, 5], [2, 3, 2, 4, 2, 0], [2, 3, 2, 4, 3, 4], [2, 3, 2, 4, 4, 8], [2, 3, 2, 4, 5, 3], [2, 3, 2, 4, 6, 7], [2, 3, 2, 4, 7, 2], [2, 3, 2, 4, 8, 6], [2, 3, 2, 5, 0, 3], [2, 3, 2, 5, 1, 7], [2, 3, 2, 5, 2, 2], [2, 3, 2, 5, 3, 6], [2, 3, 2, 5, 4, 1], [2, 3, 2, 5, 5, 5], [2, 3, 2, 5, 6, 0], [2, 3, 2, 5, 7, 4], [2, 3, 2, 5, 8, 8], [2, 3, 2, 6, 0, 5], [2, 3, 2, 6, 1, 0], [2, 3, 2, 6, 2, 4], [2, 3, 2, 6, 3, 8], [2, 3, 2, 6, 4, 3], [2, 3, 2, 6, 5, 7], [2, 3, 2, 6, 6, 2], [2, 3, 2, 6, 7, 6], [2, 3, 2, 6, 8, 1], [2, 3, 2, 7, 0, 7], [2, 3, 2, 7, 1, 2], [2, 3, 2, 7, 2, 6], [2, 3, 2, 7, 3, 1], [2, 3, 2, 7, 4, 5], [2, 3, 2, 7, 5, 0], [2, 3, 2, 7, 6, 4], [2, 3, 2, 7, 7, 8], [2, 3, 2, 7, 8, 3], [2, 3, 2, 8, 0, 0], [2, 3, 2, 8, 1, 4], [2, 3, 2, 8, 2, 8], [2, 3, 2, 8, 3, 3], [2, 3, 2, 8, 4, 7], [2, 3, 2, 8, 5, 2], [2, 3, 2, 8, 6, 6], [2, 3, 2, 8, 7, 1], [2, 3, 2, 8, 8, 5], [2, 4, 6, 0, 0, 2], [2, 4, 6, 0, 1, 6], [2, 4, 6, 0, 2, 1], [2, 4, 6, 0, 3, 5], [2, 4, 6, 0, 4, 0], [2, 4, 6, 0, 5, 4], [2, 4, 6, 0, 6, 8], [2, 4, 6, 0, 7, 3], [2, 4, 6, 0, 8, 7], [2, 4, 6, 1, 0, 4], [2, 4, 6, 1, 1, 8], [2, 4, 6, 1, 2, 3], [2, 4, 6, 1, 3, 7], [2, 4, 6, 1, 4, 2], [2, 4, 6, 1, 5, 6], [2, 4, 6, 1, 6, 1], [2, 4, 6, 1, 7, 5], [2, 4, 6, 1, 8, 0], [2, 4, 6, 2, 0, 6], [2, 4, 6, 2, 1, 1], [2, 4, 6, 2, 2, 5], [2, 4, 6, 2, 3, 0], [2, 4, 6, 2, 4, 4], [2, 4, 6, 2, 5, 8], [2, 4, 6, 2, 6, 3], [2, 4, 6, 2, 7, 7], [2, 4, 6, 2, 8, 2], [2, 4, 6, 3, 0, 8], [2, 4, 6, 3, 1, 3], [2, 4, 6, 3, 2, 7], [2, 4, 6, 3, 3, 2], [2, 4, 6, 3, 4, 6], [2, 4, 6, 3, 5, 1], [2, 4, 6, 3, 6, 5], [2, 4, 6, 3, 7, 0], [2, 4, 6, 3, 8, 4], [2, 4, 6, 4, 0, 1], [2, 4, 6, 4, 1, 5], [2, 4, 6, 4, 2, 0], [2, 4, 6, 4, 3, 4], [2, 4, 6, 4, 4, 8], [2, 4, 6, 4, 5, 3], [2, 4, 6, 4, 6, 7], [2, 4, 6, 4, 7, 2], [2, 4, 6, 4, 8, 6], [2, 4, 6, 5, 0, 3], [2, 4, 6, 5, 1, 7], [2, 4, 6, 5, 2, 2], [2, 4, 6, 5, 3, 6], [2, 4, 6, 5, 4, 1], [2, 4, 6, 5, 5, 5], [2, 4, 6, 5, 6, 0], [2, 4, 6, 5, 7, 4], [2, 4, 6, 5, 8, 8], [2, 4, 6, 6, 0, 5], [2, 4, 6, 6, 1, 0], [2, 4, 6, 6, 2, 4], [2, 4, 6, 6, 3, 8], [2, 4, 6, 6, 4, 3], [2, 4, 6, 6, 5, 7], [2, 4, 6, 6, 6, 2], [2, 4, 6, 6, 7, 6], [2, 4, 6, 6, 8, 1], [2, 4, 6, 7, 0, 7], [2, 4, 6, 7, 1, 2], [2, 4, 6, 7, 2, 6], [2, 4, 6, 7, 3, 1], [2, 4, 6, 7, 4, 5], [2, 4, 6, 7, 5, 0], [2, 4, 6, 7, 6, 4], [2, 4, 6, 7, 7, 8], [2, 4, 6, 7, 8, 3], [2, 4, 6, 8, 0, 0], [2, 4, 6, 8, 1, 4], [2, 4, 6, 8, 2, 8], [2, 4, 6, 8, 3, 3], [2, 4, 6, 8, 4, 7], [2, 4, 6, 8, 5, 2], [2, 4, 6, 8, 6, 6], [2, 4, 6, 8, 7, 1], [2, 4, 6, 8, 8, 5], [2, 5, 1, 0, 0, 2], [2, 5, 1, 0, 1, 6], [2, 5, 1, 0, 2, 1], [2, 5, 1, 0, 3, 5], [2, 5, 1, 0, 4, 0], [2, 5, 1, 0, 5, 4], [2, 5, 1, 0, 6, 8], [2, 5, 1, 0, 7, 3], [2, 5, 1, 0, 8, 7], [2, 5, 1, 1, 0, 4], [2, 5, 1, 1, 1, 8], [2, 5, 1, 1, 2, 3], [2, 5, 1, 1, 3, 7], [2, 5, 1, 1, 4, 2], [2, 5, 1, 1, 5, 6], [2, 5, 1, 1, 6, 1], [2, 5, 1, 1, 7, 5], [2, 5, 1, 1, 8, 0], [2, 5, 1, 2, 0, 6], [2, 5, 1, 2, 1, 1], [2, 5, 1, 2, 2, 5], [2, 5, 1, 2, 3, 0], [2, 5, 1, 2, 4, 4], [2, 5, 1, 2, 5, 8], [2, 5, 1, 2, 6, 3], [2, 5, 1, 2, 7, 7], [2, 5, 1, 2, 8, 2], [2, 5, 1, 3, 0, 8], [2, 5, 1, 3, 1, 3], [2, 5, 1, 3, 2, 7], [2, 5, 1, 3, 3, 2], [2, 5, 1, 3, 4, 6], [2, 5, 1, 3, 5, 1], [2, 5, 1, 3, 6, 5], [2, 5, 1, 3, 7, 0], [2, 5, 1, 3, 8, 4], [2, 5, 1, 4, 0, 1], [2, 5, 1, 4, 1, 5], [2, 5, 1, 4, 2, 0], [2, 5, 1, 4, 3, 4], [2, 5, 1, 4, 4, 8], [2, 5, 1, 4, 5, 3], [2, 5, 1, 4, 6, 7], [2, 5, 1, 4, 7, 2], [2, 5, 1, 4, 8, 6], [2, 5, 1, 5, 0, 3], [2, 5, 1, 5, 1, 7], [2, 5, 1, 5, 2, 2], [2, 5, 1, 5, 3, 6], [2, 5, 1, 5, 4, 1], [2, 5, 1, 5, 5, 5], [2, 5, 1, 5, 6, 0], [2, 5, 1, 5, 7, 4], [2, 5, 1, 5, 8, 8], [2, 5, 1, 6, 0, 5], [2, 5, 1, 6, 1, 0], [2, 5, 1, 6, 2, 4], [2, 5, 1, 6, 3, 8], [2, 5, 1, 6, 4, 3], [2, 5, 1, 6, 5, 7], [2, 5, 1, 6, 6, 2], [2, 5, 1, 6, 7, 6], [2, 5, 1, 6, 8, 1], [2, 5, 1, 7, 0, 7], [2, 5, 1, 7, 1, 2], [2, 5, 1, 7, 2, 6], [2, 5, 1, 7, 3, 1], [2, 5, 1, 7, 4, 5], [2, 5, 1, 7, 5, 0], [2, 5, 1, 7, 6, 4], [2, 5, 1, 7, 7, 8], [2, 5, 1, 7, 8, 3], [2, 5, 1, 8, 0, 0], [2, 5, 1, 8, 1, 4], [2, 5, 1, 8, 2, 8], [2, 5, 1, 8, 3, 3], [2, 5, 1, 8, 4, 7], [2, 5, 1, 8, 5, 2], [2, 5, 1, 8, 6, 6], [2, 5, 1, 8, 7, 1], [2, 5, 1, 8, 8, 5], [2, 6, 5, 0, 0, 2], [2, 6, 5, 0, 1, 6], [2, 6, 5, 0, 2, 1], [2, 6, 5, 0, 3, 5], [2, 6, 5, 0, 4, 0], [2, 6, 5, 0, 5, 4], [2, 6, 5, 0, 6, 8], [2, 6, 5, 0, 7, 3], [2, 6, 5, 0, 8, 7], [2, 6, 5, 1, 0, 4], [2, 6, 5, 1, 1, 8], [2, 6, 5, 1, 2, 3], [2, 6, 5, 1, 3, 7], [2, 6, 5, 1, 4, 2], [2, 6, 5, 1, 5, 6], [2, 6, 5, 1, 6, 1], [2, 6, 5, 1, 7, 5], [2, 6, 5, 1, 8, 0], [2, 6, 5, 2, 0, 6], [2, 6, 5, 2, 1, 1], [2, 6, 5, 2, 2, 5], [2, 6, 5, 2, 3, 0], [2, 6, 5, 2, 4, 4], [2, 6, 5, 2, 5, 8], [2, 6, 5, 2, 6, 3], [2, 6, 5, 2, 7, 7], [2, 6, 5, 2, 8, 2], [2, 6, 5, 3, 0, 8], [2, 6, 5, 3, 1, 3], [2, 6, 5, 3, 2, 7], [2, 6, 5, 3, 3, 2], [2, 6, 5, 3, 4, 6], [2, 6, 5, 3, 5, 1], [2, 6, 5, 3, 6, 5], [2, 6, 5, 3, 7, 0], [2, 6, 5, 3, 8, 4], [2, 6, 5, 4, 0, 1], [2, 6, 5, 4, 1, 5], [2, 6, 5, 4, 2, 0], [2, 6, 5, 4, 3, 4], [2, 6, 5, 4, 4, 8], [2, 6, 5, 4, 5, 3], [2, 6, 5, 4, 6, 7], [2, 6, 5, 4, 7, 2], [2, 6, 5, 4, 8, 6], [2, 6, 5, 5, 0, 3], [2, 6, 5, 5, 1, 7], [2, 6, 5, 5, 2, 2], [2, 6, 5, 5, 3, 6], [2, 6, 5, 5, 4, 1], [2, 6, 5, 5, 5, 5], [2, 6, 5, 5, 6, 0], [2, 6, 5, 5, 7, 4], [2, 6, 5, 5, 8, 8], [2, 6, 5, 6, 0, 5], [2, 6, 5, 6, 1, 0], [2, 6, 5, 6, 2, 4], [2, 6, 5, 6, 3, 8], [2, 6, 5, 6, 4, 3], [2, 6, 5, 6, 5, 7], [2, 6, 5, 6, 6, 2], [2, 6, 5, 6, 7, 6], [2, 6, 5, 6, 8, 1], [2, 6, 5, 7, 0, 7], [2, 6, 5, 7, 1, 2], [2, 6, 5, 7, 2, 6], [2, 6, 5, 7, 3, 1], [2, 6, 5, 7, 4, 5], [2, 6, 5, 7, 5, 0], [2, 6, 5, 7, 6, 4], [2, 6, 5, 7, 7, 8], [2, 6, 5, 7, 8, 3], [2, 6, 5, 8, 0, 0], [2, 6, 5, 8, 1, 4], [2, 6, 5, 8, 2, 8], [2, 6, 5, 8, 3, 3], [2, 6, 5, 8, 4, 7], [2, 6, 5, 8, 5, 2], [2, 6, 5, 8, 6, 6], [2, 6, 5, 8, 7, 1], [2, 6, 5, 8, 8, 5], [2, 7, 0, 0, 0, 2], [2, 7, 0, 0, 1, 6], [2, 7, 0, 0, 2, 1], [2, 7, 0, 0, 3, 5], [2, 7, 0, 0, 4, 0], [2, 7, 0, 0, 5, 4], [2, 7, 0, 0, 6, 8], [2, 7, 0, 0, 7, 3], [2, 7, 0, 0, 8, 7], [2, 7, 0, 1, 0, 4], [2, 7, 0, 1, 1, 8], [2, 7, 0, 1, 2, 3], [2, 7, 0, 1, 3, 7], [2, 7, 0, 1, 4, 2], [2, 7, 0, 1, 5, 6], [2, 7, 0, 1, 6, 1], [2, 7, 0, 1, 7, 5], [2, 7, 0, 1, 8, 0], [2, 7, 0, 2, 0, 6], [2, 7, 0, 2, 1, 1], [2, 7, 0, 2, 2, 5], [2, 7, 0, 2, 3, 0], [2, 7, 0, 2, 4, 4], [2, 7, 0, 2, 5, 8], [2, 7, 0, 2, 6, 3], [2, 7, 0, 2, 7, 7], [2, 7, 0, 2, 8, 2], [2, 7, 0, 3, 0, 8], [2, 7, 0, 3, 1, 3], [2, 7, 0, 3, 2, 7], [2, 7, 0, 3, 3, 2], [2, 7, 0, 3, 4, 6], [2, 7, 0, 3, 5, 1], [2, 7, 0, 3, 6, 5], [2, 7, 0, 3, 7, 0], [2, 7, 0, 3, 8, 4], [2, 7, 0, 4, 0, 1], [2, 7, 0, 4, 1, 5], [2, 7, 0, 4, 2, 0], [2, 7, 0, 4, 3, 4], [2, 7, 0, 4, 4, 8], [2, 7, 0, 4, 5, 3], [2, 7, 0, 4, 6, 7], [2, 7, 0, 4, 7, 2], [2, 7, 0, 4, 8, 6], [2, 7, 0, 5, 0, 3], [2, 7, 0, 5, 1, 7], [2, 7, 0, 5, 2, 2], [2, 7, 0, 5, 3, 6], [2, 7, 0, 5, 4, 1], [2, 7, 0, 5, 5, 5], [2, 7, 0, 5, 6, 0], [2, 7, 0, 5, 7, 4], [2, 7, 0, 5, 8, 8], [2, 7, 0, 6, 0, 5], [2, 7, 0, 6, 1, 0], [2, 7, 0, 6, 2, 4], [2, 7, 0, 6, 3, 8], [2, 7, 0, 6, 4, 3], [2, 7, 0, 6, 5, 7], [2, 7, 0, 6, 6, 2], [2, 7, 0, 6, 7, 6], [2, 7, 0, 6, 8, 1], [2, 7, 0, 7, 0, 7], [2, 7, 0, 7, 1, 2], [2, 7, 0, 7, 2, 6], [2, 7, 0, 7, 3, 1], [2, 7, 0, 7, 4, 5], [2, 7, 0, 7, 5, 0], [2, 7, 0, 7, 6, 4], [2, 7, 0, 7, 7, 8], [2, 7, 0, 7, 8, 3], [2, 7, 0, 8, 0, 0], [2, 7, 0, 8, 1, 4], [2, 7, 0, 8, 2, 8], [2, 7, 0, 8, 3, 3], [2, 7, 0, 8, 4, 7], [2, 7, 0, 8, 5, 2], [2, 7, 0, 8, 6, 6], [2, 7, 0, 8, 7, 1], [2, 7, 0, 8, 8, 5], [2, 8, 4, 0, 0, 2], [2, 8, 4, 0, 1, 6], [2, 8, 4, 0, 2, 1], [2, 8, 4, 0, 3, 5], [2, 8, 4, 0, 4, 0], [2, 8, 4, 0, 5, 4], [2, 8, 4, 0, 6, 8], [2, 8, 4, 0, 7, 3], [2, 8, 4, 0, 8, 7], [2, 8, 4, 1, 0, 4], [2, 8, 4, 1, 1, 8], [2, 8, 4, 1, 2, 3], [2, 8, 4, 1, 3, 7], [2, 8, 4, 1, 4, 2], [2, 8, 4, 1, 5, 6], [2, 8, 4, 1, 6, 1], [2, 8, 4, 1, 7, 5], [2, 8, 4, 1, 8, 0], [2, 8, 4, 2, 0, 6], [2, 8, 4, 2, 1, 1], [2, 8, 4, 2, 2, 5], [2, 8, 4, 2, 3, 0], [2, 8, 4, 2, 4, 4], [2, 8, 4, 2, 5, 8], [2, 8, 4, 2, 6, 3], [2, 8, 4, 2, 7, 7], [2, 8, 4, 2, 8, 2], [2, 8, 4, 3, 0, 8], [2, 8, 4, 3, 1, 3], [2, 8, 4, 3, 2, 7], [2, 8, 4, 3, 3, 2], [2, 8, 4, 3, 4, 6], [2, 8, 4, 3, 5, 1], [2, 8, 4, 3, 6, 5], [2, 8, 4, 3, 7, 0], [2, 8, 4, 3, 8, 4], [2, 8, 4, 4, 0, 1], [2, 8, 4, 4, 1, 5], [2, 8, 4, 4, 2, 0], [2, 8, 4, 4, 3, 4], [2, 8, 4, 4, 4, 8], [2, 8, 4, 4, 5, 3], [2, 8, 4, 4, 6, 7], [2, 8, 4, 4, 7, 2], [2, 8, 4, 4, 8, 6], [2, 8, 4, 5, 0, 3], [2, 8, 4, 5, 1, 7], [2, 8, 4, 5, 2, 2], [2, 8, 4, 5, 3, 6], [2, 8, 4, 5, 4, 1], [2, 8, 4, 5, 5, 5], [2, 8, 4, 5, 6, 0], [2, 8, 4, 5, 7, 4], [2, 8, 4, 5, 8, 8], [2, 8, 4, 6, 0, 5], [2, 8, 4, 6, 1, 0], [2, 8, 4, 6, 2, 4], [2, 8, 4, 6, 3, 8], [2, 8, 4, 6, 4, 3], [2, 8, 4, 6, 5, 7], [2, 8, 4, 6, 6, 2], [2, 8, 4, 6, 7, 6], [2, 8, 4, 6, 8, 1], [2, 8, 4, 7, 0, 7], [2, 8, 4, 7, 1, 2], [2, 8, 4, 7, 2, 6], [2, 8, 4, 7, 3, 1], [2, 8, 4, 7, 4, 5], [2, 8, 4, 7, 5, 0], [2, 8, 4, 7, 6, 4], [2, 8, 4, 7, 7, 8], [2, 8, 4, 7, 8, 3], [2, 8, 4, 8, 0, 0], [2, 8, 4, 8, 1, 4], [2, 8, 4, 8, 2, 8], [2, 8, 4, 8, 3, 3], [2, 8, 4, 8, 4, 7], [2, 8, 4, 8, 5, 2], [2, 8, 4, 8, 6, 6], [2, 8, 4, 8, 7, 1], [2, 8, 4, 8, 8, 5], [3, 0, 1, 0, 0, 2], [3, 0, 1, 0, 1, 6], [3, 0, 1, 0, 2, 1], [3, 0, 1, 0, 3, 5], [3, 0, 1, 0, 4, 0], [3, 0, 1, 0, 5, 4], [3, 0, 1, 0, 6, 8], [3, 0, 1, 0, 7, 3], [3, 0, 1, 0, 8, 7], [3, 0, 1, 1, 0, 4], [3, 0, 1, 1, 1, 8], [3, 0, 1, 1, 2, 3], [3, 0, 1, 1, 3, 7], [3, 0, 1, 1, 4, 2], [3, 0, 1, 1, 5, 6], [3, 0, 1, 1, 6, 1], [3, 0, 1, 1, 7, 5], [3, 0, 1, 1, 8, 0], [3, 0, 1, 2, 0, 6], [3, 0, 1, 2, 1, 1], [3, 0, 1, 2, 2, 5], [3, 0, 1, 2, 3, 0], [3, 0, 1, 2, 4, 4], [3, 0, 1, 2, 5, 8], [3, 0, 1, 2, 6, 3], [3, 0, 1, 2, 7, 7], [3, 0, 1, 2, 8, 2], [3, 0, 1, 3, 0, 8], [3, 0, 1, 3, 1, 3], [3, 0, 1, 3, 2, 7], [3, 0, 1, 3, 3, 2], [3, 0, 1, 3, 4, 6], [3, 0, 1, 3, 5, 1], [3, 0, 1, 3, 6, 5], [3, 0, 1, 3, 7, 0], [3, 0, 1, 3, 8, 4], [3, 0, 1, 4, 0, 1], [3, 0, 1, 4, 1, 5], [3, 0, 1, 4, 2, 0], [3, 0, 1, 4, 3, 4], [3, 0, 1, 4, 4, 8], [3, 0, 1, 4, 5, 3], [3, 0, 1, 4, 6, 7], [3, 0, 1, 4, 7, 2], [3, 0, 1, 4, 8, 6], [3, 0, 1, 5, 0, 3], [3, 0, 1, 5, 1, 7], [3, 0, 1, 5, 2, 2], [3, 0, 1, 5, 3, 6], [3, 0, 1, 5, 4, 1], [3, 0, 1, 5, 5, 5], [3, 0, 1, 5, 6, 0], [3, 0, 1, 5, 7, 4], [3, 0, 1, 5, 8, 8], [3, 0, 1, 6, 0, 5], [3, 0, 1, 6, 1, 0], [3, 0, 1, 6, 2, 4], [3, 0, 1, 6, 3, 8], [3, 0, 1, 6, 4, 3], [3, 0, 1, 6, 5, 7], [3, 0, 1, 6, 6, 2], [3, 0, 1, 6, 7, 6], [3, 0, 1, 6, 8, 1], [3, 0, 1, 7, 0, 7], [3, 0, 1, 7, 1, 2], [3, 0, 1, 7, 2, 6], [3, 0, 1, 7, 3, 1], [3, 0, 1, 7, 4, 5], [3, 0, 1, 7, 5, 0], [3, 0, 1, 7, 6, 4], [3, 0, 1, 7, 7, 8], [3, 0, 1, 7, 8, 3], [3, 0, 1, 8, 0, 0], [3, 0, 1, 8, 1, 4], [3, 0, 1, 8, 2, 8], [3, 0, 1, 8, 3, 3], [3, 0, 1, 8, 4, 7], [3, 0, 1, 8, 5, 2], [3, 0, 1, 8, 6, 6], [3, 0, 1, 8, 7, 1], [3, 0, 1, 8, 8, 5], [3, 1, 5, 0, 0, 2], [3, 1, 5, 0, 1, 6], [3, 1, 5, 0, 2, 1], [3, 1, 5, 0, 3, 5], [3, 1, 5, 0, 4, 0], [3, 1, 5, 0, 5, 4], [3, 1, 5, 0, 6, 8], [3, 1, 5, 0, 7, 3], [3, 1, 5, 0, 8, 7], [3, 1, 5, 1, 0, 4], [3, 1, 5, 1, 1, 8], [3, 1, 5, 1, 2, 3], [3, 1, 5, 1, 3, 7], [3, 1, 5, 1, 4, 2], [3, 1, 5, 1, 5, 6], [3, 1, 5, 1, 6, 1], [3, 1, 5, 1, 7, 5], [3, 1, 5, 1, 8, 0], [3, 1, 5, 2, 0, 6], [3, 1, 5, 2, 1, 1], [3, 1, 5, 2, 2, 5], [3, 1, 5, 2, 3, 0], [3, 1, 5, 2, 4, 4], [3, 1, 5, 2, 5, 8], [3, 1, 5, 2, 6, 3], [3, 1, 5, 2, 7, 7], [3, 1, 5, 2, 8, 2], [3, 1, 5, 3, 0, 8], [3, 1, 5, 3, 1, 3], [3, 1, 5, 3, 2, 7], [3, 1, 5, 3, 3, 2], [3, 1, 5, 3, 4, 6], [3, 1, 5, 3, 5, 1], [3, 1, 5, 3, 6, 5], [3, 1, 5, 3, 7, 0], [3, 1, 5, 3, 8, 4], [3, 1, 5, 4, 0, 1], [3, 1, 5, 4, 1, 5], [3, 1, 5, 4, 2, 0], [3, 1, 5, 4, 3, 4], [3, 1, 5, 4, 4, 8], [3, 1, 5, 4, 5, 3], [3, 1, 5, 4, 6, 7], [3, 1, 5, 4, 7, 2], [3, 1, 5, 4, 8, 6], [3, 1, 5, 5, 0, 3], [3, 1, 5, 5, 1, 7], [3, 1, 5, 5, 2, 2], [3, 1, 5, 5, 3, 6], [3, 1, 5, 5, 4, 1], [3, 1, 5, 5, 5, 5], [3, 1, 5, 5, 6, 0], [3, 1, 5, 5, 7, 4], [3, 1, 5, 5, 8, 8], [3, 1, 5, 6, 0, 5], [3, 1, 5, 6, 1, 0], [3, 1, 5, 6, 2, 4], [3, 1, 5, 6, 3, 8], [3, 1, 5, 6, 4, 3], [3, 1, 5, 6, 5, 7], [3, 1, 5, 6, 6, 2], [3, 1, 5, 6, 7, 6], [3, 1, 5, 6, 8, 1], [3, 1, 5, 7, 0, 7], [3, 1, 5, 7, 1, 2], [3, 1, 5, 7, 2, 6], [3, 1, 5, 7, 3, 1], [3, 1, 5, 7, 4, 5], [3, 1, 5, 7, 5, 0], [3, 1, 5, 7, 6, 4], [3, 1, 5, 7, 7, 8], [3, 1, 5, 7, 8, 3], [3, 1, 5, 8, 0, 0], [3, 1, 5, 8, 1, 4], [3, 1, 5, 8, 2, 8], [3, 1, 5, 8, 3, 3], [3, 1, 5, 8, 4, 7], [3, 1, 5, 8, 5, 2], [3, 1, 5, 8, 6, 6], [3, 1, 5, 8, 7, 1], [3, 1, 5, 8, 8, 5], [3, 2, 0, 0, 0, 2], [3, 2, 0, 0, 1, 6], [3, 2, 0, 0, 2, 1], [3, 2, 0, 0, 3, 5], [3, 2, 0, 0, 4, 0], [3, 2, 0, 0, 5, 4], [3, 2, 0, 0, 6, 8], [3, 2, 0, 0, 7, 3], [3, 2, 0, 0, 8, 7], [3, 2, 0, 1, 0, 4], [3, 2, 0, 1, 1, 8], [3, 2, 0, 1, 2, 3], [3, 2, 0, 1, 3, 7], [3, 2, 0, 1, 4, 2], [3, 2, 0, 1, 5, 6], [3, 2, 0, 1, 6, 1], [3, 2, 0, 1, 7, 5], [3, 2, 0, 1, 8, 0], [3, 2, 0, 2, 0, 6], [3, 2, 0, 2, 1, 1], [3, 2, 0, 2, 2, 5], [3, 2, 0, 2, 3, 0], [3, 2, 0, 2, 4, 4], [3, 2, 0, 2, 5, 8], [3, 2, 0, 2, 6, 3], [3, 2, 0, 2, 7, 7], [3, 2, 0, 2, 8, 2], [3, 2, 0, 3, 0, 8], [3, 2, 0, 3, 1, 3], [3, 2, 0, 3, 2, 7], [3, 2, 0, 3, 3, 2], [3, 2, 0, 3, 4, 6], [3, 2, 0, 3, 5, 1], [3, 2, 0, 3, 6, 5], [3, 2, 0, 3, 7, 0], [3, 2, 0, 3, 8, 4], [3, 2, 0, 4, 0, 1], [3, 2, 0, 4, 1, 5], [3, 2, 0, 4, 2, 0], [3, 2, 0, 4, 3, 4], [3, 2, 0, 4, 4, 8], [3, 2, 0, 4, 5, 3], [3, 2, 0, 4, 6, 7], [3, 2, 0, 4, 7, 2], [3, 2, 0, 4, 8, 6], [3, 2, 0, 5, 0, 3], [3, 2, 0, 5, 1, 7], [3, 2, 0, 5, 2, 2], [3, 2, 0, 5, 3, 6], [3, 2, 0, 5, 4, 1], [3, 2, 0, 5, 5, 5], [3, 2, 0, 5, 6, 0], [3, 2, 0, 5, 7, 4], [3, 2, 0, 5, 8, 8], [3, 2, 0, 6, 0, 5], [3, 2, 0, 6, 1, 0], [3, 2, 0, 6, 2, 4], [3, 2, 0, 6, 3, 8], [3, 2, 0, 6, 4, 3], [3, 2, 0, 6, 5, 7], [3, 2, 0, 6, 6, 2], [3, 2, 0, 6, 7, 6], [3, 2, 0, 6, 8, 1], [3, 2, 0, 7, 0, 7], [3, 2, 0, 7, 1, 2], [3, 2, 0, 7, 2, 6], [3, 2, 0, 7, 3, 1], [3, 2, 0, 7, 4, 5], [3, 2, 0, 7, 5, 0], [3, 2, 0, 7, 6, 4], [3, 2, 0, 7, 7, 8], [3, 2, 0, 7, 8, 3], [3, 2, 0, 8, 0, 0], [3, 2, 0, 8, 1, 4], [3, 2, 0, 8, 2, 8], [3, 2, 0, 8, 3, 3], [3, 2, 0, 8, 4, 7], [3, 2, 0, 8, 5, 2], [3, 2, 0, 8, 6, 6], [3, 2, 0, 8, 7, 1], [3, 2, 0, 8, 8, 5], [3, 3, 4, 0, 0, 2], [3, 3, 4, 0, 1, 6], [3, 3, 4, 0, 2, 1], [3, 3, 4, 0, 3, 5], [3, 3, 4, 0, 4, 0], [3, 3, 4, 0, 5, 4], [3, 3, 4, 0, 6, 8], [3, 3, 4, 0, 7, 3], [3, 3, 4, 0, 8, 7], [3, 3, 4, 1, 0, 4], [3, 3, 4, 1, 1, 8], [3, 3, 4, 1, 2, 3], [3, 3, 4, 1, 3, 7], [3, 3, 4, 1, 4, 2], [3, 3, 4, 1, 5, 6], [3, 3, 4, 1, 6, 1], [3, 3, 4, 1, 7, 5], [3, 3, 4, 1, 8, 0], [3, 3, 4, 2, 0, 6], [3, 3, 4, 2, 1, 1], [3, 3, 4, 2, 2, 5], [3, 3, 4, 2, 3, 0], [3, 3, 4, 2, 4, 4], [3, 3, 4, 2, 5, 8], [3, 3, 4, 2, 6, 3], [3, 3, 4, 2, 7, 7], [3, 3, 4, 2, 8, 2], [3, 3, 4, 3, 0, 8], [3, 3, 4, 3, 1, 3], [3, 3, 4, 3, 2, 7], [3, 3, 4, 3, 3, 2], [3, 3, 4, 3, 4, 6], [3, 3, 4, 3, 5, 1], [3, 3, 4, 3, 6, 5], [3, 3, 4, 3, 7, 0], [3, 3, 4, 3, 8, 4], [3, 3, 4, 4, 0, 1], [3, 3, 4, 4, 1, 5], [3, 3, 4, 4, 2, 0], [3, 3, 4, 4, 3, 4], [3, 3, 4, 4, 4, 8], [3, 3, 4, 4, 5, 3], [3, 3, 4, 4, 6, 7], [3, 3, 4, 4, 7, 2], [3, 3, 4, 4, 8, 6], [3, 3, 4, 5, 0, 3], [3, 3, 4, 5, 1, 7], [3, 3, 4, 5, 2, 2], [3, 3, 4, 5, 3, 6], [3, 3, 4, 5, 4, 1], [3, 3, 4, 5, 5, 5], [3, 3, 4, 5, 6, 0], [3, 3, 4, 5, 7, 4], [3, 3, 4, 5, 8, 8], [3, 3, 4, 6, 0, 5], [3, 3, 4, 6, 1, 0], [3, 3, 4, 6, 2, 4], [3, 3, 4, 6, 3, 8], [3, 3, 4, 6, 4, 3], [3, 3, 4, 6, 5, 7], [3, 3, 4, 6, 6, 2], [3, 3, 4, 6, 7, 6], [3, 3, 4, 6, 8, 1], [3, 3, 4, 7, 0, 7], [3, 3, 4, 7, 1, 2], [3, 3, 4, 7, 2, 6], [3, 3, 4, 7, 3, 1], [3, 3, 4, 7, 4, 5], [3, 3, 4, 7, 5, 0], [3, 3, 4, 7, 6, 4], [3, 3, 4, 7, 7, 8], [3, 3, 4, 7, 8, 3], [3, 3, 4, 8, 0, 0], [3, 3, 4, 8, 1, 4], [3, 3, 4, 8, 2, 8], [3, 3, 4, 8, 3, 3], [3, 3, 4, 8, 4, 7], [3, 3, 4, 8, 5, 2], [3, 3, 4, 8, 6, 6], [3, 3, 4, 8, 7, 1], [3, 3, 4, 8, 8, 5], [3, 4, 8, 0, 0, 2], [3, 4, 8, 0, 1, 6], [3, 4, 8, 0, 2, 1], [3, 4, 8, 0, 3, 5], [3, 4, 8, 0, 4, 0], [3, 4, 8, 0, 5, 4], [3, 4, 8, 0, 6, 8], [3, 4, 8, 0, 7, 3], [3, 4, 8, 0, 8, 7], [3, 4, 8, 1, 0, 4], [3, 4, 8, 1, 1, 8], [3, 4, 8, 1, 2, 3], [3, 4, 8, 1, 3, 7], [3, 4, 8, 1, 4, 2], [3, 4, 8, 1, 5, 6], [3, 4, 8, 1, 6, 1], [3, 4, 8, 1, 7, 5], [3, 4, 8, 1, 8, 0], [3, 4, 8, 2, 0, 6], [3, 4, 8, 2, 1, 1], [3, 4, 8, 2, 2, 5], [3, 4, 8, 2, 3, 0], [3, 4, 8, 2, 4, 4], [3, 4, 8, 2, 5, 8], [3, 4, 8, 2, 6, 3], [3, 4, 8, 2, 7, 7], [3, 4, 8, 2, 8, 2], [3, 4, 8, 3, 0, 8], [3, 4, 8, 3, 1, 3], [3, 4, 8, 3, 2, 7], [3, 4, 8, 3, 3, 2], [3, 4, 8, 3, 4, 6], [3, 4, 8, 3, 5, 1], [3, 4, 8, 3, 6, 5], [3, 4, 8, 3, 7, 0], [3, 4, 8, 3, 8, 4], [3, 4, 8, 4, 0, 1], [3, 4, 8, 4, 1, 5], [3, 4, 8, 4, 2, 0], [3, 4, 8, 4, 3, 4], [3, 4, 8, 4, 4, 8], [3, 4, 8, 4, 5, 3], [3, 4, 8, 4, 6, 7], [3, 4, 8, 4, 7, 2], [3, 4, 8, 4, 8, 6], [3, 4, 8, 5, 0, 3], [3, 4, 8, 5, 1, 7], [3, 4, 8, 5, 2, 2], [3, 4, 8, 5, 3, 6], [3, 4, 8, 5, 4, 1], [3, 4, 8, 5, 5, 5], [3, 4, 8, 5, 6, 0], [3, 4, 8, 5, 7, 4], [3, 4, 8, 5, 8, 8], [3, 4, 8, 6, 0, 5], [3, 4, 8, 6, 1, 0], [3, 4, 8, 6, 2, 4], [3, 4, 8, 6, 3, 8], [3, 4, 8, 6, 4, 3], [3, 4, 8, 6, 5, 7], [3, 4, 8, 6, 6, 2], [3, 4, 8, 6, 7, 6], [3, 4, 8, 6, 8, 1], [3, 4, 8, 7, 0, 7], [3, 4, 8, 7, 1, 2], [3, 4, 8, 7, 2, 6], [3, 4, 8, 7, 3, 1], [3, 4, 8, 7, 4, 5], [3, 4, 8, 7, 5, 0], [3, 4, 8, 7, 6, 4], [3, 4, 8, 7, 7, 8], [3, 4, 8, 7, 8, 3], [3, 4, 8, 8, 0, 0], [3, 4, 8, 8, 1, 4], [3, 4, 8, 8, 2, 8], [3, 4, 8, 8, 3, 3], [3, 4, 8, 8, 4, 7], [3, 4, 8, 8, 5, 2], [3, 4, 8, 8, 6, 6], [3, 4, 8, 8, 7, 1], [3, 4, 8, 8, 8, 5], [3, 5, 3, 0, 0, 2], [3, 5, 3, 0, 1, 6], [3, 5, 3, 0, 2, 1], [3, 5, 3, 0, 3, 5], [3, 5, 3, 0, 4, 0], [3, 5, 3, 0, 5, 4], [3, 5, 3, 0, 6, 8], [3, 5, 3, 0, 7, 3], [3, 5, 3, 0, 8, 7], [3, 5, 3, 1, 0, 4], [3, 5, 3, 1, 1, 8], [3, 5, 3, 1, 2, 3], [3, 5, 3, 1, 3, 7], [3, 5, 3, 1, 4, 2], [3, 5, 3, 1, 5, 6], [3, 5, 3, 1, 6, 1], [3, 5, 3, 1, 7, 5], [3, 5, 3, 1, 8, 0], [3, 5, 3, 2, 0, 6], [3, 5, 3, 2, 1, 1], [3, 5, 3, 2, 2, 5], [3, 5, 3, 2, 3, 0], [3, 5, 3, 2, 4, 4], [3, 5, 3, 2, 5, 8], [3, 5, 3, 2, 6, 3], [3, 5, 3, 2, 7, 7], [3, 5, 3, 2, 8, 2], [3, 5, 3, 3, 0, 8], [3, 5, 3, 3, 1, 3], [3, 5, 3, 3, 2, 7], [3, 5, 3, 3, 3, 2], [3, 5, 3, 3, 4, 6], [3, 5, 3, 3, 5, 1], [3, 5, 3, 3, 6, 5], [3, 5, 3, 3, 7, 0], [3, 5, 3, 3, 8, 4], [3, 5, 3, 4, 0, 1], [3, 5, 3, 4, 1, 5], [3, 5, 3, 4, 2, 0], [3, 5, 3, 4, 3, 4], [3, 5, 3, 4, 4, 8], [3, 5, 3, 4, 5, 3], [3, 5, 3, 4, 6, 7], [3, 5, 3, 4, 7, 2], [3, 5, 3, 4, 8, 6], [3, 5, 3, 5, 0, 3], [3, 5, 3, 5, 1, 7], [3, 5, 3, 5, 2, 2], [3, 5, 3, 5, 3, 6], [3, 5, 3, 5, 4, 1], [3, 5, 3, 5, 5, 5], [3, 5, 3, 5, 6, 0], [3, 5, 3, 5, 7, 4], [3, 5, 3, 5, 8, 8], [3, 5, 3, 6, 0, 5], [3, 5, 3, 6, 1, 0], [3, 5, 3, 6, 2, 4], [3, 5, 3, 6, 3, 8], [3, 5, 3, 6, 4, 3], [3, 5, 3, 6, 5, 7], [3, 5, 3, 6, 6, 2], [3, 5, 3, 6, 7, 6], [3, 5, 3, 6, 8, 1], [3, 5, 3, 7, 0, 7], [3, 5, 3, 7, 1, 2], [3, 5, 3, 7, 2, 6], [3, 5, 3, 7, 3, 1], [3, 5, 3, 7, 4, 5], [3, 5, 3, 7, 5, 0], [3, 5, 3, 7, 6, 4], [3, 5, 3, 7, 7, 8], [3, 5, 3, 7, 8, 3], [3, 5, 3, 8, 0, 0], [3, 5, 3, 8, 1, 4], [3, 5, 3, 8, 2, 8], [3, 5, 3, 8, 3, 3], [3, 5, 3, 8, 4, 7], [3, 5, 3, 8, 5, 2], [3, 5, 3, 8, 6, 6], [3, 5, 3, 8, 7, 1], [3, 5, 3, 8, 8, 5], [3, 6, 7, 0, 0, 2], [3, 6, 7, 0, 1, 6], [3, 6, 7, 0, 2, 1], [3, 6, 7, 0, 3, 5], [3, 6, 7, 0, 4, 0], [3, 6, 7, 0, 5, 4], [3, 6, 7, 0, 6, 8], [3, 6, 7, 0, 7, 3], [3, 6, 7, 0, 8, 7], [3, 6, 7, 1, 0, 4], [3, 6, 7, 1, 1, 8], [3, 6, 7, 1, 2, 3], [3, 6, 7, 1, 3, 7], [3, 6, 7, 1, 4, 2], [3, 6, 7, 1, 5, 6], [3, 6, 7, 1, 6, 1], [3, 6, 7, 1, 7, 5], [3, 6, 7, 1, 8, 0], [3, 6, 7, 2, 0, 6], [3, 6, 7, 2, 1, 1], [3, 6, 7, 2, 2, 5], [3, 6, 7, 2, 3, 0], [3, 6, 7, 2, 4, 4], [3, 6, 7, 2, 5, 8], [3, 6, 7, 2, 6, 3], [3, 6, 7, 2, 7, 7], [3, 6, 7, 2, 8, 2], [3, 6, 7, 3, 0, 8], [3, 6, 7, 3, 1, 3], [3, 6, 7, 3, 2, 7], [3, 6, 7, 3, 3, 2], [3, 6, 7, 3, 4, 6], [3, 6, 7, 3, 5, 1], [3, 6, 7, 3, 6, 5], [3, 6, 7, 3, 7, 0], [3, 6, 7, 3, 8, 4], [3, 6, 7, 4, 0, 1], [3, 6, 7, 4, 1, 5], [3, 6, 7, 4, 2, 0], [3, 6, 7, 4, 3, 4], [3, 6, 7, 4, 4, 8], [3, 6, 7, 4, 5, 3], [3, 6, 7, 4, 6, 7], [3, 6, 7, 4, 7, 2], [3, 6, 7, 4, 8, 6], [3, 6, 7, 5, 0, 3], [3, 6, 7, 5, 1, 7], [3, 6, 7, 5, 2, 2], [3, 6, 7, 5, 3, 6], [3, 6, 7, 5, 4, 1], [3, 6, 7, 5, 5, 5], [3, 6, 7, 5, 6, 0], [3, 6, 7, 5, 7, 4], [3, 6, 7, 5, 8, 8], [3, 6, 7, 6, 0, 5], [3, 6, 7, 6, 1, 0], [3, 6, 7, 6, 2, 4], [3, 6, 7, 6, 3, 8], [3, 6, 7, 6, 4, 3], [3, 6, 7, 6, 5, 7], [3, 6, 7, 6, 6, 2], [3, 6, 7, 6, 7, 6], [3, 6, 7, 6, 8, 1], [3, 6, 7, 7, 0, 7], [3, 6, 7, 7, 1, 2], [3, 6, 7, 7, 2, 6], [3, 6, 7, 7, 3, 1], [3, 6, 7, 7, 4, 5], [3, 6, 7, 7, 5, 0], [3, 6, 7, 7, 6, 4], [3, 6, 7, 7, 7, 8], [3, 6, 7, 7, 8, 3], [3, 6, 7, 8, 0, 0], [3, 6, 7, 8, 1, 4], [3, 6, 7, 8, 2, 8], [3, 6, 7, 8, 3, 3], [3, 6, 7, 8, 4, 7], [3, 6, 7, 8, 5, 2], [3, 6, 7, 8, 6, 6], [3, 6, 7, 8, 7, 1], [3, 6, 7, 8, 8, 5], [3, 7, 2, 0, 0, 2], [3, 7, 2, 0, 1, 6], [3, 7, 2, 0, 2, 1], [3, 7, 2, 0, 3, 5], [3, 7, 2, 0, 4, 0], [3, 7, 2, 0, 5, 4], [3, 7, 2, 0, 6, 8], [3, 7, 2, 0, 7, 3], [3, 7, 2, 0, 8, 7], [3, 7, 2, 1, 0, 4], [3, 7, 2, 1, 1, 8], [3, 7, 2, 1, 2, 3], [3, 7, 2, 1, 3, 7], [3, 7, 2, 1, 4, 2], [3, 7, 2, 1, 5, 6], [3, 7, 2, 1, 6, 1], [3, 7, 2, 1, 7, 5], [3, 7, 2, 1, 8, 0], [3, 7, 2, 2, 0, 6], [3, 7, 2, 2, 1, 1], [3, 7, 2, 2, 2, 5], [3, 7, 2, 2, 3, 0], [3, 7, 2, 2, 4, 4], [3, 7, 2, 2, 5, 8], [3, 7, 2, 2, 6, 3], [3, 7, 2, 2, 7, 7], [3, 7, 2, 2, 8, 2], [3, 7, 2, 3, 0, 8], [3, 7, 2, 3, 1, 3], [3, 7, 2, 3, 2, 7], [3, 7, 2, 3, 3, 2], [3, 7, 2, 3, 4, 6], [3, 7, 2, 3, 5, 1], [3, 7, 2, 3, 6, 5], [3, 7, 2, 3, 7, 0], [3, 7, 2, 3, 8, 4], [3, 7, 2, 4, 0, 1], [3, 7, 2, 4, 1, 5], [3, 7, 2, 4, 2, 0], [3, 7, 2, 4, 3, 4], [3, 7, 2, 4, 4, 8], [3, 7, 2, 4, 5, 3], [3, 7, 2, 4, 6, 7], [3, 7, 2, 4, 7, 2], [3, 7, 2, 4, 8, 6], [3, 7, 2, 5, 0, 3], [3, 7, 2, 5, 1, 7], [3, 7, 2, 5, 2, 2], [3, 7, 2, 5, 3, 6], [3, 7, 2, 5, 4, 1], [3, 7, 2, 5, 5, 5], [3, 7, 2, 5, 6, 0], [3, 7, 2, 5, 7, 4], [3, 7, 2, 5, 8, 8], [3, 7, 2, 6, 0, 5], [3, 7, 2, 6, 1, 0], [3, 7, 2, 6, 2, 4], [3, 7, 2, 6, 3, 8], [3, 7, 2, 6, 4, 3], [3, 7, 2, 6, 5, 7], [3, 7, 2, 6, 6, 2], [3, 7, 2, 6, 7, 6], [3, 7, 2, 6, 8, 1], [3, 7, 2, 7, 0, 7], [3, 7, 2, 7, 1, 2], [3, 7, 2, 7, 2, 6], [3, 7, 2, 7, 3, 1], [3, 7, 2, 7, 4, 5], [3, 7, 2, 7, 5, 0], [3, 7, 2, 7, 6, 4], [3, 7, 2, 7, 7, 8], [3, 7, 2, 7, 8, 3], [3, 7, 2, 8, 0, 0], [3, 7, 2, 8, 1, 4], [3, 7, 2, 8, 2, 8], [3, 7, 2, 8, 3, 3], [3, 7, 2, 8, 4, 7], [3, 7, 2, 8, 5, 2], [3, 7, 2, 8, 6, 6], [3, 7, 2, 8, 7, 1], [3, 7, 2, 8, 8, 5], [3, 8, 6, 0, 0, 2], [3, 8, 6, 0, 1, 6], [3, 8, 6, 0, 2, 1], [3, 8, 6, 0, 3, 5], [3, 8, 6, 0, 4, 0], [3, 8, 6, 0, 5, 4], [3, 8, 6, 0, 6, 8], [3, 8, 6, 0, 7, 3], [3, 8, 6, 0, 8, 7], [3, 8, 6, 1, 0, 4], [3, 8, 6, 1, 1, 8], [3, 8, 6, 1, 2, 3], [3, 8, 6, 1, 3, 7], [3, 8, 6, 1, 4, 2], [3, 8, 6, 1, 5, 6], [3, 8, 6, 1, 6, 1], [3, 8, 6, 1, 7, 5], [3, 8, 6, 1, 8, 0], [3, 8, 6, 2, 0, 6], [3, 8, 6, 2, 1, 1], [3, 8, 6, 2, 2, 5], [3, 8, 6, 2, 3, 0], [3, 8, 6, 2, 4, 4], [3, 8, 6, 2, 5, 8], [3, 8, 6, 2, 6, 3], [3, 8, 6, 2, 7, 7], [3, 8, 6, 2, 8, 2], [3, 8, 6, 3, 0, 8], [3, 8, 6, 3, 1, 3], [3, 8, 6, 3, 2, 7], [3, 8, 6, 3, 3, 2], [3, 8, 6, 3, 4, 6], [3, 8, 6, 3, 5, 1], [3, 8, 6, 3, 6, 5], [3, 8, 6, 3, 7, 0], [3, 8, 6, 3, 8, 4], [3, 8, 6, 4, 0, 1], [3, 8, 6, 4, 1, 5], [3, 8, 6, 4, 2, 0], [3, 8, 6, 4, 3, 4], [3, 8, 6, 4, 4, 8], [3, 8, 6, 4, 5, 3], [3, 8, 6, 4, 6, 7], [3, 8, 6, 4, 7, 2], [3, 8, 6, 4, 8, 6], [3, 8, 6, 5, 0, 3], [3, 8, 6, 5, 1, 7], [3, 8, 6, 5, 2, 2], [3, 8, 6, 5, 3, 6], [3, 8, 6, 5, 4, 1], [3, 8, 6, 5, 5, 5], [3, 8, 6, 5, 6, 0], [3, 8, 6, 5, 7, 4], [3, 8, 6, 5, 8, 8], [3, 8, 6, 6, 0, 5], [3, 8, 6, 6, 1, 0], [3, 8, 6, 6, 2, 4], [3, 8, 6, 6, 3, 8], [3, 8, 6, 6, 4, 3], [3, 8, 6, 6, 5, 7], [3, 8, 6, 6, 6, 2], [3, 8, 6, 6, 7, 6], [3, 8, 6, 6, 8, 1], [3, 8, 6, 7, 0, 7], [3, 8, 6, 7, 1, 2], [3, 8, 6, 7, 2, 6], [3, 8, 6, 7, 3, 1], [3, 8, 6, 7, 4, 5], [3, 8, 6, 7, 5, 0], [3, 8, 6, 7, 6, 4], [3, 8, 6, 7, 7, 8], [3, 8, 6, 7, 8, 3], [3, 8, 6, 8, 0, 0], [3, 8, 6, 8, 1, 4], [3, 8, 6, 8, 2, 8], [3, 8, 6, 8, 3, 3], [3, 8, 6, 8, 4, 7], [3, 8, 6, 8, 5, 2], [3, 8, 6, 8, 6, 6], [3, 8, 6, 8, 7, 1], [3, 8, 6, 8, 8, 5], [4, 0, 3, 0, 0, 2], [4, 0, 3, 0, 1, 6], [4, 0, 3, 0, 2, 1], [4, 0, 3, 0, 3, 5], [4, 0, 3, 0, 4, 0], [4, 0, 3, 0, 5, 4], [4, 0, 3, 0, 6, 8], [4, 0, 3, 0, 7, 3], [4, 0, 3, 0, 8, 7], [4, 0, 3, 1, 0, 4], [4, 0, 3, 1, 1, 8], [4, 0, 3, 1, 2, 3], [4, 0, 3, 1, 3, 7], [4, 0, 3, 1, 4, 2], [4, 0, 3, 1, 5, 6], [4, 0, 3, 1, 6, 1], [4, 0, 3, 1, 7, 5], [4, 0, 3, 1, 8, 0], [4, 0, 3, 2, 0, 6], [4, 0, 3, 2, 1, 1], [4, 0, 3, 2, 2, 5], [4, 0, 3, 2, 3, 0], [4, 0, 3, 2, 4, 4], [4, 0, 3, 2, 5, 8], [4, 0, 3, 2, 6, 3], [4, 0, 3, 2, 7, 7], [4, 0, 3, 2, 8, 2], [4, 0, 3, 3, 0, 8], [4, 0, 3, 3, 1, 3], [4, 0, 3, 3, 2, 7], [4, 0, 3, 3, 3, 2], [4, 0, 3, 3, 4, 6], [4, 0, 3, 3, 5, 1], [4, 0, 3, 3, 6, 5], [4, 0, 3, 3, 7, 0], [4, 0, 3, 3, 8, 4], [4, 0, 3, 4, 0, 1], [4, 0, 3, 4, 1, 5], [4, 0, 3, 4, 2, 0], [4, 0, 3, 4, 3, 4], [4, 0, 3, 4, 4, 8], [4, 0, 3, 4, 5, 3], [4, 0, 3, 4, 6, 7], [4, 0, 3, 4, 7, 2], [4, 0, 3, 4, 8, 6], [4, 0, 3, 5, 0, 3], [4, 0, 3, 5, 1, 7], [4, 0, 3, 5, 2, 2], [4, 0, 3, 5, 3, 6], [4, 0, 3, 5, 4, 1], [4, 0, 3, 5, 5, 5], [4, 0, 3, 5, 6, 0], [4, 0, 3, 5, 7, 4], [4, 0, 3, 5, 8, 8], [4, 0, 3, 6, 0, 5], [4, 0, 3, 6, 1, 0], [4, 0, 3, 6, 2, 4], [4, 0, 3, 6, 3, 8], [4, 0, 3, 6, 4, 3], [4, 0, 3, 6, 5, 7], [4, 0, 3, 6, 6, 2], [4, 0, 3, 6, 7, 6], [4, 0, 3, 6, 8, 1], [4, 0, 3, 7, 0, 7], [4, 0, 3, 7, 1, 2], [4, 0, 3, 7, 2, 6], [4, 0, 3, 7, 3, 1], [4, 0, 3, 7, 4, 5], [4, 0, 3, 7, 5, 0], [4, 0, 3, 7, 6, 4], [4, 0, 3, 7, 7, 8], [4, 0, 3, 7, 8, 3], [4, 0, 3, 8, 0, 0], [4, 0, 3, 8, 1, 4], [4, 0, 3, 8, 2, 8], [4, 0, 3, 8, 3, 3], [4, 0, 3, 8, 4, 7], [4, 0, 3, 8, 5, 2], [4, 0, 3, 8, 6, 6], [4, 0, 3, 8, 7, 1], [4, 0, 3, 8, 8, 5], [4, 1, 7, 0, 0, 2], [4, 1, 7, 0, 1, 6], [4, 1, 7, 0, 2, 1], [4, 1, 7, 0, 3, 5], [4, 1, 7, 0, 4, 0], [4, 1, 7, 0, 5, 4], [4, 1, 7, 0, 6, 8], [4, 1, 7, 0, 7, 3], [4, 1, 7, 0, 8, 7], [4, 1, 7, 1, 0, 4], [4, 1, 7, 1, 1, 8], [4, 1, 7, 1, 2, 3], [4, 1, 7, 1, 3, 7], [4, 1, 7, 1, 4, 2], [4, 1, 7, 1, 5, 6], [4, 1, 7, 1, 6, 1], [4, 1, 7, 1, 7, 5], [4, 1, 7, 1, 8, 0], [4, 1, 7, 2, 0, 6], [4, 1, 7, 2, 1, 1], [4, 1, 7, 2, 2, 5], [4, 1, 7, 2, 3, 0], [4, 1, 7, 2, 4, 4], [4, 1, 7, 2, 5, 8], [4, 1, 7, 2, 6, 3], [4, 1, 7, 2, 7, 7], [4, 1, 7, 2, 8, 2], [4, 1, 7, 3, 0, 8], [4, 1, 7, 3, 1, 3], [4, 1, 7, 3, 2, 7], [4, 1, 7, 3, 3, 2], [4, 1, 7, 3, 4, 6], [4, 1, 7, 3, 5, 1], [4, 1, 7, 3, 6, 5], [4, 1, 7, 3, 7, 0], [4, 1, 7, 3, 8, 4], [4, 1, 7, 4, 0, 1], [4, 1, 7, 4, 1, 5], [4, 1, 7, 4, 2, 0], [4, 1, 7, 4, 3, 4], [4, 1, 7, 4, 4, 8], [4, 1, 7, 4, 5, 3], [4, 1, 7, 4, 6, 7], [4, 1, 7, 4, 7, 2], [4, 1, 7, 4, 8, 6], [4, 1, 7, 5, 0, 3], [4, 1, 7, 5, 1, 7], [4, 1, 7, 5, 2, 2], [4, 1, 7, 5, 3, 6], [4, 1, 7, 5, 4, 1], [4, 1, 7, 5, 5, 5], [4, 1, 7, 5, 6, 0], [4, 1, 7, 5, 7, 4], [4, 1, 7, 5, 8, 8], [4, 1, 7, 6, 0, 5], [4, 1, 7, 6, 1, 0], [4, 1, 7, 6, 2, 4], [4, 1, 7, 6, 3, 8], [4, 1, 7, 6, 4, 3], [4, 1, 7, 6, 5, 7], [4, 1, 7, 6, 6, 2], [4, 1, 7, 6, 7, 6], [4, 1, 7, 6, 8, 1], [4, 1, 7, 7, 0, 7], [4, 1, 7, 7, 1, 2], [4, 1, 7, 7, 2, 6], [4, 1, 7, 7, 3, 1], [4, 1, 7, 7, 4, 5], [4, 1, 7, 7, 5, 0], [4, 1, 7, 7, 6, 4], [4, 1, 7, 7, 7, 8], [4, 1, 7, 7, 8, 3], [4, 1, 7, 8, 0, 0], [4, 1, 7, 8, 1, 4], [4, 1, 7, 8, 2, 8], [4, 1, 7, 8, 3, 3], [4, 1, 7, 8, 4, 7], [4, 1, 7, 8, 5, 2], [4, 1, 7, 8, 6, 6], [4, 1, 7, 8, 7, 1], [4, 1, 7, 8, 8, 5], [4, 2, 2, 0, 0, 2], [4, 2, 2, 0, 1, 6], [4, 2, 2, 0, 2, 1], [4, 2, 2, 0, 3, 5], [4, 2, 2, 0, 4, 0], [4, 2, 2, 0, 5, 4], [4, 2, 2, 0, 6, 8], [4, 2, 2, 0, 7, 3], [4, 2, 2, 0, 8, 7], [4, 2, 2, 1, 0, 4], [4, 2, 2, 1, 1, 8], [4, 2, 2, 1, 2, 3], [4, 2, 2, 1, 3, 7], [4, 2, 2, 1, 4, 2], [4, 2, 2, 1, 5, 6], [4, 2, 2, 1, 6, 1], [4, 2, 2, 1, 7, 5], [4, 2, 2, 1, 8, 0], [4, 2, 2, 2, 0, 6], [4, 2, 2, 2, 1, 1], [4, 2, 2, 2, 2, 5], [4, 2, 2, 2, 3, 0], [4, 2, 2, 2, 4, 4], [4, 2, 2, 2, 5, 8], [4, 2, 2, 2, 6, 3], [4, 2, 2, 2, 7, 7], [4, 2, 2, 2, 8, 2], [4, 2, 2, 3, 0, 8], [4, 2, 2, 3, 1, 3], [4, 2, 2, 3, 2, 7], [4, 2, 2, 3, 3, 2], [4, 2, 2, 3, 4, 6], [4, 2, 2, 3, 5, 1], [4, 2, 2, 3, 6, 5], [4, 2, 2, 3, 7, 0], [4, 2, 2, 3, 8, 4], [4, 2, 2, 4, 0, 1], [4, 2, 2, 4, 1, 5], [4, 2, 2, 4, 2, 0], [4, 2, 2, 4, 3, 4], [4, 2, 2, 4, 4, 8], [4, 2, 2, 4, 5, 3], [4, 2, 2, 4, 6, 7], [4, 2, 2, 4, 7, 2], [4, 2, 2, 4, 8, 6], [4, 2, 2, 5, 0, 3], [4, 2, 2, 5, 1, 7], [4, 2, 2, 5, 2, 2], [4, 2, 2, 5, 3, 6], [4, 2, 2, 5, 4, 1], [4, 2, 2, 5, 5, 5], [4, 2, 2, 5, 6, 0], [4, 2, 2, 5, 7, 4], [4, 2, 2, 5, 8, 8], [4, 2, 2, 6, 0, 5], [4, 2, 2, 6, 1, 0], [4, 2, 2, 6, 2, 4], [4, 2, 2, 6, 3, 8], [4, 2, 2, 6, 4, 3], [4, 2, 2, 6, 5, 7], [4, 2, 2, 6, 6, 2], [4, 2, 2, 6, 7, 6], [4, 2, 2, 6, 8, 1], [4, 2, 2, 7, 0, 7], [4, 2, 2, 7, 1, 2], [4, 2, 2, 7, 2, 6], [4, 2, 2, 7, 3, 1], [4, 2, 2, 7, 4, 5], [4, 2, 2, 7, 5, 0], [4, 2, 2, 7, 6, 4], [4, 2, 2, 7, 7, 8], [4, 2, 2, 7, 8, 3], [4, 2, 2, 8, 0, 0], [4, 2, 2, 8, 1, 4], [4, 2, 2, 8, 2, 8], [4, 2, 2, 8, 3, 3], [4, 2, 2, 8, 4, 7], [4, 2, 2, 8, 5, 2], [4, 2, 2, 8, 6, 6], [4, 2, 2, 8, 7, 1], [4, 2, 2, 8, 8, 5], [4, 3, 6, 0, 0, 2], [4, 3, 6, 0, 1, 6], [4, 3, 6, 0, 2, 1], [4, 3, 6, 0, 3, 5], [4, 3, 6, 0, 4, 0], [4, 3, 6, 0, 5, 4], [4, 3, 6, 0, 6, 8], [4, 3, 6, 0, 7, 3], [4, 3, 6, 0, 8, 7], [4, 3, 6, 1, 0, 4], [4, 3, 6, 1, 1, 8], [4, 3, 6, 1, 2, 3], [4, 3, 6, 1, 3, 7], [4, 3, 6, 1, 4, 2], [4, 3, 6, 1, 5, 6], [4, 3, 6, 1, 6, 1], [4, 3, 6, 1, 7, 5], [4, 3, 6, 1, 8, 0], [4, 3, 6, 2, 0, 6], [4, 3, 6, 2, 1, 1], [4, 3, 6, 2, 2, 5], [4, 3, 6, 2, 3, 0], [4, 3, 6, 2, 4, 4], [4, 3, 6, 2, 5, 8], [4, 3, 6, 2, 6, 3], [4, 3, 6, 2, 7, 7], [4, 3, 6, 2, 8, 2], [4, 3, 6, 3, 0, 8], [4, 3, 6, 3, 1, 3], [4, 3, 6, 3, 2, 7], [4, 3, 6, 3, 3, 2], [4, 3, 6, 3, 4, 6], [4, 3, 6, 3, 5, 1], [4, 3, 6, 3, 6, 5], [4, 3, 6, 3, 7, 0], [4, 3, 6, 3, 8, 4], [4, 3, 6, 4, 0, 1], [4, 3, 6, 4, 1, 5], [4, 3, 6, 4, 2, 0], [4, 3, 6, 4, 3, 4], [4, 3, 6, 4, 4, 8], [4, 3, 6, 4, 5, 3], [4, 3, 6, 4, 6, 7], [4, 3, 6, 4, 7, 2], [4, 3, 6, 4, 8, 6], [4, 3, 6, 5, 0, 3], [4, 3, 6, 5, 1, 7], [4, 3, 6, 5, 2, 2], [4, 3, 6, 5, 3, 6], [4, 3, 6, 5, 4, 1], [4, 3, 6, 5, 5, 5], [4, 3, 6, 5, 6, 0], [4, 3, 6, 5, 7, 4], [4, 3, 6, 5, 8, 8], [4, 3, 6, 6, 0, 5], [4, 3, 6, 6, 1, 0], [4, 3, 6, 6, 2, 4], [4, 3, 6, 6, 3, 8], [4, 3, 6, 6, 4, 3], [4, 3, 6, 6, 5, 7], [4, 3, 6, 6, 6, 2], [4, 3, 6, 6, 7, 6], [4, 3, 6, 6, 8, 1], [4, 3, 6, 7, 0, 7], [4, 3, 6, 7, 1, 2], [4, 3, 6, 7, 2, 6], [4, 3, 6, 7, 3, 1], [4, 3, 6, 7, 4, 5], [4, 3, 6, 7, 5, 0], [4, 3, 6, 7, 6, 4], [4, 3, 6, 7, 7, 8], [4, 3, 6, 7, 8, 3], [4, 3, 6, 8, 0, 0], [4, 3, 6, 8, 1, 4], [4, 3, 6, 8, 2, 8], [4, 3, 6, 8, 3, 3], [4, 3, 6, 8, 4, 7], [4, 3, 6, 8, 5, 2], [4, 3, 6, 8, 6, 6], [4, 3, 6, 8, 7, 1], [4, 3, 6, 8, 8, 5], [4, 4, 1, 0, 0, 2], [4, 4, 1, 0, 1, 6], [4, 4, 1, 0, 2, 1], [4, 4, 1, 0, 3, 5], [4, 4, 1, 0, 4, 0], [4, 4, 1, 0, 5, 4], [4, 4, 1, 0, 6, 8], [4, 4, 1, 0, 7, 3], [4, 4, 1, 0, 8, 7], [4, 4, 1, 1, 0, 4], [4, 4, 1, 1, 1, 8], [4, 4, 1, 1, 2, 3], [4, 4, 1, 1, 3, 7], [4, 4, 1, 1, 4, 2], [4, 4, 1, 1, 5, 6], [4, 4, 1, 1, 6, 1], [4, 4, 1, 1, 7, 5], [4, 4, 1, 1, 8, 0], [4, 4, 1, 2, 0, 6], [4, 4, 1, 2, 1, 1], [4, 4, 1, 2, 2, 5], [4, 4, 1, 2, 3, 0], [4, 4, 1, 2, 4, 4], [4, 4, 1, 2, 5, 8], [4, 4, 1, 2, 6, 3], [4, 4, 1, 2, 7, 7], [4, 4, 1, 2, 8, 2], [4, 4, 1, 3, 0, 8], [4, 4, 1, 3, 1, 3], [4, 4, 1, 3, 2, 7], [4, 4, 1, 3, 3, 2], [4, 4, 1, 3, 4, 6], [4, 4, 1, 3, 5, 1], [4, 4, 1, 3, 6, 5], [4, 4, 1, 3, 7, 0], [4, 4, 1, 3, 8, 4], [4, 4, 1, 4, 0, 1], [4, 4, 1, 4, 1, 5], [4, 4, 1, 4, 2, 0], [4, 4, 1, 4, 3, 4], [4, 4, 1, 4, 4, 8], [4, 4, 1, 4, 5, 3], [4, 4, 1, 4, 6, 7], [4, 4, 1, 4, 7, 2], [4, 4, 1, 4, 8, 6], [4, 4, 1, 5, 0, 3], [4, 4, 1, 5, 1, 7], [4, 4, 1, 5, 2, 2], [4, 4, 1, 5, 3, 6], [4, 4, 1, 5, 4, 1], [4, 4, 1, 5, 5, 5], [4, 4, 1, 5, 6, 0], [4, 4, 1, 5, 7, 4], [4, 4, 1, 5, 8, 8], [4, 4, 1, 6, 0, 5], [4, 4, 1, 6, 1, 0], [4, 4, 1, 6, 2, 4], [4, 4, 1, 6, 3, 8], [4, 4, 1, 6, 4, 3], [4, 4, 1, 6, 5, 7], [4, 4, 1, 6, 6, 2], [4, 4, 1, 6, 7, 6], [4, 4, 1, 6, 8, 1], [4, 4, 1, 7, 0, 7], [4, 4, 1, 7, 1, 2], [4, 4, 1, 7, 2, 6], [4, 4, 1, 7, 3, 1], [4, 4, 1, 7, 4, 5], [4, 4, 1, 7, 5, 0], [4, 4, 1, 7, 6, 4], [4, 4, 1, 7, 7, 8], [4, 4, 1, 7, 8, 3], [4, 4, 1, 8, 0, 0], [4, 4, 1, 8, 1, 4], [4, 4, 1, 8, 2, 8], [4, 4, 1, 8, 3, 3], [4, 4, 1, 8, 4, 7], [4, 4, 1, 8, 5, 2], [4, 4, 1, 8, 6, 6], [4, 4, 1, 8, 7, 1], [4, 4, 1, 8, 8, 5], [4, 5, 5, 0, 0, 2], [4, 5, 5, 0, 1, 6], [4, 5, 5, 0, 2, 1], [4, 5, 5, 0, 3, 5], [4, 5, 5, 0, 4, 0], [4, 5, 5, 0, 5, 4], [4, 5, 5, 0, 6, 8], [4, 5, 5, 0, 7, 3], [4, 5, 5, 0, 8, 7], [4, 5, 5, 1, 0, 4], [4, 5, 5, 1, 1, 8], [4, 5, 5, 1, 2, 3], [4, 5, 5, 1, 3, 7], [4, 5, 5, 1, 4, 2], [4, 5, 5, 1, 5, 6], [4, 5, 5, 1, 6, 1], [4, 5, 5, 1, 7, 5], [4, 5, 5, 1, 8, 0], [4, 5, 5, 2, 0, 6], [4, 5, 5, 2, 1, 1], [4, 5, 5, 2, 2, 5], [4, 5, 5, 2, 3, 0], [4, 5, 5, 2, 4, 4], [4, 5, 5, 2, 5, 8], [4, 5, 5, 2, 6, 3], [4, 5, 5, 2, 7, 7], [4, 5, 5, 2, 8, 2], [4, 5, 5, 3, 0, 8], [4, 5, 5, 3, 1, 3], [4, 5, 5, 3, 2, 7], [4, 5, 5, 3, 3, 2], [4, 5, 5, 3, 4, 6], [4, 5, 5, 3, 5, 1], [4, 5, 5, 3, 6, 5], [4, 5, 5, 3, 7, 0], [4, 5, 5, 3, 8, 4], [4, 5, 5, 4, 0, 1], [4, 5, 5, 4, 1, 5], [4, 5, 5, 4, 2, 0], [4, 5, 5, 4, 3, 4], [4, 5, 5, 4, 4, 8], [4, 5, 5, 4, 5, 3], [4, 5, 5, 4, 6, 7], [4, 5, 5, 4, 7, 2], [4, 5, 5, 4, 8, 6], [4, 5, 5, 5, 0, 3], [4, 5, 5, 5, 1, 7], [4, 5, 5, 5, 2, 2], [4, 5, 5, 5, 3, 6], [4, 5, 5, 5, 4, 1], [4, 5, 5, 5, 5, 5], [4, 5, 5, 5, 6, 0], [4, 5, 5, 5, 7, 4], [4, 5, 5, 5, 8, 8], [4, 5, 5, 6, 0, 5], [4, 5, 5, 6, 1, 0], [4, 5, 5, 6, 2, 4], [4, 5, 5, 6, 3, 8], [4, 5, 5, 6, 4, 3], [4, 5, 5, 6, 5, 7], [4, 5, 5, 6, 6, 2], [4, 5, 5, 6, 7, 6], [4, 5, 5, 6, 8, 1], [4, 5, 5, 7, 0, 7], [4, 5, 5, 7, 1, 2], [4, 5, 5, 7, 2, 6], [4, 5, 5, 7, 3, 1], [4, 5, 5, 7, 4, 5], [4, 5, 5, 7, 5, 0], [4, 5, 5, 7, 6, 4], [4, 5, 5, 7, 7, 8], [4, 5, 5, 7, 8, 3], [4, 5, 5, 8, 0, 0], [4, 5, 5, 8, 1, 4], [4, 5, 5, 8, 2, 8], [4, 5, 5, 8, 3, 3], [4, 5, 5, 8, 4, 7], [4, 5, 5, 8, 5, 2], [4, 5, 5, 8, 6, 6], [4, 5, 5, 8, 7, 1], [4, 5, 5, 8, 8, 5], [4, 6, 0, 0, 0, 2], [4, 6, 0, 0, 1, 6], [4, 6, 0, 0, 2, 1], [4, 6, 0, 0, 3, 5], [4, 6, 0, 0, 4, 0], [4, 6, 0, 0, 5, 4], [4, 6, 0, 0, 6, 8], [4, 6, 0, 0, 7, 3], [4, 6, 0, 0, 8, 7], [4, 6, 0, 1, 0, 4], [4, 6, 0, 1, 1, 8], [4, 6, 0, 1, 2, 3], [4, 6, 0, 1, 3, 7], [4, 6, 0, 1, 4, 2], [4, 6, 0, 1, 5, 6], [4, 6, 0, 1, 6, 1], [4, 6, 0, 1, 7, 5], [4, 6, 0, 1, 8, 0], [4, 6, 0, 2, 0, 6], [4, 6, 0, 2, 1, 1], [4, 6, 0, 2, 2, 5], [4, 6, 0, 2, 3, 0], [4, 6, 0, 2, 4, 4], [4, 6, 0, 2, 5, 8], [4, 6, 0, 2, 6, 3], [4, 6, 0, 2, 7, 7], [4, 6, 0, 2, 8, 2], [4, 6, 0, 3, 0, 8], [4, 6, 0, 3, 1, 3], [4, 6, 0, 3, 2, 7], [4, 6, 0, 3, 3, 2], [4, 6, 0, 3, 4, 6], [4, 6, 0, 3, 5, 1], [4, 6, 0, 3, 6, 5], [4, 6, 0, 3, 7, 0], [4, 6, 0, 3, 8, 4], [4, 6, 0, 4, 0, 1], [4, 6, 0, 4, 1, 5], [4, 6, 0, 4, 2, 0], [4, 6, 0, 4, 3, 4], [4, 6, 0, 4, 4, 8], [4, 6, 0, 4, 5, 3], [4, 6, 0, 4, 6, 7], [4, 6, 0, 4, 7, 2], [4, 6, 0, 4, 8, 6], [4, 6, 0, 5, 0, 3], [4, 6, 0, 5, 1, 7], [4, 6, 0, 5, 2, 2], [4, 6, 0, 5, 3, 6], [4, 6, 0, 5, 4, 1], [4, 6, 0, 5, 5, 5], [4, 6, 0, 5, 6, 0], [4, 6, 0, 5, 7, 4], [4, 6, 0, 5, 8, 8], [4, 6, 0, 6, 0, 5], [4, 6, 0, 6, 1, 0], [4, 6, 0, 6, 2, 4], [4, 6, 0, 6, 3, 8], [4, 6, 0, 6, 4, 3], [4, 6, 0, 6, 5, 7], [4, 6, 0, 6, 6, 2], [4, 6, 0, 6, 7, 6], [4, 6, 0, 6, 8, 1], [4, 6, 0, 7, 0, 7], [4, 6, 0, 7, 1, 2], [4, 6, 0, 7, 2, 6], [4, 6, 0, 7, 3, 1], [4, 6, 0, 7, 4, 5], [4, 6, 0, 7, 5, 0], [4, 6, 0, 7, 6, 4], [4, 6, 0, 7, 7, 8], [4, 6, 0, 7, 8, 3], [4, 6, 0, 8, 0, 0], [4, 6, 0, 8, 1, 4], [4, 6, 0, 8, 2, 8], [4, 6, 0, 8, 3, 3], [4, 6, 0, 8, 4, 7], [4, 6, 0, 8, 5, 2], [4, 6, 0, 8, 6, 6], [4, 6, 0, 8, 7, 1], [4, 6, 0, 8, 8, 5], [4, 7, 4, 0, 0, 2], [4, 7, 4, 0, 1, 6], [4, 7, 4, 0, 2, 1], [4, 7, 4, 0, 3, 5], [4, 7, 4, 0, 4, 0], [4, 7, 4, 0, 5, 4], [4, 7, 4, 0, 6, 8], [4, 7, 4, 0, 7, 3], [4, 7, 4, 0, 8, 7], [4, 7, 4, 1, 0, 4], [4, 7, 4, 1, 1, 8], [4, 7, 4, 1, 2, 3], [4, 7, 4, 1, 3, 7], [4, 7, 4, 1, 4, 2], [4, 7, 4, 1, 5, 6], [4, 7, 4, 1, 6, 1], [4, 7, 4, 1, 7, 5], [4, 7, 4, 1, 8, 0], [4, 7, 4, 2, 0, 6], [4, 7, 4, 2, 1, 1], [4, 7, 4, 2, 2, 5], [4, 7, 4, 2, 3, 0], [4, 7, 4, 2, 4, 4], [4, 7, 4, 2, 5, 8], [4, 7, 4, 2, 6, 3], [4, 7, 4, 2, 7, 7], [4, 7, 4, 2, 8, 2], [4, 7, 4, 3, 0, 8], [4, 7, 4, 3, 1, 3], [4, 7, 4, 3, 2, 7], [4, 7, 4, 3, 3, 2], [4, 7, 4, 3, 4, 6], [4, 7, 4, 3, 5, 1], [4, 7, 4, 3, 6, 5], [4, 7, 4, 3, 7, 0], [4, 7, 4, 3, 8, 4], [4, 7, 4, 4, 0, 1], [4, 7, 4, 4, 1, 5], [4, 7, 4, 4, 2, 0], [4, 7, 4, 4, 3, 4], [4, 7, 4, 4, 4, 8], [4, 7, 4, 4, 5, 3], [4, 7, 4, 4, 6, 7], [4, 7, 4, 4, 7, 2], [4, 7, 4, 4, 8, 6], [4, 7, 4, 5, 0, 3], [4, 7, 4, 5, 1, 7], [4, 7, 4, 5, 2, 2], [4, 7, 4, 5, 3, 6], [4, 7, 4, 5, 4, 1], [4, 7, 4, 5, 5, 5], [4, 7, 4, 5, 6, 0], [4, 7, 4, 5, 7, 4], [4, 7, 4, 5, 8, 8], [4, 7, 4, 6, 0, 5], [4, 7, 4, 6, 1, 0], [4, 7, 4, 6, 2, 4], [4, 7, 4, 6, 3, 8], [4, 7, 4, 6, 4, 3], [4, 7, 4, 6, 5, 7], [4, 7, 4, 6, 6, 2], [4, 7, 4, 6, 7, 6], [4, 7, 4, 6, 8, 1], [4, 7, 4, 7, 0, 7], [4, 7, 4, 7, 1, 2], [4, 7, 4, 7, 2, 6], [4, 7, 4, 7, 3, 1], [4, 7, 4, 7, 4, 5], [4, 7, 4, 7, 5, 0], [4, 7, 4, 7, 6, 4], [4, 7, 4, 7, 7, 8], [4, 7, 4, 7, 8, 3], [4, 7, 4, 8, 0, 0], [4, 7, 4, 8, 1, 4], [4, 7, 4, 8, 2, 8], [4, 7, 4, 8, 3, 3], [4, 7, 4, 8, 4, 7], [4, 7, 4, 8, 5, 2], [4, 7, 4, 8, 6, 6], [4, 7, 4, 8, 7, 1], [4, 7, 4, 8, 8, 5], [4, 8, 8, 0, 0, 2], [4, 8, 8, 0, 1, 6], [4, 8, 8, 0, 2, 1], [4, 8, 8, 0, 3, 5], [4, 8, 8, 0, 4, 0], [4, 8, 8, 0, 5, 4], [4, 8, 8, 0, 6, 8], [4, 8, 8, 0, 7, 3], [4, 8, 8, 0, 8, 7], [4, 8, 8, 1, 0, 4], [4, 8, 8, 1, 1, 8], [4, 8, 8, 1, 2, 3], [4, 8, 8, 1, 3, 7], [4, 8, 8, 1, 4, 2], [4, 8, 8, 1, 5, 6], [4, 8, 8, 1, 6, 1], [4, 8, 8, 1, 7, 5], [4, 8, 8, 1, 8, 0], [4, 8, 8, 2, 0, 6], [4, 8, 8, 2, 1, 1], [4, 8, 8, 2, 2, 5], [4, 8, 8, 2, 3, 0], [4, 8, 8, 2, 4, 4], [4, 8, 8, 2, 5, 8], [4, 8, 8, 2, 6, 3], [4, 8, 8, 2, 7, 7], [4, 8, 8, 2, 8, 2], [4, 8, 8, 3, 0, 8], [4, 8, 8, 3, 1, 3], [4, 8, 8, 3, 2, 7], [4, 8, 8, 3, 3, 2], [4, 8, 8, 3, 4, 6], [4, 8, 8, 3, 5, 1], [4, 8, 8, 3, 6, 5], [4, 8, 8, 3, 7, 0], [4, 8, 8, 3, 8, 4], [4, 8, 8, 4, 0, 1], [4, 8, 8, 4, 1, 5], [4, 8, 8, 4, 2, 0], [4, 8, 8, 4, 3, 4], [4, 8, 8, 4, 4, 8], [4, 8, 8, 4, 5, 3], [4, 8, 8, 4, 6, 7], [4, 8, 8, 4, 7, 2], [4, 8, 8, 4, 8, 6], [4, 8, 8, 5, 0, 3], [4, 8, 8, 5, 1, 7], [4, 8, 8, 5, 2, 2], [4, 8, 8, 5, 3, 6], [4, 8, 8, 5, 4, 1], [4, 8, 8, 5, 5, 5], [4, 8, 8, 5, 6, 0], [4, 8, 8, 5, 7, 4], [4, 8, 8, 5, 8, 8], [4, 8, 8, 6, 0, 5], [4, 8, 8, 6, 1, 0], [4, 8, 8, 6, 2, 4], [4, 8, 8, 6, 3, 8], [4, 8, 8, 6, 4, 3], [4, 8, 8, 6, 5, 7], [4, 8, 8, 6, 6, 2], [4, 8, 8, 6, 7, 6], [4, 8, 8, 6, 8, 1], [4, 8, 8, 7, 0, 7], [4, 8, 8, 7, 1, 2], [4, 8, 8, 7, 2, 6], [4, 8, 8, 7, 3, 1], [4, 8, 8, 7, 4, 5], [4, 8, 8, 7, 5, 0], [4, 8, 8, 7, 6, 4], [4, 8, 8, 7, 7, 8], [4, 8, 8, 7, 8, 3], [4, 8, 8, 8, 0, 0], [4, 8, 8, 8, 1, 4], [4, 8, 8, 8, 2, 8], [4, 8, 8, 8, 3, 3], [4, 8, 8, 8, 4, 7], [4, 8, 8, 8, 5, 2], [4, 8, 8, 8, 6, 6], [4, 8, 8, 8, 7, 1], [4, 8, 8, 8, 8, 5], [5, 0, 5, 0, 0, 2], [5, 0, 5, 0, 1, 6], [5, 0, 5, 0, 2, 1], [5, 0, 5, 0, 3, 5], [5, 0, 5, 0, 4, 0], [5, 0, 5, 0, 5, 4], [5, 0, 5, 0, 6, 8], [5, 0, 5, 0, 7, 3], [5, 0, 5, 0, 8, 7], [5, 0, 5, 1, 0, 4], [5, 0, 5, 1, 1, 8], [5, 0, 5, 1, 2, 3], [5, 0, 5, 1, 3, 7], [5, 0, 5, 1, 4, 2], [5, 0, 5, 1, 5, 6], [5, 0, 5, 1, 6, 1], [5, 0, 5, 1, 7, 5], [5, 0, 5, 1, 8, 0], [5, 0, 5, 2, 0, 6], [5, 0, 5, 2, 1, 1], [5, 0, 5, 2, 2, 5], [5, 0, 5, 2, 3, 0], [5, 0, 5, 2, 4, 4], [5, 0, 5, 2, 5, 8], [5, 0, 5, 2, 6, 3], [5, 0, 5, 2, 7, 7], [5, 0, 5, 2, 8, 2], [5, 0, 5, 3, 0, 8], [5, 0, 5, 3, 1, 3], [5, 0, 5, 3, 2, 7], [5, 0, 5, 3, 3, 2], [5, 0, 5, 3, 4, 6], [5, 0, 5, 3, 5, 1], [5, 0, 5, 3, 6, 5], [5, 0, 5, 3, 7, 0], [5, 0, 5, 3, 8, 4], [5, 0, 5, 4, 0, 1], [5, 0, 5, 4, 1, 5], [5, 0, 5, 4, 2, 0], [5, 0, 5, 4, 3, 4], [5, 0, 5, 4, 4, 8], [5, 0, 5, 4, 5, 3], [5, 0, 5, 4, 6, 7], [5, 0, 5, 4, 7, 2], [5, 0, 5, 4, 8, 6], [5, 0, 5, 5, 0, 3], [5, 0, 5, 5, 1, 7], [5, 0, 5, 5, 2, 2], [5, 0, 5, 5, 3, 6], [5, 0, 5, 5, 4, 1], [5, 0, 5, 5, 5, 5], [5, 0, 5, 5, 6, 0], [5, 0, 5, 5, 7, 4], [5, 0, 5, 5, 8, 8], [5, 0, 5, 6, 0, 5], [5, 0, 5, 6, 1, 0], [5, 0, 5, 6, 2, 4], [5, 0, 5, 6, 3, 8], [5, 0, 5, 6, 4, 3], [5, 0, 5, 6, 5, 7], [5, 0, 5, 6, 6, 2], [5, 0, 5, 6, 7, 6], [5, 0, 5, 6, 8, 1], [5, 0, 5, 7, 0, 7], [5, 0, 5, 7, 1, 2], [5, 0, 5, 7, 2, 6], [5, 0, 5, 7, 3, 1], [5, 0, 5, 7, 4, 5], [5, 0, 5, 7, 5, 0], [5, 0, 5, 7, 6, 4], [5, 0, 5, 7, 7, 8], [5, 0, 5, 7, 8, 3], [5, 0, 5, 8, 0, 0], [5, 0, 5, 8, 1, 4], [5, 0, 5, 8, 2, 8], [5, 0, 5, 8, 3, 3], [5, 0, 5, 8, 4, 7], [5, 0, 5, 8, 5, 2], [5, 0, 5, 8, 6, 6], [5, 0, 5, 8, 7, 1], [5, 0, 5, 8, 8, 5], [5, 1, 0, 0, 0, 2], [5, 1, 0, 0, 1, 6], [5, 1, 0, 0, 2, 1], [5, 1, 0, 0, 3, 5], [5, 1, 0, 0, 4, 0], [5, 1, 0, 0, 5, 4], [5, 1, 0, 0, 6, 8], [5, 1, 0, 0, 7, 3], [5, 1, 0, 0, 8, 7], [5, 1, 0, 1, 0, 4], [5, 1, 0, 1, 1, 8], [5, 1, 0, 1, 2, 3], [5, 1, 0, 1, 3, 7], [5, 1, 0, 1, 4, 2], [5, 1, 0, 1, 5, 6], [5, 1, 0, 1, 6, 1], [5, 1, 0, 1, 7, 5], [5, 1, 0, 1, 8, 0], [5, 1, 0, 2, 0, 6], [5, 1, 0, 2, 1, 1], [5, 1, 0, 2, 2, 5], [5, 1, 0, 2, 3, 0], [5, 1, 0, 2, 4, 4], [5, 1, 0, 2, 5, 8], [5, 1, 0, 2, 6, 3], [5, 1, 0, 2, 7, 7], [5, 1, 0, 2, 8, 2], [5, 1, 0, 3, 0, 8], [5, 1, 0, 3, 1, 3], [5, 1, 0, 3, 2, 7], [5, 1, 0, 3, 3, 2], [5, 1, 0, 3, 4, 6], [5, 1, 0, 3, 5, 1], [5, 1, 0, 3, 6, 5], [5, 1, 0, 3, 7, 0], [5, 1, 0, 3, 8, 4], [5, 1, 0, 4, 0, 1], [5, 1, 0, 4, 1, 5], [5, 1, 0, 4, 2, 0], [5, 1, 0, 4, 3, 4], [5, 1, 0, 4, 4, 8], [5, 1, 0, 4, 5, 3], [5, 1, 0, 4, 6, 7], [5, 1, 0, 4, 7, 2], [5, 1, 0, 4, 8, 6], [5, 1, 0, 5, 0, 3], [5, 1, 0, 5, 1, 7], [5, 1, 0, 5, 2, 2], [5, 1, 0, 5, 3, 6], [5, 1, 0, 5, 4, 1], [5, 1, 0, 5, 5, 5], [5, 1, 0, 5, 6, 0], [5, 1, 0, 5, 7, 4], [5, 1, 0, 5, 8, 8], [5, 1, 0, 6, 0, 5], [5, 1, 0, 6, 1, 0], [5, 1, 0, 6, 2, 4], [5, 1, 0, 6, 3, 8], [5, 1, 0, 6, 4, 3], [5, 1, 0, 6, 5, 7], [5, 1, 0, 6, 6, 2], [5, 1, 0, 6, 7, 6], [5, 1, 0, 6, 8, 1], [5, 1, 0, 7, 0, 7], [5, 1, 0, 7, 1, 2], [5, 1, 0, 7, 2, 6], [5, 1, 0, 7, 3, 1], [5, 1, 0, 7, 4, 5], [5, 1, 0, 7, 5, 0], [5, 1, 0, 7, 6, 4], [5, 1, 0, 7, 7, 8], [5, 1, 0, 7, 8, 3], [5, 1, 0, 8, 0, 0], [5, 1, 0, 8, 1, 4], [5, 1, 0, 8, 2, 8], [5, 1, 0, 8, 3, 3], [5, 1, 0, 8, 4, 7], [5, 1, 0, 8, 5, 2], [5, 1, 0, 8, 6, 6], [5, 1, 0, 8, 7, 1], [5, 1, 0, 8, 8, 5], [5, 2, 4, 0, 0, 2], [5, 2, 4, 0, 1, 6], [5, 2, 4, 0, 2, 1], [5, 2, 4, 0, 3, 5], [5, 2, 4, 0, 4, 0], [5, 2, 4, 0, 5, 4], [5, 2, 4, 0, 6, 8], [5, 2, 4, 0, 7, 3], [5, 2, 4, 0, 8, 7], [5, 2, 4, 1, 0, 4], [5, 2, 4, 1, 1, 8], [5, 2, 4, 1, 2, 3], [5, 2, 4, 1, 3, 7], [5, 2, 4, 1, 4, 2], [5, 2, 4, 1, 5, 6], [5, 2, 4, 1, 6, 1], [5, 2, 4, 1, 7, 5], [5, 2, 4, 1, 8, 0], [5, 2, 4, 2, 0, 6], [5, 2, 4, 2, 1, 1], [5, 2, 4, 2, 2, 5], [5, 2, 4, 2, 3, 0], [5, 2, 4, 2, 4, 4], [5, 2, 4, 2, 5, 8], [5, 2, 4, 2, 6, 3], [5, 2, 4, 2, 7, 7], [5, 2, 4, 2, 8, 2], [5, 2, 4, 3, 0, 8], [5, 2, 4, 3, 1, 3], [5, 2, 4, 3, 2, 7], [5, 2, 4, 3, 3, 2], [5, 2, 4, 3, 4, 6], [5, 2, 4, 3, 5, 1], [5, 2, 4, 3, 6, 5], [5, 2, 4, 3, 7, 0], [5, 2, 4, 3, 8, 4], [5, 2, 4, 4, 0, 1], [5, 2, 4, 4, 1, 5], [5, 2, 4, 4, 2, 0], [5, 2, 4, 4, 3, 4], [5, 2, 4, 4, 4, 8], [5, 2, 4, 4, 5, 3], [5, 2, 4, 4, 6, 7], [5, 2, 4, 4, 7, 2], [5, 2, 4, 4, 8, 6], [5, 2, 4, 5, 0, 3], [5, 2, 4, 5, 1, 7], [5, 2, 4, 5, 2, 2], [5, 2, 4, 5, 3, 6], [5, 2, 4, 5, 4, 1], [5, 2, 4, 5, 5, 5], [5, 2, 4, 5, 6, 0], [5, 2, 4, 5, 7, 4], [5, 2, 4, 5, 8, 8], [5, 2, 4, 6, 0, 5], [5, 2, 4, 6, 1, 0], [5, 2, 4, 6, 2, 4], [5, 2, 4, 6, 3, 8], [5, 2, 4, 6, 4, 3], [5, 2, 4, 6, 5, 7], [5, 2, 4, 6, 6, 2], [5, 2, 4, 6, 7, 6], [5, 2, 4, 6, 8, 1], [5, 2, 4, 7, 0, 7], [5, 2, 4, 7, 1, 2], [5, 2, 4, 7, 2, 6], [5, 2, 4, 7, 3, 1], [5, 2, 4, 7, 4, 5], [5, 2, 4, 7, 5, 0], [5, 2, 4, 7, 6, 4], [5, 2, 4, 7, 7, 8], [5, 2, 4, 7, 8, 3], [5, 2, 4, 8, 0, 0], [5, 2, 4, 8, 1, 4], [5, 2, 4, 8, 2, 8], [5, 2, 4, 8, 3, 3], [5, 2, 4, 8, 4, 7], [5, 2, 4, 8, 5, 2], [5, 2, 4, 8, 6, 6], [5, 2, 4, 8, 7, 1], [5, 2, 4, 8, 8, 5], [5, 3, 8, 0, 0, 2], [5, 3, 8, 0, 1, 6], [5, 3, 8, 0, 2, 1], [5, 3, 8, 0, 3, 5], [5, 3, 8, 0, 4, 0], [5, 3, 8, 0, 5, 4], [5, 3, 8, 0, 6, 8], [5, 3, 8, 0, 7, 3], [5, 3, 8, 0, 8, 7], [5, 3, 8, 1, 0, 4], [5, 3, 8, 1, 1, 8], [5, 3, 8, 1, 2, 3], [5, 3, 8, 1, 3, 7], [5, 3, 8, 1, 4, 2], [5, 3, 8, 1, 5, 6], [5, 3, 8, 1, 6, 1], [5, 3, 8, 1, 7, 5], [5, 3, 8, 1, 8, 0], [5, 3, 8, 2, 0, 6], [5, 3, 8, 2, 1, 1], [5, 3, 8, 2, 2, 5], [5, 3, 8, 2, 3, 0], [5, 3, 8, 2, 4, 4], [5, 3, 8, 2, 5, 8], [5, 3, 8, 2, 6, 3], [5, 3, 8, 2, 7, 7], [5, 3, 8, 2, 8, 2], [5, 3, 8, 3, 0, 8], [5, 3, 8, 3, 1, 3], [5, 3, 8, 3, 2, 7], [5, 3, 8, 3, 3, 2], [5, 3, 8, 3, 4, 6], [5, 3, 8, 3, 5, 1], [5, 3, 8, 3, 6, 5], [5, 3, 8, 3, 7, 0], [5, 3, 8, 3, 8, 4], [5, 3, 8, 4, 0, 1], [5, 3, 8, 4, 1, 5], [5, 3, 8, 4, 2, 0], [5, 3, 8, 4, 3, 4], [5, 3, 8, 4, 4, 8], [5, 3, 8, 4, 5, 3], [5, 3, 8, 4, 6, 7], [5, 3, 8, 4, 7, 2], [5, 3, 8, 4, 8, 6], [5, 3, 8, 5, 0, 3], [5, 3, 8, 5, 1, 7], [5, 3, 8, 5, 2, 2], [5, 3, 8, 5, 3, 6], [5, 3, 8, 5, 4, 1], [5, 3, 8, 5, 5, 5], [5, 3, 8, 5, 6, 0], [5, 3, 8, 5, 7, 4], [5, 3, 8, 5, 8, 8], [5, 3, 8, 6, 0, 5], [5, 3, 8, 6, 1, 0], [5, 3, 8, 6, 2, 4], [5, 3, 8, 6, 3, 8], [5, 3, 8, 6, 4, 3], [5, 3, 8, 6, 5, 7], [5, 3, 8, 6, 6, 2], [5, 3, 8, 6, 7, 6], [5, 3, 8, 6, 8, 1], [5, 3, 8, 7, 0, 7], [5, 3, 8, 7, 1, 2], [5, 3, 8, 7, 2, 6], [5, 3, 8, 7, 3, 1], [5, 3, 8, 7, 4, 5], [5, 3, 8, 7, 5, 0], [5, 3, 8, 7, 6, 4], [5, 3, 8, 7, 7, 8], [5, 3, 8, 7, 8, 3], [5, 3, 8, 8, 0, 0], [5, 3, 8, 8, 1, 4], [5, 3, 8, 8, 2, 8], [5, 3, 8, 8, 3, 3], [5, 3, 8, 8, 4, 7], [5, 3, 8, 8, 5, 2], [5, 3, 8, 8, 6, 6], [5, 3, 8, 8, 7, 1], [5, 3, 8, 8, 8, 5], [5, 4, 3, 0, 0, 2], [5, 4, 3, 0, 1, 6], [5, 4, 3, 0, 2, 1], [5, 4, 3, 0, 3, 5], [5, 4, 3, 0, 4, 0], [5, 4, 3, 0, 5, 4], [5, 4, 3, 0, 6, 8], [5, 4, 3, 0, 7, 3], [5, 4, 3, 0, 8, 7], [5, 4, 3, 1, 0, 4], [5, 4, 3, 1, 1, 8], [5, 4, 3, 1, 2, 3], [5, 4, 3, 1, 3, 7], [5, 4, 3, 1, 4, 2], [5, 4, 3, 1, 5, 6], [5, 4, 3, 1, 6, 1], [5, 4, 3, 1, 7, 5], [5, 4, 3, 1, 8, 0], [5, 4, 3, 2, 0, 6], [5, 4, 3, 2, 1, 1], [5, 4, 3, 2, 2, 5], [5, 4, 3, 2, 3, 0], [5, 4, 3, 2, 4, 4], [5, 4, 3, 2, 5, 8], [5, 4, 3, 2, 6, 3], [5, 4, 3, 2, 7, 7], [5, 4, 3, 2, 8, 2], [5, 4, 3, 3, 0, 8], [5, 4, 3, 3, 1, 3], [5, 4, 3, 3, 2, 7], [5, 4, 3, 3, 3, 2], [5, 4, 3, 3, 4, 6], [5, 4, 3, 3, 5, 1], [5, 4, 3, 3, 6, 5], [5, 4, 3, 3, 7, 0], [5, 4, 3, 3, 8, 4], [5, 4, 3, 4, 0, 1], [5, 4, 3, 4, 1, 5], [5, 4, 3, 4, 2, 0], [5, 4, 3, 4, 3, 4], [5, 4, 3, 4, 4, 8], [5, 4, 3, 4, 5, 3], [5, 4, 3, 4, 6, 7], [5, 4, 3, 4, 7, 2], [5, 4, 3, 4, 8, 6], [5, 4, 3, 5, 0, 3], [5, 4, 3, 5, 1, 7], [5, 4, 3, 5, 2, 2], [5, 4, 3, 5, 3, 6], [5, 4, 3, 5, 4, 1], [5, 4, 3, 5, 5, 5], [5, 4, 3, 5, 6, 0], [5, 4, 3, 5, 7, 4], [5, 4, 3, 5, 8, 8], [5, 4, 3, 6, 0, 5], [5, 4, 3, 6, 1, 0], [5, 4, 3, 6, 2, 4], [5, 4, 3, 6, 3, 8], [5, 4, 3, 6, 4, 3], [5, 4, 3, 6, 5, 7], [5, 4, 3, 6, 6, 2], [5, 4, 3, 6, 7, 6], [5, 4, 3, 6, 8, 1], [5, 4, 3, 7, 0, 7], [5, 4, 3, 7, 1, 2], [5, 4, 3, 7, 2, 6], [5, 4, 3, 7, 3, 1], [5, 4, 3, 7, 4, 5], [5, 4, 3, 7, 5, 0], [5, 4, 3, 7, 6, 4], [5, 4, 3, 7, 7, 8], [5, 4, 3, 7, 8, 3], [5, 4, 3, 8, 0, 0], [5, 4, 3, 8, 1, 4], [5, 4, 3, 8, 2, 8], [5, 4, 3, 8, 3, 3], [5, 4, 3, 8, 4, 7], [5, 4, 3, 8, 5, 2], [5, 4, 3, 8, 6, 6], [5, 4, 3, 8, 7, 1], [5, 4, 3, 8, 8, 5], [5, 5, 7, 0, 0, 2], [5, 5, 7, 0, 1, 6], [5, 5, 7, 0, 2, 1], [5, 5, 7, 0, 3, 5], [5, 5, 7, 0, 4, 0], [5, 5, 7, 0, 5, 4], [5, 5, 7, 0, 6, 8], [5, 5, 7, 0, 7, 3], [5, 5, 7, 0, 8, 7], [5, 5, 7, 1, 0, 4], [5, 5, 7, 1, 1, 8], [5, 5, 7, 1, 2, 3], [5, 5, 7, 1, 3, 7], [5, 5, 7, 1, 4, 2], [5, 5, 7, 1, 5, 6], [5, 5, 7, 1, 6, 1], [5, 5, 7, 1, 7, 5], [5, 5, 7, 1, 8, 0], [5, 5, 7, 2, 0, 6], [5, 5, 7, 2, 1, 1], [5, 5, 7, 2, 2, 5], [5, 5, 7, 2, 3, 0], [5, 5, 7, 2, 4, 4], [5, 5, 7, 2, 5, 8], [5, 5, 7, 2, 6, 3], [5, 5, 7, 2, 7, 7], [5, 5, 7, 2, 8, 2], [5, 5, 7, 3, 0, 8], [5, 5, 7, 3, 1, 3], [5, 5, 7, 3, 2, 7], [5, 5, 7, 3, 3, 2], [5, 5, 7, 3, 4, 6], [5, 5, 7, 3, 5, 1], [5, 5, 7, 3, 6, 5], [5, 5, 7, 3, 7, 0], [5, 5, 7, 3, 8, 4], [5, 5, 7, 4, 0, 1], [5, 5, 7, 4, 1, 5], [5, 5, 7, 4, 2, 0], [5, 5, 7, 4, 3, 4], [5, 5, 7, 4, 4, 8], [5, 5, 7, 4, 5, 3], [5, 5, 7, 4, 6, 7], [5, 5, 7, 4, 7, 2], [5, 5, 7, 4, 8, 6], [5, 5, 7, 5, 0, 3], [5, 5, 7, 5, 1, 7], [5, 5, 7, 5, 2, 2], [5, 5, 7, 5, 3, 6], [5, 5, 7, 5, 4, 1], [5, 5, 7, 5, 5, 5], [5, 5, 7, 5, 6, 0], [5, 5, 7, 5, 7, 4], [5, 5, 7, 5, 8, 8], [5, 5, 7, 6, 0, 5], [5, 5, 7, 6, 1, 0], [5, 5, 7, 6, 2, 4], [5, 5, 7, 6, 3, 8], [5, 5, 7, 6, 4, 3], [5, 5, 7, 6, 5, 7], [5, 5, 7, 6, 6, 2], [5, 5, 7, 6, 7, 6], [5, 5, 7, 6, 8, 1], [5, 5, 7, 7, 0, 7], [5, 5, 7, 7, 1, 2], [5, 5, 7, 7, 2, 6], [5, 5, 7, 7, 3, 1], [5, 5, 7, 7, 4, 5], [5, 5, 7, 7, 5, 0], [5, 5, 7, 7, 6, 4], [5, 5, 7, 7, 7, 8], [5, 5, 7, 7, 8, 3], [5, 5, 7, 8, 0, 0], [5, 5, 7, 8, 1, 4], [5, 5, 7, 8, 2, 8], [5, 5, 7, 8, 3, 3], [5, 5, 7, 8, 4, 7], [5, 5, 7, 8, 5, 2], [5, 5, 7, 8, 6, 6], [5, 5, 7, 8, 7, 1], [5, 5, 7, 8, 8, 5], [5, 6, 2, 0, 0, 2], [5, 6, 2, 0, 1, 6], [5, 6, 2, 0, 2, 1], [5, 6, 2, 0, 3, 5], [5, 6, 2, 0, 4, 0], [5, 6, 2, 0, 5, 4], [5, 6, 2, 0, 6, 8], [5, 6, 2, 0, 7, 3], [5, 6, 2, 0, 8, 7], [5, 6, 2, 1, 0, 4], [5, 6, 2, 1, 1, 8], [5, 6, 2, 1, 2, 3], [5, 6, 2, 1, 3, 7], [5, 6, 2, 1, 4, 2], [5, 6, 2, 1, 5, 6], [5, 6, 2, 1, 6, 1], [5, 6, 2, 1, 7, 5], [5, 6, 2, 1, 8, 0], [5, 6, 2, 2, 0, 6], [5, 6, 2, 2, 1, 1], [5, 6, 2, 2, 2, 5], [5, 6, 2, 2, 3, 0], [5, 6, 2, 2, 4, 4], [5, 6, 2, 2, 5, 8], [5, 6, 2, 2, 6, 3], [5, 6, 2, 2, 7, 7], [5, 6, 2, 2, 8, 2], [5, 6, 2, 3, 0, 8], [5, 6, 2, 3, 1, 3], [5, 6, 2, 3, 2, 7], [5, 6, 2, 3, 3, 2], [5, 6, 2, 3, 4, 6], [5, 6, 2, 3, 5, 1], [5, 6, 2, 3, 6, 5], [5, 6, 2, 3, 7, 0], [5, 6, 2, 3, 8, 4], [5, 6, 2, 4, 0, 1], [5, 6, 2, 4, 1, 5], [5, 6, 2, 4, 2, 0], [5, 6, 2, 4, 3, 4], [5, 6, 2, 4, 4, 8], [5, 6, 2, 4, 5, 3], [5, 6, 2, 4, 6, 7], [5, 6, 2, 4, 7, 2], [5, 6, 2, 4, 8, 6], [5, 6, 2, 5, 0, 3], [5, 6, 2, 5, 1, 7], [5, 6, 2, 5, 2, 2], [5, 6, 2, 5, 3, 6], [5, 6, 2, 5, 4, 1], [5, 6, 2, 5, 5, 5], [5, 6, 2, 5, 6, 0], [5, 6, 2, 5, 7, 4], [5, 6, 2, 5, 8, 8], [5, 6, 2, 6, 0, 5], [5, 6, 2, 6, 1, 0], [5, 6, 2, 6, 2, 4], [5, 6, 2, 6, 3, 8], [5, 6, 2, 6, 4, 3], [5, 6, 2, 6, 5, 7], [5, 6, 2, 6, 6, 2], [5, 6, 2, 6, 7, 6], [5, 6, 2, 6, 8, 1], [5, 6, 2, 7, 0, 7], [5, 6, 2, 7, 1, 2], [5, 6, 2, 7, 2, 6], [5, 6, 2, 7, 3, 1], [5, 6, 2, 7, 4, 5], [5, 6, 2, 7, 5, 0], [5, 6, 2, 7, 6, 4], [5, 6, 2, 7, 7, 8], [5, 6, 2, 7, 8, 3], [5, 6, 2, 8, 0, 0], [5, 6, 2, 8, 1, 4], [5, 6, 2, 8, 2, 8], [5, 6, 2, 8, 3, 3], [5, 6, 2, 8, 4, 7], [5, 6, 2, 8, 5, 2], [5, 6, 2, 8, 6, 6], [5, 6, 2, 8, 7, 1], [5, 6, 2, 8, 8, 5], [5, 7, 6, 0, 0, 2], [5, 7, 6, 0, 1, 6], [5, 7, 6, 0, 2, 1], [5, 7, 6, 0, 3, 5], [5, 7, 6, 0, 4, 0], [5, 7, 6, 0, 5, 4], [5, 7, 6, 0, 6, 8], [5, 7, 6, 0, 7, 3], [5, 7, 6, 0, 8, 7], [5, 7, 6, 1, 0, 4], [5, 7, 6, 1, 1, 8], [5, 7, 6, 1, 2, 3], [5, 7, 6, 1, 3, 7], [5, 7, 6, 1, 4, 2], [5, 7, 6, 1, 5, 6], [5, 7, 6, 1, 6, 1], [5, 7, 6, 1, 7, 5], [5, 7, 6, 1, 8, 0], [5, 7, 6, 2, 0, 6], [5, 7, 6, 2, 1, 1], [5, 7, 6, 2, 2, 5], [5, 7, 6, 2, 3, 0], [5, 7, 6, 2, 4, 4], [5, 7, 6, 2, 5, 8], [5, 7, 6, 2, 6, 3], [5, 7, 6, 2, 7, 7], [5, 7, 6, 2, 8, 2], [5, 7, 6, 3, 0, 8], [5, 7, 6, 3, 1, 3], [5, 7, 6, 3, 2, 7], [5, 7, 6, 3, 3, 2], [5, 7, 6, 3, 4, 6], [5, 7, 6, 3, 5, 1], [5, 7, 6, 3, 6, 5], [5, 7, 6, 3, 7, 0], [5, 7, 6, 3, 8, 4], [5, 7, 6, 4, 0, 1], [5, 7, 6, 4, 1, 5], [5, 7, 6, 4, 2, 0], [5, 7, 6, 4, 3, 4], [5, 7, 6, 4, 4, 8], [5, 7, 6, 4, 5, 3], [5, 7, 6, 4, 6, 7], [5, 7, 6, 4, 7, 2], [5, 7, 6, 4, 8, 6], [5, 7, 6, 5, 0, 3], [5, 7, 6, 5, 1, 7], [5, 7, 6, 5, 2, 2], [5, 7, 6, 5, 3, 6], [5, 7, 6, 5, 4, 1], [5, 7, 6, 5, 5, 5], [5, 7, 6, 5, 6, 0], [5, 7, 6, 5, 7, 4], [5, 7, 6, 5, 8, 8], [5, 7, 6, 6, 0, 5], [5, 7, 6, 6, 1, 0], [5, 7, 6, 6, 2, 4], [5, 7, 6, 6, 3, 8], [5, 7, 6, 6, 4, 3], [5, 7, 6, 6, 5, 7], [5, 7, 6, 6, 6, 2], [5, 7, 6, 6, 7, 6], [5, 7, 6, 6, 8, 1], [5, 7, 6, 7, 0, 7], [5, 7, 6, 7, 1, 2], [5, 7, 6, 7, 2, 6], [5, 7, 6, 7, 3, 1], [5, 7, 6, 7, 4, 5], [5, 7, 6, 7, 5, 0], [5, 7, 6, 7, 6, 4], [5, 7, 6, 7, 7, 8], [5, 7, 6, 7, 8, 3], [5, 7, 6, 8, 0, 0], [5, 7, 6, 8, 1, 4], [5, 7, 6, 8, 2, 8], [5, 7, 6, 8, 3, 3], [5, 7, 6, 8, 4, 7], [5, 7, 6, 8, 5, 2], [5, 7, 6, 8, 6, 6], [5, 7, 6, 8, 7, 1], [5, 7, 6, 8, 8, 5], [5, 8, 1, 0, 0, 2], [5, 8, 1, 0, 1, 6], [5, 8, 1, 0, 2, 1], [5, 8, 1, 0, 3, 5], [5, 8, 1, 0, 4, 0], [5, 8, 1, 0, 5, 4], [5, 8, 1, 0, 6, 8], [5, 8, 1, 0, 7, 3], [5, 8, 1, 0, 8, 7], [5, 8, 1, 1, 0, 4], [5, 8, 1, 1, 1, 8], [5, 8, 1, 1, 2, 3], [5, 8, 1, 1, 3, 7], [5, 8, 1, 1, 4, 2], [5, 8, 1, 1, 5, 6], [5, 8, 1, 1, 6, 1], [5, 8, 1, 1, 7, 5], [5, 8, 1, 1, 8, 0], [5, 8, 1, 2, 0, 6], [5, 8, 1, 2, 1, 1], [5, 8, 1, 2, 2, 5], [5, 8, 1, 2, 3, 0], [5, 8, 1, 2, 4, 4], [5, 8, 1, 2, 5, 8], [5, 8, 1, 2, 6, 3], [5, 8, 1, 2, 7, 7], [5, 8, 1, 2, 8, 2], [5, 8, 1, 3, 0, 8], [5, 8, 1, 3, 1, 3], [5, 8, 1, 3, 2, 7], [5, 8, 1, 3, 3, 2], [5, 8, 1, 3, 4, 6], [5, 8, 1, 3, 5, 1], [5, 8, 1, 3, 6, 5], [5, 8, 1, 3, 7, 0], [5, 8, 1, 3, 8, 4], [5, 8, 1, 4, 0, 1], [5, 8, 1, 4, 1, 5], [5, 8, 1, 4, 2, 0], [5, 8, 1, 4, 3, 4], [5, 8, 1, 4, 4, 8], [5, 8, 1, 4, 5, 3], [5, 8, 1, 4, 6, 7], [5, 8, 1, 4, 7, 2], [5, 8, 1, 4, 8, 6], [5, 8, 1, 5, 0, 3], [5, 8, 1, 5, 1, 7], [5, 8, 1, 5, 2, 2], [5, 8, 1, 5, 3, 6], [5, 8, 1, 5, 4, 1], [5, 8, 1, 5, 5, 5], [5, 8, 1, 5, 6, 0], [5, 8, 1, 5, 7, 4], [5, 8, 1, 5, 8, 8], [5, 8, 1, 6, 0, 5], [5, 8, 1, 6, 1, 0], [5, 8, 1, 6, 2, 4], [5, 8, 1, 6, 3, 8], [5, 8, 1, 6, 4, 3], [5, 8, 1, 6, 5, 7], [5, 8, 1, 6, 6, 2], [5, 8, 1, 6, 7, 6], [5, 8, 1, 6, 8, 1], [5, 8, 1, 7, 0, 7], [5, 8, 1, 7, 1, 2], [5, 8, 1, 7, 2, 6], [5, 8, 1, 7, 3, 1], [5, 8, 1, 7, 4, 5], [5, 8, 1, 7, 5, 0], [5, 8, 1, 7, 6, 4], [5, 8, 1, 7, 7, 8], [5, 8, 1, 7, 8, 3], [5, 8, 1, 8, 0, 0], [5, 8, 1, 8, 1, 4], [5, 8, 1, 8, 2, 8], [5, 8, 1, 8, 3, 3], [5, 8, 1, 8, 4, 7], [5, 8, 1, 8, 5, 2], [5, 8, 1, 8, 6, 6], [5, 8, 1, 8, 7, 1], [5, 8, 1, 8, 8, 5], [6, 0, 7, 0, 0, 2], [6, 0, 7, 0, 1, 6], [6, 0, 7, 0, 2, 1], [6, 0, 7, 0, 3, 5], [6, 0, 7, 0, 4, 0], [6, 0, 7, 0, 5, 4], [6, 0, 7, 0, 6, 8], [6, 0, 7, 0, 7, 3], [6, 0, 7, 0, 8, 7], [6, 0, 7, 1, 0, 4], [6, 0, 7, 1, 1, 8], [6, 0, 7, 1, 2, 3], [6, 0, 7, 1, 3, 7], [6, 0, 7, 1, 4, 2], [6, 0, 7, 1, 5, 6], [6, 0, 7, 1, 6, 1], [6, 0, 7, 1, 7, 5], [6, 0, 7, 1, 8, 0], [6, 0, 7, 2, 0, 6], [6, 0, 7, 2, 1, 1], [6, 0, 7, 2, 2, 5], [6, 0, 7, 2, 3, 0], [6, 0, 7, 2, 4, 4], [6, 0, 7, 2, 5, 8], [6, 0, 7, 2, 6, 3], [6, 0, 7, 2, 7, 7], [6, 0, 7, 2, 8, 2], [6, 0, 7, 3, 0, 8], [6, 0, 7, 3, 1, 3], [6, 0, 7, 3, 2, 7], [6, 0, 7, 3, 3, 2], [6, 0, 7, 3, 4, 6], [6, 0, 7, 3, 5, 1], [6, 0, 7, 3, 6, 5], [6, 0, 7, 3, 7, 0], [6, 0, 7, 3, 8, 4], [6, 0, 7, 4, 0, 1], [6, 0, 7, 4, 1, 5], [6, 0, 7, 4, 2, 0], [6, 0, 7, 4, 3, 4], [6, 0, 7, 4, 4, 8], [6, 0, 7, 4, 5, 3], [6, 0, 7, 4, 6, 7], [6, 0, 7, 4, 7, 2], [6, 0, 7, 4, 8, 6], [6, 0, 7, 5, 0, 3], [6, 0, 7, 5, 1, 7], [6, 0, 7, 5, 2, 2], [6, 0, 7, 5, 3, 6], [6, 0, 7, 5, 4, 1], [6, 0, 7, 5, 5, 5], [6, 0, 7, 5, 6, 0], [6, 0, 7, 5, 7, 4], [6, 0, 7, 5, 8, 8], [6, 0, 7, 6, 0, 5], [6, 0, 7, 6, 1, 0], [6, 0, 7, 6, 2, 4], [6, 0, 7, 6, 3, 8], [6, 0, 7, 6, 4, 3], [6, 0, 7, 6, 5, 7], [6, 0, 7, 6, 6, 2], [6, 0, 7, 6, 7, 6], [6, 0, 7, 6, 8, 1], [6, 0, 7, 7, 0, 7], [6, 0, 7, 7, 1, 2], [6, 0, 7, 7, 2, 6], [6, 0, 7, 7, 3, 1], [6, 0, 7, 7, 4, 5], [6, 0, 7, 7, 5, 0], [6, 0, 7, 7, 6, 4], [6, 0, 7, 7, 7, 8], [6, 0, 7, 7, 8, 3], [6, 0, 7, 8, 0, 0], [6, 0, 7, 8, 1, 4], [6, 0, 7, 8, 2, 8], [6, 0, 7, 8, 3, 3], [6, 0, 7, 8, 4, 7], [6, 0, 7, 8, 5, 2], [6, 0, 7, 8, 6, 6], [6, 0, 7, 8, 7, 1], [6, 0, 7, 8, 8, 5], [6, 1, 2, 0, 0, 2], [6, 1, 2, 0, 1, 6], [6, 1, 2, 0, 2, 1], [6, 1, 2, 0, 3, 5], [6, 1, 2, 0, 4, 0], [6, 1, 2, 0, 5, 4], [6, 1, 2, 0, 6, 8], [6, 1, 2, 0, 7, 3], [6, 1, 2, 0, 8, 7], [6, 1, 2, 1, 0, 4], [6, 1, 2, 1, 1, 8], [6, 1, 2, 1, 2, 3], [6, 1, 2, 1, 3, 7], [6, 1, 2, 1, 4, 2], [6, 1, 2, 1, 5, 6], [6, 1, 2, 1, 6, 1], [6, 1, 2, 1, 7, 5], [6, 1, 2, 1, 8, 0], [6, 1, 2, 2, 0, 6], [6, 1, 2, 2, 1, 1], [6, 1, 2, 2, 2, 5], [6, 1, 2, 2, 3, 0], [6, 1, 2, 2, 4, 4], [6, 1, 2, 2, 5, 8], [6, 1, 2, 2, 6, 3], [6, 1, 2, 2, 7, 7], [6, 1, 2, 2, 8, 2], [6, 1, 2, 3, 0, 8], [6, 1, 2, 3, 1, 3], [6, 1, 2, 3, 2, 7], [6, 1, 2, 3, 3, 2], [6, 1, 2, 3, 4, 6], [6, 1, 2, 3, 5, 1], [6, 1, 2, 3, 6, 5], [6, 1, 2, 3, 7, 0], [6, 1, 2, 3, 8, 4], [6, 1, 2, 4, 0, 1], [6, 1, 2, 4, 1, 5], [6, 1, 2, 4, 2, 0], [6, 1, 2, 4, 3, 4], [6, 1, 2, 4, 4, 8], [6, 1, 2, 4, 5, 3], [6, 1, 2, 4, 6, 7], [6, 1, 2, 4, 7, 2], [6, 1, 2, 4, 8, 6], [6, 1, 2, 5, 0, 3], [6, 1, 2, 5, 1, 7], [6, 1, 2, 5, 2, 2], [6, 1, 2, 5, 3, 6], [6, 1, 2, 5, 4, 1], [6, 1, 2, 5, 5, 5], [6, 1, 2, 5, 6, 0], [6, 1, 2, 5, 7, 4], [6, 1, 2, 5, 8, 8], [6, 1, 2, 6, 0, 5], [6, 1, 2, 6, 1, 0], [6, 1, 2, 6, 2, 4], [6, 1, 2, 6, 3, 8], [6, 1, 2, 6, 4, 3], [6, 1, 2, 6, 5, 7], [6, 1, 2, 6, 6, 2], [6, 1, 2, 6, 7, 6], [6, 1, 2, 6, 8, 1], [6, 1, 2, 7, 0, 7], [6, 1, 2, 7, 1, 2], [6, 1, 2, 7, 2, 6], [6, 1, 2, 7, 3, 1], [6, 1, 2, 7, 4, 5], [6, 1, 2, 7, 5, 0], [6, 1, 2, 7, 6, 4], [6, 1, 2, 7, 7, 8], [6, 1, 2, 7, 8, 3], [6, 1, 2, 8, 0, 0], [6, 1, 2, 8, 1, 4], [6, 1, 2, 8, 2, 8], [6, 1, 2, 8, 3, 3], [6, 1, 2, 8, 4, 7], [6, 1, 2, 8, 5, 2], [6, 1, 2, 8, 6, 6], [6, 1, 2, 8, 7, 1], [6, 1, 2, 8, 8, 5], [6, 2, 6, 0, 0, 2], [6, 2, 6, 0, 1, 6], [6, 2, 6, 0, 2, 1], [6, 2, 6, 0, 3, 5], [6, 2, 6, 0, 4, 0], [6, 2, 6, 0, 5, 4], [6, 2, 6, 0, 6, 8], [6, 2, 6, 0, 7, 3], [6, 2, 6, 0, 8, 7], [6, 2, 6, 1, 0, 4], [6, 2, 6, 1, 1, 8], [6, 2, 6, 1, 2, 3], [6, 2, 6, 1, 3, 7], [6, 2, 6, 1, 4, 2], [6, 2, 6, 1, 5, 6], [6, 2, 6, 1, 6, 1], [6, 2, 6, 1, 7, 5], [6, 2, 6, 1, 8, 0], [6, 2, 6, 2, 0, 6], [6, 2, 6, 2, 1, 1], [6, 2, 6, 2, 2, 5], [6, 2, 6, 2, 3, 0], [6, 2, 6, 2, 4, 4], [6, 2, 6, 2, 5, 8], [6, 2, 6, 2, 6, 3], [6, 2, 6, 2, 7, 7], [6, 2, 6, 2, 8, 2], [6, 2, 6, 3, 0, 8], [6, 2, 6, 3, 1, 3], [6, 2, 6, 3, 2, 7], [6, 2, 6, 3, 3, 2], [6, 2, 6, 3, 4, 6], [6, 2, 6, 3, 5, 1], [6, 2, 6, 3, 6, 5], [6, 2, 6, 3, 7, 0], [6, 2, 6, 3, 8, 4], [6, 2, 6, 4, 0, 1], [6, 2, 6, 4, 1, 5], [6, 2, 6, 4, 2, 0], [6, 2, 6, 4, 3, 4], [6, 2, 6, 4, 4, 8], [6, 2, 6, 4, 5, 3], [6, 2, 6, 4, 6, 7], [6, 2, 6, 4, 7, 2], [6, 2, 6, 4, 8, 6], [6, 2, 6, 5, 0, 3], [6, 2, 6, 5, 1, 7], [6, 2, 6, 5, 2, 2], [6, 2, 6, 5, 3, 6], [6, 2, 6, 5, 4, 1], [6, 2, 6, 5, 5, 5], [6, 2, 6, 5, 6, 0], [6, 2, 6, 5, 7, 4], [6, 2, 6, 5, 8, 8], [6, 2, 6, 6, 0, 5], [6, 2, 6, 6, 1, 0], [6, 2, 6, 6, 2, 4], [6, 2, 6, 6, 3, 8], [6, 2, 6, 6, 4, 3], [6, 2, 6, 6, 5, 7], [6, 2, 6, 6, 6, 2], [6, 2, 6, 6, 7, 6], [6, 2, 6, 6, 8, 1], [6, 2, 6, 7, 0, 7], [6, 2, 6, 7, 1, 2], [6, 2, 6, 7, 2, 6], [6, 2, 6, 7, 3, 1], [6, 2, 6, 7, 4, 5], [6, 2, 6, 7, 5, 0], [6, 2, 6, 7, 6, 4], [6, 2, 6, 7, 7, 8], [6, 2, 6, 7, 8, 3], [6, 2, 6, 8, 0, 0], [6, 2, 6, 8, 1, 4], [6, 2, 6, 8, 2, 8], [6, 2, 6, 8, 3, 3], [6, 2, 6, 8, 4, 7], [6, 2, 6, 8, 5, 2], [6, 2, 6, 8, 6, 6], [6, 2, 6, 8, 7, 1], [6, 2, 6, 8, 8, 5], [6, 3, 1, 0, 0, 2], [6, 3, 1, 0, 1, 6], [6, 3, 1, 0, 2, 1], [6, 3, 1, 0, 3, 5], [6, 3, 1, 0, 4, 0], [6, 3, 1, 0, 5, 4], [6, 3, 1, 0, 6, 8], [6, 3, 1, 0, 7, 3], [6, 3, 1, 0, 8, 7], [6, 3, 1, 1, 0, 4], [6, 3, 1, 1, 1, 8], [6, 3, 1, 1, 2, 3], [6, 3, 1, 1, 3, 7], [6, 3, 1, 1, 4, 2], [6, 3, 1, 1, 5, 6], [6, 3, 1, 1, 6, 1], [6, 3, 1, 1, 7, 5], [6, 3, 1, 1, 8, 0], [6, 3, 1, 2, 0, 6], [6, 3, 1, 2, 1, 1], [6, 3, 1, 2, 2, 5], [6, 3, 1, 2, 3, 0], [6, 3, 1, 2, 4, 4], [6, 3, 1, 2, 5, 8], [6, 3, 1, 2, 6, 3], [6, 3, 1, 2, 7, 7], [6, 3, 1, 2, 8, 2], [6, 3, 1, 3, 0, 8], [6, 3, 1, 3, 1, 3], [6, 3, 1, 3, 2, 7], [6, 3, 1, 3, 3, 2], [6, 3, 1, 3, 4, 6], [6, 3, 1, 3, 5, 1], [6, 3, 1, 3, 6, 5], [6, 3, 1, 3, 7, 0], [6, 3, 1, 3, 8, 4], [6, 3, 1, 4, 0, 1], [6, 3, 1, 4, 1, 5], [6, 3, 1, 4, 2, 0], [6, 3, 1, 4, 3, 4], [6, 3, 1, 4, 4, 8], [6, 3, 1, 4, 5, 3], [6, 3, 1, 4, 6, 7], [6, 3, 1, 4, 7, 2], [6, 3, 1, 4, 8, 6], [6, 3, 1, 5, 0, 3], [6, 3, 1, 5, 1, 7], [6, 3, 1, 5, 2, 2], [6, 3, 1, 5, 3, 6], [6, 3, 1, 5, 4, 1], [6, 3, 1, 5, 5, 5], [6, 3, 1, 5, 6, 0], [6, 3, 1, 5, 7, 4], [6, 3, 1, 5, 8, 8], [6, 3, 1, 6, 0, 5], [6, 3, 1, 6, 1, 0], [6, 3, 1, 6, 2, 4], [6, 3, 1, 6, 3, 8], [6, 3, 1, 6, 4, 3], [6, 3, 1, 6, 5, 7], [6, 3, 1, 6, 6, 2], [6, 3, 1, 6, 7, 6], [6, 3, 1, 6, 8, 1], [6, 3, 1, 7, 0, 7], [6, 3, 1, 7, 1, 2], [6, 3, 1, 7, 2, 6], [6, 3, 1, 7, 3, 1], [6, 3, 1, 7, 4, 5], [6, 3, 1, 7, 5, 0], [6, 3, 1, 7, 6, 4], [6, 3, 1, 7, 7, 8], [6, 3, 1, 7, 8, 3], [6, 3, 1, 8, 0, 0], [6, 3, 1, 8, 1, 4], [6, 3, 1, 8, 2, 8], [6, 3, 1, 8, 3, 3], [6, 3, 1, 8, 4, 7], [6, 3, 1, 8, 5, 2], [6, 3, 1, 8, 6, 6], [6, 3, 1, 8, 7, 1], [6, 3, 1, 8, 8, 5], [6, 4, 5, 0, 0, 2], [6, 4, 5, 0, 1, 6], [6, 4, 5, 0, 2, 1], [6, 4, 5, 0, 3, 5], [6, 4, 5, 0, 4, 0], [6, 4, 5, 0, 5, 4], [6, 4, 5, 0, 6, 8], [6, 4, 5, 0, 7, 3], [6, 4, 5, 0, 8, 7], [6, 4, 5, 1, 0, 4], [6, 4, 5, 1, 1, 8], [6, 4, 5, 1, 2, 3], [6, 4, 5, 1, 3, 7], [6, 4, 5, 1, 4, 2], [6, 4, 5, 1, 5, 6], [6, 4, 5, 1, 6, 1], [6, 4, 5, 1, 7, 5], [6, 4, 5, 1, 8, 0], [6, 4, 5, 2, 0, 6], [6, 4, 5, 2, 1, 1], [6, 4, 5, 2, 2, 5], [6, 4, 5, 2, 3, 0], [6, 4, 5, 2, 4, 4], [6, 4, 5, 2, 5, 8], [6, 4, 5, 2, 6, 3], [6, 4, 5, 2, 7, 7], [6, 4, 5, 2, 8, 2], [6, 4, 5, 3, 0, 8], [6, 4, 5, 3, 1, 3], [6, 4, 5, 3, 2, 7], [6, 4, 5, 3, 3, 2], [6, 4, 5, 3, 4, 6], [6, 4, 5, 3, 5, 1], [6, 4, 5, 3, 6, 5], [6, 4, 5, 3, 7, 0], [6, 4, 5, 3, 8, 4], [6, 4, 5, 4, 0, 1], [6, 4, 5, 4, 1, 5], [6, 4, 5, 4, 2, 0], [6, 4, 5, 4, 3, 4], [6, 4, 5, 4, 4, 8], [6, 4, 5, 4, 5, 3], [6, 4, 5, 4, 6, 7], [6, 4, 5, 4, 7, 2], [6, 4, 5, 4, 8, 6], [6, 4, 5, 5, 0, 3], [6, 4, 5, 5, 1, 7], [6, 4, 5, 5, 2, 2], [6, 4, 5, 5, 3, 6], [6, 4, 5, 5, 4, 1], [6, 4, 5, 5, 5, 5], [6, 4, 5, 5, 6, 0], [6, 4, 5, 5, 7, 4], [6, 4, 5, 5, 8, 8], [6, 4, 5, 6, 0, 5], [6, 4, 5, 6, 1, 0], [6, 4, 5, 6, 2, 4], [6, 4, 5, 6, 3, 8], [6, 4, 5, 6, 4, 3], [6, 4, 5, 6, 5, 7], [6, 4, 5, 6, 6, 2], [6, 4, 5, 6, 7, 6], [6, 4, 5, 6, 8, 1], [6, 4, 5, 7, 0, 7], [6, 4, 5, 7, 1, 2], [6, 4, 5, 7, 2, 6], [6, 4, 5, 7, 3, 1], [6, 4, 5, 7, 4, 5], [6, 4, 5, 7, 5, 0], [6, 4, 5, 7, 6, 4], [6, 4, 5, 7, 7, 8], [6, 4, 5, 7, 8, 3], [6, 4, 5, 8, 0, 0], [6, 4, 5, 8, 1, 4], [6, 4, 5, 8, 2, 8], [6, 4, 5, 8, 3, 3], [6, 4, 5, 8, 4, 7], [6, 4, 5, 8, 5, 2], [6, 4, 5, 8, 6, 6], [6, 4, 5, 8, 7, 1], [6, 4, 5, 8, 8, 5], [6, 5, 0, 0, 0, 2], [6, 5, 0, 0, 1, 6], [6, 5, 0, 0, 2, 1], [6, 5, 0, 0, 3, 5], [6, 5, 0, 0, 4, 0], [6, 5, 0, 0, 5, 4], [6, 5, 0, 0, 6, 8], [6, 5, 0, 0, 7, 3], [6, 5, 0, 0, 8, 7], [6, 5, 0, 1, 0, 4], [6, 5, 0, 1, 1, 8], [6, 5, 0, 1, 2, 3], [6, 5, 0, 1, 3, 7], [6, 5, 0, 1, 4, 2], [6, 5, 0, 1, 5, 6], [6, 5, 0, 1, 6, 1], [6, 5, 0, 1, 7, 5], [6, 5, 0, 1, 8, 0], [6, 5, 0, 2, 0, 6], [6, 5, 0, 2, 1, 1], [6, 5, 0, 2, 2, 5], [6, 5, 0, 2, 3, 0], [6, 5, 0, 2, 4, 4], [6, 5, 0, 2, 5, 8], [6, 5, 0, 2, 6, 3], [6, 5, 0, 2, 7, 7], [6, 5, 0, 2, 8, 2], [6, 5, 0, 3, 0, 8], [6, 5, 0, 3, 1, 3], [6, 5, 0, 3, 2, 7], [6, 5, 0, 3, 3, 2], [6, 5, 0, 3, 4, 6], [6, 5, 0, 3, 5, 1], [6, 5, 0, 3, 6, 5], [6, 5, 0, 3, 7, 0], [6, 5, 0, 3, 8, 4], [6, 5, 0, 4, 0, 1], [6, 5, 0, 4, 1, 5], [6, 5, 0, 4, 2, 0], [6, 5, 0, 4, 3, 4], [6, 5, 0, 4, 4, 8], [6, 5, 0, 4, 5, 3], [6, 5, 0, 4, 6, 7], [6, 5, 0, 4, 7, 2], [6, 5, 0, 4, 8, 6], [6, 5, 0, 5, 0, 3], [6, 5, 0, 5, 1, 7], [6, 5, 0, 5, 2, 2], [6, 5, 0, 5, 3, 6], [6, 5, 0, 5, 4, 1], [6, 5, 0, 5, 5, 5], [6, 5, 0, 5, 6, 0], [6, 5, 0, 5, 7, 4], [6, 5, 0, 5, 8, 8], [6, 5, 0, 6, 0, 5], [6, 5, 0, 6, 1, 0], [6, 5, 0, 6, 2, 4], [6, 5, 0, 6, 3, 8], [6, 5, 0, 6, 4, 3], [6, 5, 0, 6, 5, 7], [6, 5, 0, 6, 6, 2], [6, 5, 0, 6, 7, 6], [6, 5, 0, 6, 8, 1], [6, 5, 0, 7, 0, 7], [6, 5, 0, 7, 1, 2], [6, 5, 0, 7, 2, 6], [6, 5, 0, 7, 3, 1], [6, 5, 0, 7, 4, 5], [6, 5, 0, 7, 5, 0], [6, 5, 0, 7, 6, 4], [6, 5, 0, 7, 7, 8], [6, 5, 0, 7, 8, 3], [6, 5, 0, 8, 0, 0], [6, 5, 0, 8, 1, 4], [6, 5, 0, 8, 2, 8], [6, 5, 0, 8, 3, 3], [6, 5, 0, 8, 4, 7], [6, 5, 0, 8, 5, 2], [6, 5, 0, 8, 6, 6], [6, 5, 0, 8, 7, 1], [6, 5, 0, 8, 8, 5], [6, 6, 4, 0, 0, 2], [6, 6, 4, 0, 1, 6], [6, 6, 4, 0, 2, 1], [6, 6, 4, 0, 3, 5], [6, 6, 4, 0, 4, 0], [6, 6, 4, 0, 5, 4], [6, 6, 4, 0, 6, 8], [6, 6, 4, 0, 7, 3], [6, 6, 4, 0, 8, 7], [6, 6, 4, 1, 0, 4], [6, 6, 4, 1, 1, 8], [6, 6, 4, 1, 2, 3], [6, 6, 4, 1, 3, 7], [6, 6, 4, 1, 4, 2], [6, 6, 4, 1, 5, 6], [6, 6, 4, 1, 6, 1], [6, 6, 4, 1, 7, 5], [6, 6, 4, 1, 8, 0], [6, 6, 4, 2, 0, 6], [6, 6, 4, 2, 1, 1], [6, 6, 4, 2, 2, 5], [6, 6, 4, 2, 3, 0], [6, 6, 4, 2, 4, 4], [6, 6, 4, 2, 5, 8], [6, 6, 4, 2, 6, 3], [6, 6, 4, 2, 7, 7], [6, 6, 4, 2, 8, 2], [6, 6, 4, 3, 0, 8], [6, 6, 4, 3, 1, 3], [6, 6, 4, 3, 2, 7], [6, 6, 4, 3, 3, 2], [6, 6, 4, 3, 4, 6], [6, 6, 4, 3, 5, 1], [6, 6, 4, 3, 6, 5], [6, 6, 4, 3, 7, 0], [6, 6, 4, 3, 8, 4], [6, 6, 4, 4, 0, 1], [6, 6, 4, 4, 1, 5], [6, 6, 4, 4, 2, 0], [6, 6, 4, 4, 3, 4], [6, 6, 4, 4, 4, 8], [6, 6, 4, 4, 5, 3], [6, 6, 4, 4, 6, 7], [6, 6, 4, 4, 7, 2], [6, 6, 4, 4, 8, 6], [6, 6, 4, 5, 0, 3], [6, 6, 4, 5, 1, 7], [6, 6, 4, 5, 2, 2], [6, 6, 4, 5, 3, 6], [6, 6, 4, 5, 4, 1], [6, 6, 4, 5, 5, 5], [6, 6, 4, 5, 6, 0], [6, 6, 4, 5, 7, 4], [6, 6, 4, 5, 8, 8], [6, 6, 4, 6, 0, 5], [6, 6, 4, 6, 1, 0], [6, 6, 4, 6, 2, 4], [6, 6, 4, 6, 3, 8], [6, 6, 4, 6, 4, 3], [6, 6, 4, 6, 5, 7], [6, 6, 4, 6, 6, 2], [6, 6, 4, 6, 7, 6], [6, 6, 4, 6, 8, 1], [6, 6, 4, 7, 0, 7], [6, 6, 4, 7, 1, 2], [6, 6, 4, 7, 2, 6], [6, 6, 4, 7, 3, 1], [6, 6, 4, 7, 4, 5], [6, 6, 4, 7, 5, 0], [6, 6, 4, 7, 6, 4], [6, 6, 4, 7, 7, 8], [6, 6, 4, 7, 8, 3], [6, 6, 4, 8, 0, 0], [6, 6, 4, 8, 1, 4], [6, 6, 4, 8, 2, 8], [6, 6, 4, 8, 3, 3], [6, 6, 4, 8, 4, 7], [6, 6, 4, 8, 5, 2], [6, 6, 4, 8, 6, 6], [6, 6, 4, 8, 7, 1], [6, 6, 4, 8, 8, 5], [6, 7, 8, 0, 0, 2], [6, 7, 8, 0, 1, 6], [6, 7, 8, 0, 2, 1], [6, 7, 8, 0, 3, 5], [6, 7, 8, 0, 4, 0], [6, 7, 8, 0, 5, 4], [6, 7, 8, 0, 6, 8], [6, 7, 8, 0, 7, 3], [6, 7, 8, 0, 8, 7], [6, 7, 8, 1, 0, 4], [6, 7, 8, 1, 1, 8], [6, 7, 8, 1, 2, 3], [6, 7, 8, 1, 3, 7], [6, 7, 8, 1, 4, 2], [6, 7, 8, 1, 5, 6], [6, 7, 8, 1, 6, 1], [6, 7, 8, 1, 7, 5], [6, 7, 8, 1, 8, 0], [6, 7, 8, 2, 0, 6], [6, 7, 8, 2, 1, 1], [6, 7, 8, 2, 2, 5], [6, 7, 8, 2, 3, 0], [6, 7, 8, 2, 4, 4], [6, 7, 8, 2, 5, 8], [6, 7, 8, 2, 6, 3], [6, 7, 8, 2, 7, 7], [6, 7, 8, 2, 8, 2], [6, 7, 8, 3, 0, 8], [6, 7, 8, 3, 1, 3], [6, 7, 8, 3, 2, 7], [6, 7, 8, 3, 3, 2], [6, 7, 8, 3, 4, 6], [6, 7, 8, 3, 5, 1], [6, 7, 8, 3, 6, 5], [6, 7, 8, 3, 7, 0], [6, 7, 8, 3, 8, 4], [6, 7, 8, 4, 0, 1], [6, 7, 8, 4, 1, 5], [6, 7, 8, 4, 2, 0], [6, 7, 8, 4, 3, 4], [6, 7, 8, 4, 4, 8], [6, 7, 8, 4, 5, 3], [6, 7, 8, 4, 6, 7], [6, 7, 8, 4, 7, 2], [6, 7, 8, 4, 8, 6], [6, 7, 8, 5, 0, 3], [6, 7, 8, 5, 1, 7], [6, 7, 8, 5, 2, 2], [6, 7, 8, 5, 3, 6], [6, 7, 8, 5, 4, 1], [6, 7, 8, 5, 5, 5], [6, 7, 8, 5, 6, 0], [6, 7, 8, 5, 7, 4], [6, 7, 8, 5, 8, 8], [6, 7, 8, 6, 0, 5], [6, 7, 8, 6, 1, 0], [6, 7, 8, 6, 2, 4], [6, 7, 8, 6, 3, 8], [6, 7, 8, 6, 4, 3], [6, 7, 8, 6, 5, 7], [6, 7, 8, 6, 6, 2], [6, 7, 8, 6, 7, 6], [6, 7, 8, 6, 8, 1], [6, 7, 8, 7, 0, 7], [6, 7, 8, 7, 1, 2], [6, 7, 8, 7, 2, 6], [6, 7, 8, 7, 3, 1], [6, 7, 8, 7, 4, 5], [6, 7, 8, 7, 5, 0], [6, 7, 8, 7, 6, 4], [6, 7, 8, 7, 7, 8], [6, 7, 8, 7, 8, 3], [6, 7, 8, 8, 0, 0], [6, 7, 8, 8, 1, 4], [6, 7, 8, 8, 2, 8], [6, 7, 8, 8, 3, 3], [6, 7, 8, 8, 4, 7], [6, 7, 8, 8, 5, 2], [6, 7, 8, 8, 6, 6], [6, 7, 8, 8, 7, 1], [6, 7, 8, 8, 8, 5], [6, 8, 3, 0, 0, 2], [6, 8, 3, 0, 1, 6], [6, 8, 3, 0, 2, 1], [6, 8, 3, 0, 3, 5], [6, 8, 3, 0, 4, 0], [6, 8, 3, 0, 5, 4], [6, 8, 3, 0, 6, 8], [6, 8, 3, 0, 7, 3], [6, 8, 3, 0, 8, 7], [6, 8, 3, 1, 0, 4], [6, 8, 3, 1, 1, 8], [6, 8, 3, 1, 2, 3], [6, 8, 3, 1, 3, 7], [6, 8, 3, 1, 4, 2], [6, 8, 3, 1, 5, 6], [6, 8, 3, 1, 6, 1], [6, 8, 3, 1, 7, 5], [6, 8, 3, 1, 8, 0], [6, 8, 3, 2, 0, 6], [6, 8, 3, 2, 1, 1], [6, 8, 3, 2, 2, 5], [6, 8, 3, 2, 3, 0], [6, 8, 3, 2, 4, 4], [6, 8, 3, 2, 5, 8], [6, 8, 3, 2, 6, 3], [6, 8, 3, 2, 7, 7], [6, 8, 3, 2, 8, 2], [6, 8, 3, 3, 0, 8], [6, 8, 3, 3, 1, 3], [6, 8, 3, 3, 2, 7], [6, 8, 3, 3, 3, 2], [6, 8, 3, 3, 4, 6], [6, 8, 3, 3, 5, 1], [6, 8, 3, 3, 6, 5], [6, 8, 3, 3, 7, 0], [6, 8, 3, 3, 8, 4], [6, 8, 3, 4, 0, 1], [6, 8, 3, 4, 1, 5], [6, 8, 3, 4, 2, 0], [6, 8, 3, 4, 3, 4], [6, 8, 3, 4, 4, 8], [6, 8, 3, 4, 5, 3], [6, 8, 3, 4, 6, 7], [6, 8, 3, 4, 7, 2], [6, 8, 3, 4, 8, 6], [6, 8, 3, 5, 0, 3], [6, 8, 3, 5, 1, 7], [6, 8, 3, 5, 2, 2], [6, 8, 3, 5, 3, 6], [6, 8, 3, 5, 4, 1], [6, 8, 3, 5, 5, 5], [6, 8, 3, 5, 6, 0], [6, 8, 3, 5, 7, 4], [6, 8, 3, 5, 8, 8], [6, 8, 3, 6, 0, 5], [6, 8, 3, 6, 1, 0], [6, 8, 3, 6, 2, 4], [6, 8, 3, 6, 3, 8], [6, 8, 3, 6, 4, 3], [6, 8, 3, 6, 5, 7], [6, 8, 3, 6, 6, 2], [6, 8, 3, 6, 7, 6], [6, 8, 3, 6, 8, 1], [6, 8, 3, 7, 0, 7], [6, 8, 3, 7, 1, 2], [6, 8, 3, 7, 2, 6], [6, 8, 3, 7, 3, 1], [6, 8, 3, 7, 4, 5], [6, 8, 3, 7, 5, 0], [6, 8, 3, 7, 6, 4], [6, 8, 3, 7, 7, 8], [6, 8, 3, 7, 8, 3], [6, 8, 3, 8, 0, 0], [6, 8, 3, 8, 1, 4], [6, 8, 3, 8, 2, 8], [6, 8, 3, 8, 3, 3], [6, 8, 3, 8, 4, 7], [6, 8, 3, 8, 5, 2], [6, 8, 3, 8, 6, 6], [6, 8, 3, 8, 7, 1], [6, 8, 3, 8, 8, 5], [7, 0, 0, 0, 0, 2], [7, 0, 0, 0, 1, 6], [7, 0, 0, 0, 2, 1], [7, 0, 0, 0, 3, 5], [7, 0, 0, 0, 4, 0], [7, 0, 0, 0, 5, 4], [7, 0, 0, 0, 6, 8], [7, 0, 0, 0, 7, 3], [7, 0, 0, 0, 8, 7], [7, 0, 0, 1, 0, 4], [7, 0, 0, 1, 1, 8], [7, 0, 0, 1, 2, 3], [7, 0, 0, 1, 3, 7], [7, 0, 0, 1, 4, 2], [7, 0, 0, 1, 5, 6], [7, 0, 0, 1, 6, 1], [7, 0, 0, 1, 7, 5], [7, 0, 0, 1, 8, 0], [7, 0, 0, 2, 0, 6], [7, 0, 0, 2, 1, 1], [7, 0, 0, 2, 2, 5], [7, 0, 0, 2, 3, 0], [7, 0, 0, 2, 4, 4], [7, 0, 0, 2, 5, 8], [7, 0, 0, 2, 6, 3], [7, 0, 0, 2, 7, 7], [7, 0, 0, 2, 8, 2], [7, 0, 0, 3, 0, 8], [7, 0, 0, 3, 1, 3], [7, 0, 0, 3, 2, 7], [7, 0, 0, 3, 3, 2], [7, 0, 0, 3, 4, 6], [7, 0, 0, 3, 5, 1], [7, 0, 0, 3, 6, 5], [7, 0, 0, 3, 7, 0], [7, 0, 0, 3, 8, 4], [7, 0, 0, 4, 0, 1], [7, 0, 0, 4, 1, 5], [7, 0, 0, 4, 2, 0], [7, 0, 0, 4, 3, 4], [7, 0, 0, 4, 4, 8], [7, 0, 0, 4, 5, 3], [7, 0, 0, 4, 6, 7], [7, 0, 0, 4, 7, 2], [7, 0, 0, 4, 8, 6], [7, 0, 0, 5, 0, 3], [7, 0, 0, 5, 1, 7], [7, 0, 0, 5, 2, 2], [7, 0, 0, 5, 3, 6], [7, 0, 0, 5, 4, 1], [7, 0, 0, 5, 5, 5], [7, 0, 0, 5, 6, 0], [7, 0, 0, 5, 7, 4], [7, 0, 0, 5, 8, 8], [7, 0, 0, 6, 0, 5], [7, 0, 0, 6, 1, 0], [7, 0, 0, 6, 2, 4], [7, 0, 0, 6, 3, 8], [7, 0, 0, 6, 4, 3], [7, 0, 0, 6, 5, 7], [7, 0, 0, 6, 6, 2], [7, 0, 0, 6, 7, 6], [7, 0, 0, 6, 8, 1], [7, 0, 0, 7, 0, 7], [7, 0, 0, 7, 1, 2], [7, 0, 0, 7, 2, 6], [7, 0, 0, 7, 3, 1], [7, 0, 0, 7, 4, 5], [7, 0, 0, 7, 5, 0], [7, 0, 0, 7, 6, 4], [7, 0, 0, 7, 7, 8], [7, 0, 0, 7, 8, 3], [7, 0, 0, 8, 0, 0], [7, 0, 0, 8, 1, 4], [7, 0, 0, 8, 2, 8], [7, 0, 0, 8, 3, 3], [7, 0, 0, 8, 4, 7], [7, 0, 0, 8, 5, 2], [7, 0, 0, 8, 6, 6], [7, 0, 0, 8, 7, 1], [7, 0, 0, 8, 8, 5], [7, 1, 4, 0, 0, 2], [7, 1, 4, 0, 1, 6], [7, 1, 4, 0, 2, 1], [7, 1, 4, 0, 3, 5], [7, 1, 4, 0, 4, 0], [7, 1, 4, 0, 5, 4], [7, 1, 4, 0, 6, 8], [7, 1, 4, 0, 7, 3], [7, 1, 4, 0, 8, 7], [7, 1, 4, 1, 0, 4], [7, 1, 4, 1, 1, 8], [7, 1, 4, 1, 2, 3], [7, 1, 4, 1, 3, 7], [7, 1, 4, 1, 4, 2], [7, 1, 4, 1, 5, 6], [7, 1, 4, 1, 6, 1], [7, 1, 4, 1, 7, 5], [7, 1, 4, 1, 8, 0], [7, 1, 4, 2, 0, 6], [7, 1, 4, 2, 1, 1], [7, 1, 4, 2, 2, 5], [7, 1, 4, 2, 3, 0], [7, 1, 4, 2, 4, 4], [7, 1, 4, 2, 5, 8], [7, 1, 4, 2, 6, 3], [7, 1, 4, 2, 7, 7], [7, 1, 4, 2, 8, 2], [7, 1, 4, 3, 0, 8], [7, 1, 4, 3, 1, 3], [7, 1, 4, 3, 2, 7], [7, 1, 4, 3, 3, 2], [7, 1, 4, 3, 4, 6], [7, 1, 4, 3, 5, 1], [7, 1, 4, 3, 6, 5], [7, 1, 4, 3, 7, 0], [7, 1, 4, 3, 8, 4], [7, 1, 4, 4, 0, 1], [7, 1, 4, 4, 1, 5], [7, 1, 4, 4, 2, 0], [7, 1, 4, 4, 3, 4], [7, 1, 4, 4, 4, 8], [7, 1, 4, 4, 5, 3], [7, 1, 4, 4, 6, 7], [7, 1, 4, 4, 7, 2], [7, 1, 4, 4, 8, 6], [7, 1, 4, 5, 0, 3], [7, 1, 4, 5, 1, 7], [7, 1, 4, 5, 2, 2], [7, 1, 4, 5, 3, 6], [7, 1, 4, 5, 4, 1], [7, 1, 4, 5, 5, 5], [7, 1, 4, 5, 6, 0], [7, 1, 4, 5, 7, 4], [7, 1, 4, 5, 8, 8], [7, 1, 4, 6, 0, 5], [7, 1, 4, 6, 1, 0], [7, 1, 4, 6, 2, 4], [7, 1, 4, 6, 3, 8], [7, 1, 4, 6, 4, 3], [7, 1, 4, 6, 5, 7], [7, 1, 4, 6, 6, 2], [7, 1, 4, 6, 7, 6], [7, 1, 4, 6, 8, 1], [7, 1, 4, 7, 0, 7], [7, 1, 4, 7, 1, 2], [7, 1, 4, 7, 2, 6], [7, 1, 4, 7, 3, 1], [7, 1, 4, 7, 4, 5], [7, 1, 4, 7, 5, 0], [7, 1, 4, 7, 6, 4], [7, 1, 4, 7, 7, 8], [7, 1, 4, 7, 8, 3], [7, 1, 4, 8, 0, 0], [7, 1, 4, 8, 1, 4], [7, 1, 4, 8, 2, 8], [7, 1, 4, 8, 3, 3], [7, 1, 4, 8, 4, 7], [7, 1, 4, 8, 5, 2], [7, 1, 4, 8, 6, 6], [7, 1, 4, 8, 7, 1], [7, 1, 4, 8, 8, 5], [7, 2, 8, 0, 0, 2], [7, 2, 8, 0, 1, 6], [7, 2, 8, 0, 2, 1], [7, 2, 8, 0, 3, 5], [7, 2, 8, 0, 4, 0], [7, 2, 8, 0, 5, 4], [7, 2, 8, 0, 6, 8], [7, 2, 8, 0, 7, 3], [7, 2, 8, 0, 8, 7], [7, 2, 8, 1, 0, 4], [7, 2, 8, 1, 1, 8], [7, 2, 8, 1, 2, 3], [7, 2, 8, 1, 3, 7], [7, 2, 8, 1, 4, 2], [7, 2, 8, 1, 5, 6], [7, 2, 8, 1, 6, 1], [7, 2, 8, 1, 7, 5], [7, 2, 8, 1, 8, 0], [7, 2, 8, 2, 0, 6], [7, 2, 8, 2, 1, 1], [7, 2, 8, 2, 2, 5], [7, 2, 8, 2, 3, 0], [7, 2, 8, 2, 4, 4], [7, 2, 8, 2, 5, 8], [7, 2, 8, 2, 6, 3], [7, 2, 8, 2, 7, 7], [7, 2, 8, 2, 8, 2], [7, 2, 8, 3, 0, 8], [7, 2, 8, 3, 1, 3], [7, 2, 8, 3, 2, 7], [7, 2, 8, 3, 3, 2], [7, 2, 8, 3, 4, 6], [7, 2, 8, 3, 5, 1], [7, 2, 8, 3, 6, 5], [7, 2, 8, 3, 7, 0], [7, 2, 8, 3, 8, 4], [7, 2, 8, 4, 0, 1], [7, 2, 8, 4, 1, 5], [7, 2, 8, 4, 2, 0], [7, 2, 8, 4, 3, 4], [7, 2, 8, 4, 4, 8], [7, 2, 8, 4, 5, 3], [7, 2, 8, 4, 6, 7], [7, 2, 8, 4, 7, 2], [7, 2, 8, 4, 8, 6], [7, 2, 8, 5, 0, 3], [7, 2, 8, 5, 1, 7], [7, 2, 8, 5, 2, 2], [7, 2, 8, 5, 3, 6], [7, 2, 8, 5, 4, 1], [7, 2, 8, 5, 5, 5], [7, 2, 8, 5, 6, 0], [7, 2, 8, 5, 7, 4], [7, 2, 8, 5, 8, 8], [7, 2, 8, 6, 0, 5], [7, 2, 8, 6, 1, 0], [7, 2, 8, 6, 2, 4], [7, 2, 8, 6, 3, 8], [7, 2, 8, 6, 4, 3], [7, 2, 8, 6, 5, 7], [7, 2, 8, 6, 6, 2], [7, 2, 8, 6, 7, 6], [7, 2, 8, 6, 8, 1], [7, 2, 8, 7, 0, 7], [7, 2, 8, 7, 1, 2], [7, 2, 8, 7, 2, 6], [7, 2, 8, 7, 3, 1], [7, 2, 8, 7, 4, 5], [7, 2, 8, 7, 5, 0], [7, 2, 8, 7, 6, 4], [7, 2, 8, 7, 7, 8], [7, 2, 8, 7, 8, 3], [7, 2, 8, 8, 0, 0], [7, 2, 8, 8, 1, 4], [7, 2, 8, 8, 2, 8], [7, 2, 8, 8, 3, 3], [7, 2, 8, 8, 4, 7], [7, 2, 8, 8, 5, 2], [7, 2, 8, 8, 6, 6], [7, 2, 8, 8, 7, 1], [7, 2, 8, 8, 8, 5], [7, 3, 3, 0, 0, 2], [7, 3, 3, 0, 1, 6], [7, 3, 3, 0, 2, 1], [7, 3, 3, 0, 3, 5], [7, 3, 3, 0, 4, 0], [7, 3, 3, 0, 5, 4], [7, 3, 3, 0, 6, 8], [7, 3, 3, 0, 7, 3], [7, 3, 3, 0, 8, 7], [7, 3, 3, 1, 0, 4], [7, 3, 3, 1, 1, 8], [7, 3, 3, 1, 2, 3], [7, 3, 3, 1, 3, 7], [7, 3, 3, 1, 4, 2], [7, 3, 3, 1, 5, 6], [7, 3, 3, 1, 6, 1], [7, 3, 3, 1, 7, 5], [7, 3, 3, 1, 8, 0], [7, 3, 3, 2, 0, 6], [7, 3, 3, 2, 1, 1], [7, 3, 3, 2, 2, 5], [7, 3, 3, 2, 3, 0], [7, 3, 3, 2, 4, 4], [7, 3, 3, 2, 5, 8], [7, 3, 3, 2, 6, 3], [7, 3, 3, 2, 7, 7], [7, 3, 3, 2, 8, 2], [7, 3, 3, 3, 0, 8], [7, 3, 3, 3, 1, 3], [7, 3, 3, 3, 2, 7], [7, 3, 3, 3, 3, 2], [7, 3, 3, 3, 4, 6], [7, 3, 3, 3, 5, 1], [7, 3, 3, 3, 6, 5], [7, 3, 3, 3, 7, 0], [7, 3, 3, 3, 8, 4], [7, 3, 3, 4, 0, 1], [7, 3, 3, 4, 1, 5], [7, 3, 3, 4, 2, 0], [7, 3, 3, 4, 3, 4], [7, 3, 3, 4, 4, 8], [7, 3, 3, 4, 5, 3], [7, 3, 3, 4, 6, 7], [7, 3, 3, 4, 7, 2], [7, 3, 3, 4, 8, 6], [7, 3, 3, 5, 0, 3], [7, 3, 3, 5, 1, 7], [7, 3, 3, 5, 2, 2], [7, 3, 3, 5, 3, 6], [7, 3, 3, 5, 4, 1], [7, 3, 3, 5, 5, 5], [7, 3, 3, 5, 6, 0], [7, 3, 3, 5, 7, 4], [7, 3, 3, 5, 8, 8], [7, 3, 3, 6, 0, 5], [7, 3, 3, 6, 1, 0], [7, 3, 3, 6, 2, 4], [7, 3, 3, 6, 3, 8], [7, 3, 3, 6, 4, 3], [7, 3, 3, 6, 5, 7], [7, 3, 3, 6, 6, 2], [7, 3, 3, 6, 7, 6], [7, 3, 3, 6, 8, 1], [7, 3, 3, 7, 0, 7], [7, 3, 3, 7, 1, 2], [7, 3, 3, 7, 2, 6], [7, 3, 3, 7, 3, 1], [7, 3, 3, 7, 4, 5], [7, 3, 3, 7, 5, 0], [7, 3, 3, 7, 6, 4], [7, 3, 3, 7, 7, 8], [7, 3, 3, 7, 8, 3], [7, 3, 3, 8, 0, 0], [7, 3, 3, 8, 1, 4], [7, 3, 3, 8, 2, 8], [7, 3, 3, 8, 3, 3], [7, 3, 3, 8, 4, 7], [7, 3, 3, 8, 5, 2], [7, 3, 3, 8, 6, 6], [7, 3, 3, 8, 7, 1], [7, 3, 3, 8, 8, 5], [7, 4, 7, 0, 0, 2], [7, 4, 7, 0, 1, 6], [7, 4, 7, 0, 2, 1], [7, 4, 7, 0, 3, 5], [7, 4, 7, 0, 4, 0], [7, 4, 7, 0, 5, 4], [7, 4, 7, 0, 6, 8], [7, 4, 7, 0, 7, 3], [7, 4, 7, 0, 8, 7], [7, 4, 7, 1, 0, 4], [7, 4, 7, 1, 1, 8], [7, 4, 7, 1, 2, 3], [7, 4, 7, 1, 3, 7], [7, 4, 7, 1, 4, 2], [7, 4, 7, 1, 5, 6], [7, 4, 7, 1, 6, 1], [7, 4, 7, 1, 7, 5], [7, 4, 7, 1, 8, 0], [7, 4, 7, 2, 0, 6], [7, 4, 7, 2, 1, 1], [7, 4, 7, 2, 2, 5], [7, 4, 7, 2, 3, 0], [7, 4, 7, 2, 4, 4], [7, 4, 7, 2, 5, 8], [7, 4, 7, 2, 6, 3], [7, 4, 7, 2, 7, 7], [7, 4, 7, 2, 8, 2], [7, 4, 7, 3, 0, 8], [7, 4, 7, 3, 1, 3], [7, 4, 7, 3, 2, 7], [7, 4, 7, 3, 3, 2], [7, 4, 7, 3, 4, 6], [7, 4, 7, 3, 5, 1], [7, 4, 7, 3, 6, 5], [7, 4, 7, 3, 7, 0], [7, 4, 7, 3, 8, 4], [7, 4, 7, 4, 0, 1], [7, 4, 7, 4, 1, 5], [7, 4, 7, 4, 2, 0], [7, 4, 7, 4, 3, 4], [7, 4, 7, 4, 4, 8], [7, 4, 7, 4, 5, 3], [7, 4, 7, 4, 6, 7], [7, 4, 7, 4, 7, 2], [7, 4, 7, 4, 8, 6], [7, 4, 7, 5, 0, 3], [7, 4, 7, 5, 1, 7], [7, 4, 7, 5, 2, 2], [7, 4, 7, 5, 3, 6], [7, 4, 7, 5, 4, 1], [7, 4, 7, 5, 5, 5], [7, 4, 7, 5, 6, 0], [7, 4, 7, 5, 7, 4], [7, 4, 7, 5, 8, 8], [7, 4, 7, 6, 0, 5], [7, 4, 7, 6, 1, 0], [7, 4, 7, 6, 2, 4], [7, 4, 7, 6, 3, 8], [7, 4, 7, 6, 4, 3], [7, 4, 7, 6, 5, 7], [7, 4, 7, 6, 6, 2], [7, 4, 7, 6, 7, 6], [7, 4, 7, 6, 8, 1], [7, 4, 7, 7, 0, 7], [7, 4, 7, 7, 1, 2], [7, 4, 7, 7, 2, 6], [7, 4, 7, 7, 3, 1], [7, 4, 7, 7, 4, 5], [7, 4, 7, 7, 5, 0], [7, 4, 7, 7, 6, 4], [7, 4, 7, 7, 7, 8], [7, 4, 7, 7, 8, 3], [7, 4, 7, 8, 0, 0], [7, 4, 7, 8, 1, 4], [7, 4, 7, 8, 2, 8], [7, 4, 7, 8, 3, 3], [7, 4, 7, 8, 4, 7], [7, 4, 7, 8, 5, 2], [7, 4, 7, 8, 6, 6], [7, 4, 7, 8, 7, 1], [7, 4, 7, 8, 8, 5], [7, 5, 2, 0, 0, 2], [7, 5, 2, 0, 1, 6], [7, 5, 2, 0, 2, 1], [7, 5, 2, 0, 3, 5], [7, 5, 2, 0, 4, 0], [7, 5, 2, 0, 5, 4], [7, 5, 2, 0, 6, 8], [7, 5, 2, 0, 7, 3], [7, 5, 2, 0, 8, 7], [7, 5, 2, 1, 0, 4], [7, 5, 2, 1, 1, 8], [7, 5, 2, 1, 2, 3], [7, 5, 2, 1, 3, 7], [7, 5, 2, 1, 4, 2], [7, 5, 2, 1, 5, 6], [7, 5, 2, 1, 6, 1], [7, 5, 2, 1, 7, 5], [7, 5, 2, 1, 8, 0], [7, 5, 2, 2, 0, 6], [7, 5, 2, 2, 1, 1], [7, 5, 2, 2, 2, 5], [7, 5, 2, 2, 3, 0], [7, 5, 2, 2, 4, 4], [7, 5, 2, 2, 5, 8], [7, 5, 2, 2, 6, 3], [7, 5, 2, 2, 7, 7], [7, 5, 2, 2, 8, 2], [7, 5, 2, 3, 0, 8], [7, 5, 2, 3, 1, 3], [7, 5, 2, 3, 2, 7], [7, 5, 2, 3, 3, 2], [7, 5, 2, 3, 4, 6], [7, 5, 2, 3, 5, 1], [7, 5, 2, 3, 6, 5], [7, 5, 2, 3, 7, 0], [7, 5, 2, 3, 8, 4], [7, 5, 2, 4, 0, 1], [7, 5, 2, 4, 1, 5], [7, 5, 2, 4, 2, 0], [7, 5, 2, 4, 3, 4], [7, 5, 2, 4, 4, 8], [7, 5, 2, 4, 5, 3], [7, 5, 2, 4, 6, 7], [7, 5, 2, 4, 7, 2], [7, 5, 2, 4, 8, 6], [7, 5, 2, 5, 0, 3], [7, 5, 2, 5, 1, 7], [7, 5, 2, 5, 2, 2], [7, 5, 2, 5, 3, 6], [7, 5, 2, 5, 4, 1], [7, 5, 2, 5, 5, 5], [7, 5, 2, 5, 6, 0], [7, 5, 2, 5, 7, 4], [7, 5, 2, 5, 8, 8], [7, 5, 2, 6, 0, 5], [7, 5, 2, 6, 1, 0], [7, 5, 2, 6, 2, 4], [7, 5, 2, 6, 3, 8], [7, 5, 2, 6, 4, 3], [7, 5, 2, 6, 5, 7], [7, 5, 2, 6, 6, 2], [7, 5, 2, 6, 7, 6], [7, 5, 2, 6, 8, 1], [7, 5, 2, 7, 0, 7], [7, 5, 2, 7, 1, 2], [7, 5, 2, 7, 2, 6], [7, 5, 2, 7, 3, 1], [7, 5, 2, 7, 4, 5], [7, 5, 2, 7, 5, 0], [7, 5, 2, 7, 6, 4], [7, 5, 2, 7, 7, 8], [7, 5, 2, 7, 8, 3], [7, 5, 2, 8, 0, 0], [7, 5, 2, 8, 1, 4], [7, 5, 2, 8, 2, 8], [7, 5, 2, 8, 3, 3], [7, 5, 2, 8, 4, 7], [7, 5, 2, 8, 5, 2], [7, 5, 2, 8, 6, 6], [7, 5, 2, 8, 7, 1], [7, 5, 2, 8, 8, 5], [7, 6, 6, 0, 0, 2], [7, 6, 6, 0, 1, 6], [7, 6, 6, 0, 2, 1], [7, 6, 6, 0, 3, 5], [7, 6, 6, 0, 4, 0], [7, 6, 6, 0, 5, 4], [7, 6, 6, 0, 6, 8], [7, 6, 6, 0, 7, 3], [7, 6, 6, 0, 8, 7], [7, 6, 6, 1, 0, 4], [7, 6, 6, 1, 1, 8], [7, 6, 6, 1, 2, 3], [7, 6, 6, 1, 3, 7], [7, 6, 6, 1, 4, 2], [7, 6, 6, 1, 5, 6], [7, 6, 6, 1, 6, 1], [7, 6, 6, 1, 7, 5], [7, 6, 6, 1, 8, 0], [7, 6, 6, 2, 0, 6], [7, 6, 6, 2, 1, 1], [7, 6, 6, 2, 2, 5], [7, 6, 6, 2, 3, 0], [7, 6, 6, 2, 4, 4], [7, 6, 6, 2, 5, 8], [7, 6, 6, 2, 6, 3], [7, 6, 6, 2, 7, 7], [7, 6, 6, 2, 8, 2], [7, 6, 6, 3, 0, 8], [7, 6, 6, 3, 1, 3], [7, 6, 6, 3, 2, 7], [7, 6, 6, 3, 3, 2], [7, 6, 6, 3, 4, 6], [7, 6, 6, 3, 5, 1], [7, 6, 6, 3, 6, 5], [7, 6, 6, 3, 7, 0], [7, 6, 6, 3, 8, 4], [7, 6, 6, 4, 0, 1], [7, 6, 6, 4, 1, 5], [7, 6, 6, 4, 2, 0], [7, 6, 6, 4, 3, 4], [7, 6, 6, 4, 4, 8], [7, 6, 6, 4, 5, 3], [7, 6, 6, 4, 6, 7], [7, 6, 6, 4, 7, 2], [7, 6, 6, 4, 8, 6], [7, 6, 6, 5, 0, 3], [7, 6, 6, 5, 1, 7], [7, 6, 6, 5, 2, 2], [7, 6, 6, 5, 3, 6], [7, 6, 6, 5, 4, 1], [7, 6, 6, 5, 5, 5], [7, 6, 6, 5, 6, 0], [7, 6, 6, 5, 7, 4], [7, 6, 6, 5, 8, 8], [7, 6, 6, 6, 0, 5], [7, 6, 6, 6, 1, 0], [7, 6, 6, 6, 2, 4], [7, 6, 6, 6, 3, 8], [7, 6, 6, 6, 4, 3], [7, 6, 6, 6, 5, 7], [7, 6, 6, 6, 6, 2], [7, 6, 6, 6, 7, 6], [7, 6, 6, 6, 8, 1], [7, 6, 6, 7, 0, 7], [7, 6, 6, 7, 1, 2], [7, 6, 6, 7, 2, 6], [7, 6, 6, 7, 3, 1], [7, 6, 6, 7, 4, 5], [7, 6, 6, 7, 5, 0], [7, 6, 6, 7, 6, 4], [7, 6, 6, 7, 7, 8], [7, 6, 6, 7, 8, 3], [7, 6, 6, 8, 0, 0], [7, 6, 6, 8, 1, 4], [7, 6, 6, 8, 2, 8], [7, 6, 6, 8, 3, 3], [7, 6, 6, 8, 4, 7], [7, 6, 6, 8, 5, 2], [7, 6, 6, 8, 6, 6], [7, 6, 6, 8, 7, 1], [7, 6, 6, 8, 8, 5], [7, 7, 1, 0, 0, 2], [7, 7, 1, 0, 1, 6], [7, 7, 1, 0, 2, 1], [7, 7, 1, 0, 3, 5], [7, 7, 1, 0, 4, 0], [7, 7, 1, 0, 5, 4], [7, 7, 1, 0, 6, 8], [7, 7, 1, 0, 7, 3], [7, 7, 1, 0, 8, 7], [7, 7, 1, 1, 0, 4], [7, 7, 1, 1, 1, 8], [7, 7, 1, 1, 2, 3], [7, 7, 1, 1, 3, 7], [7, 7, 1, 1, 4, 2], [7, 7, 1, 1, 5, 6], [7, 7, 1, 1, 6, 1], [7, 7, 1, 1, 7, 5], [7, 7, 1, 1, 8, 0], [7, 7, 1, 2, 0, 6], [7, 7, 1, 2, 1, 1], [7, 7, 1, 2, 2, 5], [7, 7, 1, 2, 3, 0], [7, 7, 1, 2, 4, 4], [7, 7, 1, 2, 5, 8], [7, 7, 1, 2, 6, 3], [7, 7, 1, 2, 7, 7], [7, 7, 1, 2, 8, 2], [7, 7, 1, 3, 0, 8], [7, 7, 1, 3, 1, 3], [7, 7, 1, 3, 2, 7], [7, 7, 1, 3, 3, 2], [7, 7, 1, 3, 4, 6], [7, 7, 1, 3, 5, 1], [7, 7, 1, 3, 6, 5], [7, 7, 1, 3, 7, 0], [7, 7, 1, 3, 8, 4], [7, 7, 1, 4, 0, 1], [7, 7, 1, 4, 1, 5], [7, 7, 1, 4, 2, 0], [7, 7, 1, 4, 3, 4], [7, 7, 1, 4, 4, 8], [7, 7, 1, 4, 5, 3], [7, 7, 1, 4, 6, 7], [7, 7, 1, 4, 7, 2], [7, 7, 1, 4, 8, 6], [7, 7, 1, 5, 0, 3], [7, 7, 1, 5, 1, 7], [7, 7, 1, 5, 2, 2], [7, 7, 1, 5, 3, 6], [7, 7, 1, 5, 4, 1], [7, 7, 1, 5, 5, 5], [7, 7, 1, 5, 6, 0], [7, 7, 1, 5, 7, 4], [7, 7, 1, 5, 8, 8], [7, 7, 1, 6, 0, 5], [7, 7, 1, 6, 1, 0], [7, 7, 1, 6, 2, 4], [7, 7, 1, 6, 3, 8], [7, 7, 1, 6, 4, 3], [7, 7, 1, 6, 5, 7], [7, 7, 1, 6, 6, 2], [7, 7, 1, 6, 7, 6], [7, 7, 1, 6, 8, 1], [7, 7, 1, 7, 0, 7], [7, 7, 1, 7, 1, 2], [7, 7, 1, 7, 2, 6], [7, 7, 1, 7, 3, 1], [7, 7, 1, 7, 4, 5], [7, 7, 1, 7, 5, 0], [7, 7, 1, 7, 6, 4], [7, 7, 1, 7, 7, 8], [7, 7, 1, 7, 8, 3], [7, 7, 1, 8, 0, 0], [7, 7, 1, 8, 1, 4], [7, 7, 1, 8, 2, 8], [7, 7, 1, 8, 3, 3], [7, 7, 1, 8, 4, 7], [7, 7, 1, 8, 5, 2], [7, 7, 1, 8, 6, 6], [7, 7, 1, 8, 7, 1], [7, 7, 1, 8, 8, 5], [7, 8, 5, 0, 0, 2], [7, 8, 5, 0, 1, 6], [7, 8, 5, 0, 2, 1], [7, 8, 5, 0, 3, 5], [7, 8, 5, 0, 4, 0], [7, 8, 5, 0, 5, 4], [7, 8, 5, 0, 6, 8], [7, 8, 5, 0, 7, 3], [7, 8, 5, 0, 8, 7], [7, 8, 5, 1, 0, 4], [7, 8, 5, 1, 1, 8], [7, 8, 5, 1, 2, 3], [7, 8, 5, 1, 3, 7], [7, 8, 5, 1, 4, 2], [7, 8, 5, 1, 5, 6], [7, 8, 5, 1, 6, 1], [7, 8, 5, 1, 7, 5], [7, 8, 5, 1, 8, 0], [7, 8, 5, 2, 0, 6], [7, 8, 5, 2, 1, 1], [7, 8, 5, 2, 2, 5], [7, 8, 5, 2, 3, 0], [7, 8, 5, 2, 4, 4], [7, 8, 5, 2, 5, 8], [7, 8, 5, 2, 6, 3], [7, 8, 5, 2, 7, 7], [7, 8, 5, 2, 8, 2], [7, 8, 5, 3, 0, 8], [7, 8, 5, 3, 1, 3], [7, 8, 5, 3, 2, 7], [7, 8, 5, 3, 3, 2], [7, 8, 5, 3, 4, 6], [7, 8, 5, 3, 5, 1], [7, 8, 5, 3, 6, 5], [7, 8, 5, 3, 7, 0], [7, 8, 5, 3, 8, 4], [7, 8, 5, 4, 0, 1], [7, 8, 5, 4, 1, 5], [7, 8, 5, 4, 2, 0], [7, 8, 5, 4, 3, 4], [7, 8, 5, 4, 4, 8], [7, 8, 5, 4, 5, 3], [7, 8, 5, 4, 6, 7], [7, 8, 5, 4, 7, 2], [7, 8, 5, 4, 8, 6], [7, 8, 5, 5, 0, 3], [7, 8, 5, 5, 1, 7], [7, 8, 5, 5, 2, 2], [7, 8, 5, 5, 3, 6], [7, 8, 5, 5, 4, 1], [7, 8, 5, 5, 5, 5], [7, 8, 5, 5, 6, 0], [7, 8, 5, 5, 7, 4], [7, 8, 5, 5, 8, 8], [7, 8, 5, 6, 0, 5], [7, 8, 5, 6, 1, 0], [7, 8, 5, 6, 2, 4], [7, 8, 5, 6, 3, 8], [7, 8, 5, 6, 4, 3], [7, 8, 5, 6, 5, 7], [7, 8, 5, 6, 6, 2], [7, 8, 5, 6, 7, 6], [7, 8, 5, 6, 8, 1], [7, 8, 5, 7, 0, 7], [7, 8, 5, 7, 1, 2], [7, 8, 5, 7, 2, 6], [7, 8, 5, 7, 3, 1], [7, 8, 5, 7, 4, 5], [7, 8, 5, 7, 5, 0], [7, 8, 5, 7, 6, 4], [7, 8, 5, 7, 7, 8], [7, 8, 5, 7, 8, 3], [7, 8, 5, 8, 0, 0], [7, 8, 5, 8, 1, 4], [7, 8, 5, 8, 2, 8], [7, 8, 5, 8, 3, 3], [7, 8, 5, 8, 4, 7], [7, 8, 5, 8, 5, 2], [7, 8, 5, 8, 6, 6], [7, 8, 5, 8, 7, 1], [7, 8, 5, 8, 8, 5], [8, 0, 2, 0, 0, 2], [8, 0, 2, 0, 1, 6], [8, 0, 2, 0, 2, 1], [8, 0, 2, 0, 3, 5], [8, 0, 2, 0, 4, 0], [8, 0, 2, 0, 5, 4], [8, 0, 2, 0, 6, 8], [8, 0, 2, 0, 7, 3], [8, 0, 2, 0, 8, 7], [8, 0, 2, 1, 0, 4], [8, 0, 2, 1, 1, 8], [8, 0, 2, 1, 2, 3], [8, 0, 2, 1, 3, 7], [8, 0, 2, 1, 4, 2], [8, 0, 2, 1, 5, 6], [8, 0, 2, 1, 6, 1], [8, 0, 2, 1, 7, 5], [8, 0, 2, 1, 8, 0], [8, 0, 2, 2, 0, 6], [8, 0, 2, 2, 1, 1], [8, 0, 2, 2, 2, 5], [8, 0, 2, 2, 3, 0], [8, 0, 2, 2, 4, 4], [8, 0, 2, 2, 5, 8], [8, 0, 2, 2, 6, 3], [8, 0, 2, 2, 7, 7], [8, 0, 2, 2, 8, 2], [8, 0, 2, 3, 0, 8], [8, 0, 2, 3, 1, 3], [8, 0, 2, 3, 2, 7], [8, 0, 2, 3, 3, 2], [8, 0, 2, 3, 4, 6], [8, 0, 2, 3, 5, 1], [8, 0, 2, 3, 6, 5], [8, 0, 2, 3, 7, 0], [8, 0, 2, 3, 8, 4], [8, 0, 2, 4, 0, 1], [8, 0, 2, 4, 1, 5], [8, 0, 2, 4, 2, 0], [8, 0, 2, 4, 3, 4], [8, 0, 2, 4, 4, 8], [8, 0, 2, 4, 5, 3], [8, 0, 2, 4, 6, 7], [8, 0, 2, 4, 7, 2], [8, 0, 2, 4, 8, 6], [8, 0, 2, 5, 0, 3], [8, 0, 2, 5, 1, 7], [8, 0, 2, 5, 2, 2], [8, 0, 2, 5, 3, 6], [8, 0, 2, 5, 4, 1], [8, 0, 2, 5, 5, 5], [8, 0, 2, 5, 6, 0], [8, 0, 2, 5, 7, 4], [8, 0, 2, 5, 8, 8], [8, 0, 2, 6, 0, 5], [8, 0, 2, 6, 1, 0], [8, 0, 2, 6, 2, 4], [8, 0, 2, 6, 3, 8], [8, 0, 2, 6, 4, 3], [8, 0, 2, 6, 5, 7], [8, 0, 2, 6, 6, 2], [8, 0, 2, 6, 7, 6], [8, 0, 2, 6, 8, 1], [8, 0, 2, 7, 0, 7], [8, 0, 2, 7, 1, 2], [8, 0, 2, 7, 2, 6], [8, 0, 2, 7, 3, 1], [8, 0, 2, 7, 4, 5], [8, 0, 2, 7, 5, 0], [8, 0, 2, 7, 6, 4], [8, 0, 2, 7, 7, 8], [8, 0, 2, 7, 8, 3], [8, 0, 2, 8, 0, 0], [8, 0, 2, 8, 1, 4], [8, 0, 2, 8, 2, 8], [8, 0, 2, 8, 3, 3], [8, 0, 2, 8, 4, 7], [8, 0, 2, 8, 5, 2], [8, 0, 2, 8, 6, 6], [8, 0, 2, 8, 7, 1], [8, 0, 2, 8, 8, 5], [8, 1, 6, 0, 0, 2], [8, 1, 6, 0, 1, 6], [8, 1, 6, 0, 2, 1], [8, 1, 6, 0, 3, 5], [8, 1, 6, 0, 4, 0], [8, 1, 6, 0, 5, 4], [8, 1, 6, 0, 6, 8], [8, 1, 6, 0, 7, 3], [8, 1, 6, 0, 8, 7], [8, 1, 6, 1, 0, 4], [8, 1, 6, 1, 1, 8], [8, 1, 6, 1, 2, 3], [8, 1, 6, 1, 3, 7], [8, 1, 6, 1, 4, 2], [8, 1, 6, 1, 5, 6], [8, 1, 6, 1, 6, 1], [8, 1, 6, 1, 7, 5], [8, 1, 6, 1, 8, 0], [8, 1, 6, 2, 0, 6], [8, 1, 6, 2, 1, 1], [8, 1, 6, 2, 2, 5], [8, 1, 6, 2, 3, 0], [8, 1, 6, 2, 4, 4], [8, 1, 6, 2, 5, 8], [8, 1, 6, 2, 6, 3], [8, 1, 6, 2, 7, 7], [8, 1, 6, 2, 8, 2], [8, 1, 6, 3, 0, 8], [8, 1, 6, 3, 1, 3], [8, 1, 6, 3, 2, 7], [8, 1, 6, 3, 3, 2], [8, 1, 6, 3, 4, 6], [8, 1, 6, 3, 5, 1], [8, 1, 6, 3, 6, 5], [8, 1, 6, 3, 7, 0], [8, 1, 6, 3, 8, 4], [8, 1, 6, 4, 0, 1], [8, 1, 6, 4, 1, 5], [8, 1, 6, 4, 2, 0], [8, 1, 6, 4, 3, 4], [8, 1, 6, 4, 4, 8], [8, 1, 6, 4, 5, 3], [8, 1, 6, 4, 6, 7], [8, 1, 6, 4, 7, 2], [8, 1, 6, 4, 8, 6], [8, 1, 6, 5, 0, 3], [8, 1, 6, 5, 1, 7], [8, 1, 6, 5, 2, 2], [8, 1, 6, 5, 3, 6], [8, 1, 6, 5, 4, 1], [8, 1, 6, 5, 5, 5], [8, 1, 6, 5, 6, 0], [8, 1, 6, 5, 7, 4], [8, 1, 6, 5, 8, 8], [8, 1, 6, 6, 0, 5], [8, 1, 6, 6, 1, 0], [8, 1, 6, 6, 2, 4], [8, 1, 6, 6, 3, 8], [8, 1, 6, 6, 4, 3], [8, 1, 6, 6, 5, 7], [8, 1, 6, 6, 6, 2], [8, 1, 6, 6, 7, 6], [8, 1, 6, 6, 8, 1], [8, 1, 6, 7, 0, 7], [8, 1, 6, 7, 1, 2], [8, 1, 6, 7, 2, 6], [8, 1, 6, 7, 3, 1], [8, 1, 6, 7, 4, 5], [8, 1, 6, 7, 5, 0], [8, 1, 6, 7, 6, 4], [8, 1, 6, 7, 7, 8], [8, 1, 6, 7, 8, 3], [8, 1, 6, 8, 0, 0], [8, 1, 6, 8, 1, 4], [8, 1, 6, 8, 2, 8], [8, 1, 6, 8, 3, 3], [8, 1, 6, 8, 4, 7], [8, 1, 6, 8, 5, 2], [8, 1, 6, 8, 6, 6], [8, 1, 6, 8, 7, 1], [8, 1, 6, 8, 8, 5], [8, 2, 1, 0, 0, 2], [8, 2, 1, 0, 1, 6], [8, 2, 1, 0, 2, 1], [8, 2, 1, 0, 3, 5], [8, 2, 1, 0, 4, 0], [8, 2, 1, 0, 5, 4], [8, 2, 1, 0, 6, 8], [8, 2, 1, 0, 7, 3], [8, 2, 1, 0, 8, 7], [8, 2, 1, 1, 0, 4], [8, 2, 1, 1, 1, 8], [8, 2, 1, 1, 2, 3], [8, 2, 1, 1, 3, 7], [8, 2, 1, 1, 4, 2], [8, 2, 1, 1, 5, 6], [8, 2, 1, 1, 6, 1], [8, 2, 1, 1, 7, 5], [8, 2, 1, 1, 8, 0], [8, 2, 1, 2, 0, 6], [8, 2, 1, 2, 1, 1], [8, 2, 1, 2, 2, 5], [8, 2, 1, 2, 3, 0], [8, 2, 1, 2, 4, 4], [8, 2, 1, 2, 5, 8], [8, 2, 1, 2, 6, 3], [8, 2, 1, 2, 7, 7], [8, 2, 1, 2, 8, 2], [8, 2, 1, 3, 0, 8], [8, 2, 1, 3, 1, 3], [8, 2, 1, 3, 2, 7], [8, 2, 1, 3, 3, 2], [8, 2, 1, 3, 4, 6], [8, 2, 1, 3, 5, 1], [8, 2, 1, 3, 6, 5], [8, 2, 1, 3, 7, 0], [8, 2, 1, 3, 8, 4], [8, 2, 1, 4, 0, 1], [8, 2, 1, 4, 1, 5], [8, 2, 1, 4, 2, 0], [8, 2, 1, 4, 3, 4], [8, 2, 1, 4, 4, 8], [8, 2, 1, 4, 5, 3], [8, 2, 1, 4, 6, 7], [8, 2, 1, 4, 7, 2], [8, 2, 1, 4, 8, 6], [8, 2, 1, 5, 0, 3], [8, 2, 1, 5, 1, 7], [8, 2, 1, 5, 2, 2], [8, 2, 1, 5, 3, 6], [8, 2, 1, 5, 4, 1], [8, 2, 1, 5, 5, 5], [8, 2, 1, 5, 6, 0], [8, 2, 1, 5, 7, 4], [8, 2, 1, 5, 8, 8], [8, 2, 1, 6, 0, 5], [8, 2, 1, 6, 1, 0], [8, 2, 1, 6, 2, 4], [8, 2, 1, 6, 3, 8], [8, 2, 1, 6, 4, 3], [8, 2, 1, 6, 5, 7], [8, 2, 1, 6, 6, 2], [8, 2, 1, 6, 7, 6], [8, 2, 1, 6, 8, 1], [8, 2, 1, 7, 0, 7], [8, 2, 1, 7, 1, 2], [8, 2, 1, 7, 2, 6], [8, 2, 1, 7, 3, 1], [8, 2, 1, 7, 4, 5], [8, 2, 1, 7, 5, 0], [8, 2, 1, 7, 6, 4], [8, 2, 1, 7, 7, 8], [8, 2, 1, 7, 8, 3], [8, 2, 1, 8, 0, 0], [8, 2, 1, 8, 1, 4], [8, 2, 1, 8, 2, 8], [8, 2, 1, 8, 3, 3], [8, 2, 1, 8, 4, 7], [8, 2, 1, 8, 5, 2], [8, 2, 1, 8, 6, 6], [8, 2, 1, 8, 7, 1], [8, 2, 1, 8, 8, 5], [8, 3, 5, 0, 0, 2], [8, 3, 5, 0, 1, 6], [8, 3, 5, 0, 2, 1], [8, 3, 5, 0, 3, 5], [8, 3, 5, 0, 4, 0], [8, 3, 5, 0, 5, 4], [8, 3, 5, 0, 6, 8], [8, 3, 5, 0, 7, 3], [8, 3, 5, 0, 8, 7], [8, 3, 5, 1, 0, 4], [8, 3, 5, 1, 1, 8], [8, 3, 5, 1, 2, 3], [8, 3, 5, 1, 3, 7], [8, 3, 5, 1, 4, 2], [8, 3, 5, 1, 5, 6], [8, 3, 5, 1, 6, 1], [8, 3, 5, 1, 7, 5], [8, 3, 5, 1, 8, 0], [8, 3, 5, 2, 0, 6], [8, 3, 5, 2, 1, 1], [8, 3, 5, 2, 2, 5], [8, 3, 5, 2, 3, 0], [8, 3, 5, 2, 4, 4], [8, 3, 5, 2, 5, 8], [8, 3, 5, 2, 6, 3], [8, 3, 5, 2, 7, 7], [8, 3, 5, 2, 8, 2], [8, 3, 5, 3, 0, 8], [8, 3, 5, 3, 1, 3], [8, 3, 5, 3, 2, 7], [8, 3, 5, 3, 3, 2], [8, 3, 5, 3, 4, 6], [8, 3, 5, 3, 5, 1], [8, 3, 5, 3, 6, 5], [8, 3, 5, 3, 7, 0], [8, 3, 5, 3, 8, 4], [8, 3, 5, 4, 0, 1], [8, 3, 5, 4, 1, 5], [8, 3, 5, 4, 2, 0], [8, 3, 5, 4, 3, 4], [8, 3, 5, 4, 4, 8], [8, 3, 5, 4, 5, 3], [8, 3, 5, 4, 6, 7], [8, 3, 5, 4, 7, 2], [8, 3, 5, 4, 8, 6], [8, 3, 5, 5, 0, 3], [8, 3, 5, 5, 1, 7], [8, 3, 5, 5, 2, 2], [8, 3, 5, 5, 3, 6], [8, 3, 5, 5, 4, 1], [8, 3, 5, 5, 5, 5], [8, 3, 5, 5, 6, 0], [8, 3, 5, 5, 7, 4], [8, 3, 5, 5, 8, 8], [8, 3, 5, 6, 0, 5], [8, 3, 5, 6, 1, 0], [8, 3, 5, 6, 2, 4], [8, 3, 5, 6, 3, 8], [8, 3, 5, 6, 4, 3], [8, 3, 5, 6, 5, 7], [8, 3, 5, 6, 6, 2], [8, 3, 5, 6, 7, 6], [8, 3, 5, 6, 8, 1], [8, 3, 5, 7, 0, 7], [8, 3, 5, 7, 1, 2], [8, 3, 5, 7, 2, 6], [8, 3, 5, 7, 3, 1], [8, 3, 5, 7, 4, 5], [8, 3, 5, 7, 5, 0], [8, 3, 5, 7, 6, 4], [8, 3, 5, 7, 7, 8], [8, 3, 5, 7, 8, 3], [8, 3, 5, 8, 0, 0], [8, 3, 5, 8, 1, 4], [8, 3, 5, 8, 2, 8], [8, 3, 5, 8, 3, 3], [8, 3, 5, 8, 4, 7], [8, 3, 5, 8, 5, 2], [8, 3, 5, 8, 6, 6], [8, 3, 5, 8, 7, 1], [8, 3, 5, 8, 8, 5], [8, 4, 0, 0, 0, 2], [8, 4, 0, 0, 1, 6], [8, 4, 0, 0, 2, 1], [8, 4, 0, 0, 3, 5], [8, 4, 0, 0, 4, 0], [8, 4, 0, 0, 5, 4], [8, 4, 0, 0, 6, 8], [8, 4, 0, 0, 7, 3], [8, 4, 0, 0, 8, 7], [8, 4, 0, 1, 0, 4], [8, 4, 0, 1, 1, 8], [8, 4, 0, 1, 2, 3], [8, 4, 0, 1, 3, 7], [8, 4, 0, 1, 4, 2], [8, 4, 0, 1, 5, 6], [8, 4, 0, 1, 6, 1], [8, 4, 0, 1, 7, 5], [8, 4, 0, 1, 8, 0], [8, 4, 0, 2, 0, 6], [8, 4, 0, 2, 1, 1], [8, 4, 0, 2, 2, 5], [8, 4, 0, 2, 3, 0], [8, 4, 0, 2, 4, 4], [8, 4, 0, 2, 5, 8], [8, 4, 0, 2, 6, 3], [8, 4, 0, 2, 7, 7], [8, 4, 0, 2, 8, 2], [8, 4, 0, 3, 0, 8], [8, 4, 0, 3, 1, 3], [8, 4, 0, 3, 2, 7], [8, 4, 0, 3, 3, 2], [8, 4, 0, 3, 4, 6], [8, 4, 0, 3, 5, 1], [8, 4, 0, 3, 6, 5], [8, 4, 0, 3, 7, 0], [8, 4, 0, 3, 8, 4], [8, 4, 0, 4, 0, 1], [8, 4, 0, 4, 1, 5], [8, 4, 0, 4, 2, 0], [8, 4, 0, 4, 3, 4], [8, 4, 0, 4, 4, 8], [8, 4, 0, 4, 5, 3], [8, 4, 0, 4, 6, 7], [8, 4, 0, 4, 7, 2], [8, 4, 0, 4, 8, 6], [8, 4, 0, 5, 0, 3], [8, 4, 0, 5, 1, 7], [8, 4, 0, 5, 2, 2], [8, 4, 0, 5, 3, 6], [8, 4, 0, 5, 4, 1], [8, 4, 0, 5, 5, 5], [8, 4, 0, 5, 6, 0], [8, 4, 0, 5, 7, 4], [8, 4, 0, 5, 8, 8], [8, 4, 0, 6, 0, 5], [8, 4, 0, 6, 1, 0], [8, 4, 0, 6, 2, 4], [8, 4, 0, 6, 3, 8], [8, 4, 0, 6, 4, 3], [8, 4, 0, 6, 5, 7], [8, 4, 0, 6, 6, 2], [8, 4, 0, 6, 7, 6], [8, 4, 0, 6, 8, 1], [8, 4, 0, 7, 0, 7], [8, 4, 0, 7, 1, 2], [8, 4, 0, 7, 2, 6], [8, 4, 0, 7, 3, 1], [8, 4, 0, 7, 4, 5], [8, 4, 0, 7, 5, 0], [8, 4, 0, 7, 6, 4], [8, 4, 0, 7, 7, 8], [8, 4, 0, 7, 8, 3], [8, 4, 0, 8, 0, 0], [8, 4, 0, 8, 1, 4], [8, 4, 0, 8, 2, 8], [8, 4, 0, 8, 3, 3], [8, 4, 0, 8, 4, 7], [8, 4, 0, 8, 5, 2], [8, 4, 0, 8, 6, 6], [8, 4, 0, 8, 7, 1], [8, 4, 0, 8, 8, 5], [8, 5, 4, 0, 0, 2], [8, 5, 4, 0, 1, 6], [8, 5, 4, 0, 2, 1], [8, 5, 4, 0, 3, 5], [8, 5, 4, 0, 4, 0], [8, 5, 4, 0, 5, 4], [8, 5, 4, 0, 6, 8], [8, 5, 4, 0, 7, 3], [8, 5, 4, 0, 8, 7], [8, 5, 4, 1, 0, 4], [8, 5, 4, 1, 1, 8], [8, 5, 4, 1, 2, 3], [8, 5, 4, 1, 3, 7], [8, 5, 4, 1, 4, 2], [8, 5, 4, 1, 5, 6], [8, 5, 4, 1, 6, 1], [8, 5, 4, 1, 7, 5], [8, 5, 4, 1, 8, 0], [8, 5, 4, 2, 0, 6], [8, 5, 4, 2, 1, 1], [8, 5, 4, 2, 2, 5], [8, 5, 4, 2, 3, 0], [8, 5, 4, 2, 4, 4], [8, 5, 4, 2, 5, 8], [8, 5, 4, 2, 6, 3], [8, 5, 4, 2, 7, 7], [8, 5, 4, 2, 8, 2], [8, 5, 4, 3, 0, 8], [8, 5, 4, 3, 1, 3], [8, 5, 4, 3, 2, 7], [8, 5, 4, 3, 3, 2], [8, 5, 4, 3, 4, 6], [8, 5, 4, 3, 5, 1], [8, 5, 4, 3, 6, 5], [8, 5, 4, 3, 7, 0], [8, 5, 4, 3, 8, 4], [8, 5, 4, 4, 0, 1], [8, 5, 4, 4, 1, 5], [8, 5, 4, 4, 2, 0], [8, 5, 4, 4, 3, 4], [8, 5, 4, 4, 4, 8], [8, 5, 4, 4, 5, 3], [8, 5, 4, 4, 6, 7], [8, 5, 4, 4, 7, 2], [8, 5, 4, 4, 8, 6], [8, 5, 4, 5, 0, 3], [8, 5, 4, 5, 1, 7], [8, 5, 4, 5, 2, 2], [8, 5, 4, 5, 3, 6], [8, 5, 4, 5, 4, 1], [8, 5, 4, 5, 5, 5], [8, 5, 4, 5, 6, 0], [8, 5, 4, 5, 7, 4], [8, 5, 4, 5, 8, 8], [8, 5, 4, 6, 0, 5], [8, 5, 4, 6, 1, 0], [8, 5, 4, 6, 2, 4], [8, 5, 4, 6, 3, 8], [8, 5, 4, 6, 4, 3], [8, 5, 4, 6, 5, 7], [8, 5, 4, 6, 6, 2], [8, 5, 4, 6, 7, 6], [8, 5, 4, 6, 8, 1], [8, 5, 4, 7, 0, 7], [8, 5, 4, 7, 1, 2], [8, 5, 4, 7, 2, 6], [8, 5, 4, 7, 3, 1], [8, 5, 4, 7, 4, 5], [8, 5, 4, 7, 5, 0], [8, 5, 4, 7, 6, 4], [8, 5, 4, 7, 7, 8], [8, 5, 4, 7, 8, 3], [8, 5, 4, 8, 0, 0], [8, 5, 4, 8, 1, 4], [8, 5, 4, 8, 2, 8], [8, 5, 4, 8, 3, 3], [8, 5, 4, 8, 4, 7], [8, 5, 4, 8, 5, 2], [8, 5, 4, 8, 6, 6], [8, 5, 4, 8, 7, 1], [8, 5, 4, 8, 8, 5], [8, 6, 8, 0, 0, 2], [8, 6, 8, 0, 1, 6], [8, 6, 8, 0, 2, 1], [8, 6, 8, 0, 3, 5], [8, 6, 8, 0, 4, 0], [8, 6, 8, 0, 5, 4], [8, 6, 8, 0, 6, 8], [8, 6, 8, 0, 7, 3], [8, 6, 8, 0, 8, 7], [8, 6, 8, 1, 0, 4], [8, 6, 8, 1, 1, 8], [8, 6, 8, 1, 2, 3], [8, 6, 8, 1, 3, 7], [8, 6, 8, 1, 4, 2], [8, 6, 8, 1, 5, 6], [8, 6, 8, 1, 6, 1], [8, 6, 8, 1, 7, 5], [8, 6, 8, 1, 8, 0], [8, 6, 8, 2, 0, 6], [8, 6, 8, 2, 1, 1], [8, 6, 8, 2, 2, 5], [8, 6, 8, 2, 3, 0], [8, 6, 8, 2, 4, 4], [8, 6, 8, 2, 5, 8], [8, 6, 8, 2, 6, 3], [8, 6, 8, 2, 7, 7], [8, 6, 8, 2, 8, 2], [8, 6, 8, 3, 0, 8], [8, 6, 8, 3, 1, 3], [8, 6, 8, 3, 2, 7], [8, 6, 8, 3, 3, 2], [8, 6, 8, 3, 4, 6], [8, 6, 8, 3, 5, 1], [8, 6, 8, 3, 6, 5], [8, 6, 8, 3, 7, 0], [8, 6, 8, 3, 8, 4], [8, 6, 8, 4, 0, 1], [8, 6, 8, 4, 1, 5], [8, 6, 8, 4, 2, 0], [8, 6, 8, 4, 3, 4], [8, 6, 8, 4, 4, 8], [8, 6, 8, 4, 5, 3], [8, 6, 8, 4, 6, 7], [8, 6, 8, 4, 7, 2], [8, 6, 8, 4, 8, 6], [8, 6, 8, 5, 0, 3], [8, 6, 8, 5, 1, 7], [8, 6, 8, 5, 2, 2], [8, 6, 8, 5, 3, 6], [8, 6, 8, 5, 4, 1], [8, 6, 8, 5, 5, 5], [8, 6, 8, 5, 6, 0], [8, 6, 8, 5, 7, 4], [8, 6, 8, 5, 8, 8], [8, 6, 8, 6, 0, 5], [8, 6, 8, 6, 1, 0], [8, 6, 8, 6, 2, 4], [8, 6, 8, 6, 3, 8], [8, 6, 8, 6, 4, 3], [8, 6, 8, 6, 5, 7], [8, 6, 8, 6, 6, 2], [8, 6, 8, 6, 7, 6], [8, 6, 8, 6, 8, 1], [8, 6, 8, 7, 0, 7], [8, 6, 8, 7, 1, 2], [8, 6, 8, 7, 2, 6], [8, 6, 8, 7, 3, 1], [8, 6, 8, 7, 4, 5], [8, 6, 8, 7, 5, 0], [8, 6, 8, 7, 6, 4], [8, 6, 8, 7, 7, 8], [8, 6, 8, 7, 8, 3], [8, 6, 8, 8, 0, 0], [8, 6, 8, 8, 1, 4], [8, 6, 8, 8, 2, 8], [8, 6, 8, 8, 3, 3], [8, 6, 8, 8, 4, 7], [8, 6, 8, 8, 5, 2], [8, 6, 8, 8, 6, 6], [8, 6, 8, 8, 7, 1], [8, 6, 8, 8, 8, 5], [8, 7, 3, 0, 0, 2], [8, 7, 3, 0, 1, 6], [8, 7, 3, 0, 2, 1], [8, 7, 3, 0, 3, 5], [8, 7, 3, 0, 4, 0], [8, 7, 3, 0, 5, 4], [8, 7, 3, 0, 6, 8], [8, 7, 3, 0, 7, 3], [8, 7, 3, 0, 8, 7], [8, 7, 3, 1, 0, 4], [8, 7, 3, 1, 1, 8], [8, 7, 3, 1, 2, 3], [8, 7, 3, 1, 3, 7], [8, 7, 3, 1, 4, 2], [8, 7, 3, 1, 5, 6], [8, 7, 3, 1, 6, 1], [8, 7, 3, 1, 7, 5], [8, 7, 3, 1, 8, 0], [8, 7, 3, 2, 0, 6], [8, 7, 3, 2, 1, 1], [8, 7, 3, 2, 2, 5], [8, 7, 3, 2, 3, 0], [8, 7, 3, 2, 4, 4], [8, 7, 3, 2, 5, 8], [8, 7, 3, 2, 6, 3], [8, 7, 3, 2, 7, 7], [8, 7, 3, 2, 8, 2], [8, 7, 3, 3, 0, 8], [8, 7, 3, 3, 1, 3], [8, 7, 3, 3, 2, 7], [8, 7, 3, 3, 3, 2], [8, 7, 3, 3, 4, 6], [8, 7, 3, 3, 5, 1], [8, 7, 3, 3, 6, 5], [8, 7, 3, 3, 7, 0], [8, 7, 3, 3, 8, 4], [8, 7, 3, 4, 0, 1], [8, 7, 3, 4, 1, 5], [8, 7, 3, 4, 2, 0], [8, 7, 3, 4, 3, 4], [8, 7, 3, 4, 4, 8], [8, 7, 3, 4, 5, 3], [8, 7, 3, 4, 6, 7], [8, 7, 3, 4, 7, 2], [8, 7, 3, 4, 8, 6], [8, 7, 3, 5, 0, 3], [8, 7, 3, 5, 1, 7], [8, 7, 3, 5, 2, 2], [8, 7, 3, 5, 3, 6], [8, 7, 3, 5, 4, 1], [8, 7, 3, 5, 5, 5], [8, 7, 3, 5, 6, 0], [8, 7, 3, 5, 7, 4], [8, 7, 3, 5, 8, 8], [8, 7, 3, 6, 0, 5], [8, 7, 3, 6, 1, 0], [8, 7, 3, 6, 2, 4], [8, 7, 3, 6, 3, 8], [8, 7, 3, 6, 4, 3], [8, 7, 3, 6, 5, 7], [8, 7, 3, 6, 6, 2], [8, 7, 3, 6, 7, 6], [8, 7, 3, 6, 8, 1], [8, 7, 3, 7, 0, 7], [8, 7, 3, 7, 1, 2], [8, 7, 3, 7, 2, 6], [8, 7, 3, 7, 3, 1], [8, 7, 3, 7, 4, 5], [8, 7, 3, 7, 5, 0], [8, 7, 3, 7, 6, 4], [8, 7, 3, 7, 7, 8], [8, 7, 3, 7, 8, 3], [8, 7, 3, 8, 0, 0], [8, 7, 3, 8, 1, 4], [8, 7, 3, 8, 2, 8], [8, 7, 3, 8, 3, 3], [8, 7, 3, 8, 4, 7], [8, 7, 3, 8, 5, 2], [8, 7, 3, 8, 6, 6], [8, 7, 3, 8, 7, 1], [8, 7, 3, 8, 8, 5], [8, 8, 7, 0, 0, 2], [8, 8, 7, 0, 1, 6], [8, 8, 7, 0, 2, 1], [8, 8, 7, 0, 3, 5], [8, 8, 7, 0, 4, 0], [8, 8, 7, 0, 5, 4], [8, 8, 7, 0, 6, 8], [8, 8, 7, 0, 7, 3], [8, 8, 7, 0, 8, 7], [8, 8, 7, 1, 0, 4], [8, 8, 7, 1, 1, 8], [8, 8, 7, 1, 2, 3], [8, 8, 7, 1, 3, 7], [8, 8, 7, 1, 4, 2], [8, 8, 7, 1, 5, 6], [8, 8, 7, 1, 6, 1], [8, 8, 7, 1, 7, 5], [8, 8, 7, 1, 8, 0], [8, 8, 7, 2, 0, 6], [8, 8, 7, 2, 1, 1], [8, 8, 7, 2, 2, 5], [8, 8, 7, 2, 3, 0], [8, 8, 7, 2, 4, 4], [8, 8, 7, 2, 5, 8], [8, 8, 7, 2, 6, 3], [8, 8, 7, 2, 7, 7], [8, 8, 7, 2, 8, 2], [8, 8, 7, 3, 0, 8], [8, 8, 7, 3, 1, 3], [8, 8, 7, 3, 2, 7], [8, 8, 7, 3, 3, 2], [8, 8, 7, 3, 4, 6], [8, 8, 7, 3, 5, 1], [8, 8, 7, 3, 6, 5], [8, 8, 7, 3, 7, 0], [8, 8, 7, 3, 8, 4], [8, 8, 7, 4, 0, 1], [8, 8, 7, 4, 1, 5], [8, 8, 7, 4, 2, 0], [8, 8, 7, 4, 3, 4], [8, 8, 7, 4, 4, 8], [8, 8, 7, 4, 5, 3], [8, 8, 7, 4, 6, 7], [8, 8, 7, 4, 7, 2], [8, 8, 7, 4, 8, 6], [8, 8, 7, 5, 0, 3], [8, 8, 7, 5, 1, 7], [8, 8, 7, 5, 2, 2], [8, 8, 7, 5, 3, 6], [8, 8, 7, 5, 4, 1], [8, 8, 7, 5, 5, 5], [8, 8, 7, 5, 6, 0], [8, 8, 7, 5, 7, 4], [8, 8, 7, 5, 8, 8], [8, 8, 7, 6, 0, 5], [8, 8, 7, 6, 1, 0], [8, 8, 7, 6, 2, 4], [8, 8, 7, 6, 3, 8], [8, 8, 7, 6, 4, 3], [8, 8, 7, 6, 5, 7], [8, 8, 7, 6, 6, 2], [8, 8, 7, 6, 7, 6], [8, 8, 7, 6, 8, 1], [8, 8, 7, 7, 0, 7], [8, 8, 7, 7, 1, 2], [8, 8, 7, 7, 2, 6], [8, 8, 7, 7, 3, 1], [8, 8, 7, 7, 4, 5], [8, 8, 7, 7, 5, 0], [8, 8, 7, 7, 6, 4], [8, 8, 7, 7, 7, 8], [8, 8, 7, 7, 8, 3], [8, 8, 7, 8, 0, 0], [8, 8, 7, 8, 1, 4], [8, 8, 7, 8, 2, 8], [8, 8, 7, 8, 3, 3], [8, 8, 7, 8, 4, 7], [8, 8, 7, 8, 5, 2], [8, 8, 7, 8, 6, 6], [8, 8, 7, 8, 7, 1], [8, 8, 7, 8, 8, 5]]} +RLMATH_EOF diff --git a/tasks/optimize-fs-cycle-indep-c9-n6/tests/check.py b/tasks/optimize-fs-cycle-indep-c9-n6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..18467766f4b39df02d00aad7ae384bd83e857320 --- /dev/null +++ b/tasks/optimize-fs-cycle-indep-c9-n6/tests/check.py @@ -0,0 +1,38 @@ +"""Independent set in the strong product C_m^{⊠n}. Score = size. + +Two distinct vertices x, y of C_m^{⊠n} (n-tuples over Z_m) are adjacent iff x_i - y_i ∈ {-1, 0, 1} (mod m) +for every i. Check: mark the answer in a boolean table of size m^n and look up all 3^n - 1 neighbours of +every answer vertex (vectorised; 26244 vertices of C_9^7 take ~1 s). +""" +import itertools + +import numpy as np + +from run import Invalid, int_list + + +def check(inst, ans): + m, n = inst["m"], inst["n"] + vecs = ans.get("vertices") + # alpha(C_m^{⊠n}) <= (m/2)^n (fractional independence number is multiplicative under strong products), + # so longer lists are invalid; rejecting them early also bounds grading time + if not isinstance(vecs, list) or not vecs or 2 ** n * len(vecs) > m ** n: + raise Invalid(f"vertices must be a non-empty list of at most ({m}/2)^{n} tuples") + for v in vecs: + int_list(v, n, 0, m - 1, "vertex") + A = np.array(vecs, dtype=np.int64) + pw = m ** np.arange(n - 1, -1, -1, dtype=np.int64) + codes = A @ pw + if len(np.unique(codes)) != len(codes): + raise Invalid("duplicate vertices") + table = np.zeros(m ** n, bool) + table[codes] = True + for off in itertools.product((-1, 0, 1), repeat=n): + if not any(off): + continue + nb = ((A + np.array(off)) % m) @ pw + hit = table[nb] + if hit.any(): + k = int(np.nonzero(hit)[0][0]) + raise Invalid(f"vertices {vecs[k]} and {[(x + o) % m for x, o in zip(vecs[k], off)]} are adjacent") + return float(len(vecs)), {"size": len(vecs)} diff --git a/tasks/optimize-fs-cycle-indep-c9-n6/tests/instance.json b/tasks/optimize-fs-cycle-indep-c9-n6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2cacc38bd08f97c0855e5913f033444c7e162b66 --- /dev/null +++ b/tasks/optimize-fs-cycle-indep-c9-n6/tests/instance.json @@ -0,0 +1 @@ +{"m": 9, "n": 6, "direction": "maximize", "best_known": 6561, "baseline": 4096, "family": "fs_cycle_independent_set", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-fs-cycle-indep-c9-n6/tests/run.py b/tasks/optimize-fs-cycle-indep-c9-n6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-fs-cycle-indep-c9-n6/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-fs-cycle-indep-c9-n6/tests/test.sh b/tasks/optimize-fs-cycle-indep-c9-n6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-fs-cycle-indep-c9-n6/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