heh
25/9
| -rw-r--r-- | src/inp.txt | 1496 | ||||
| -rw-r--r-- | src/main.rs | 231 |
2 files changed, 680 insertions, 1047 deletions
diff --git a/src/inp.txt b/src/inp.txt index 40f0262..6f1e277 100644 --- a/src/inp.txt +++ b/src/inp.txt @@ -1,1000 +1,496 @@ -75262,24842,97390 -5850,23406,34462 -26020,4432,80875 -57825,52185,42207 -61244,41825,99111 -41106,37991,96738 -18548,46804,50777 -82345,90100,44635 -52588,93061,39246 -16907,17561,8557 -92859,22926,42537 -56374,41906,10940 -2000,60958,7605 -39763,11100,93449 -53412,83932,28008 -54240,64204,70671 -80662,7998,35309 -89694,37693,92407 -6882,81993,95279 -57743,18143,44156 -15357,86472,86437 -37821,2676,39005 -78028,15498,33943 -73455,91817,24669 -69014,70653,29680 -31018,57570,38701 -54084,72177,63033 -79073,6701,68127 -24909,24807,72769 -39610,70105,43679 -62176,27410,19864 -70000,47082,32572 -61292,48573,50417 -69409,8440,56324 -42608,12081,47670 -87,44167,33594 -83589,63789,87909 -59063,95984,12239 -658,47892,13542 -20431,74799,61297 -68129,32547,14635 -80290,33244,10238 -31125,96983,73988 -79158,86765,80128 -53520,50969,45504 -99372,94859,86959 -91833,6081,87947 -82142,49754,248 -42977,15055,52682 -40236,13624,9783 -6626,66584,71581 -50964,13098,43262 -88712,39030,7992 -64306,39521,57902 -55630,14333,47019 -88278,61775,5857 -64572,50658,28832 -81296,77836,19250 -34668,64128,70429 -52888,32457,61533 -77929,36250,22101 -64349,43779,84049 -58881,1994,31735 -4836,36925,97617 -69898,47721,4336 -28107,35754,15211 -43930,35043,7900 -44737,44493,5572 -33560,68887,18569 -59840,52,14324 -15539,46471,69008 -98516,75186,76208 -83522,14361,54066 -71732,96918,40240 -92537,98464,87448 -87908,26962,75634 -12909,65530,62533 -71661,53400,27310 -25895,24890,77023 -45200,1952,25791 -13136,39458,10136 -64752,9421,62112 -96186,19674,93928 -36231,56106,97701 -30611,11097,89190 -87778,98830,22631 -12401,46411,3622 -24677,94363,63454 -26915,31829,65002 -12036,10937,41421 -77442,15448,56797 -61092,88956,91312 -65174,90106,54312 -1075,15721,95492 -5,21511,9203 -97323,54205,9050 -96006,67311,22501 -80966,8774,38774 -21881,37731,60834 -88253,58395,84764 -78716,45227,71161 -30403,2163,8811 -76138,80056,12365 -42938,56573,68248 -74979,4593,38082 -63575,3132,55326 -99899,3772,34153 -62909,50284,15108 -56982,17787,94044 -2690,42818,44614 -49563,64985,95090 -60740,7931,50695 -4525,25954,39255 -91103,37024,97386 -33000,72993,95333 -83099,47314,71563 -36590,12074,44449 -9145,36544,68078 -8245,2679,14797 -82809,98437,83502 -53971,38961,63788 -28955,97410,87170 -50300,12403,15438 -49476,36404,21554 -18162,34692,58191 -93290,24616,73600 -54246,84846,92933 -40806,31587,28058 -76373,39231,96716 -66826,5098,7506 -94734,43171,46475 -71705,85599,98497 -67663,4097,61404 -82500,96773,2702 -68370,89771,44023 -47800,59189,65285 -25966,82983,27493 -64976,15801,68388 -99116,21319,85533 -48483,2338,29795 -83697,3677,59493 -38145,10661,28355 -28808,23232,75183 -13387,41652,80977 -86723,50964,85864 -23174,11535,17766 -59687,75042,83386 -99123,87809,42167 -55923,64301,46267 -72167,40352,89489 -76568,71227,24149 -979,92267,58701 -81547,2636,49121 -3816,90074,87760 -89230,232,67765 -70144,1848,99551 -58969,9283,10560 -60061,71754,32946 -85745,27804,13651 -61274,49870,73040 -74275,21179,44310 -64983,60749,70780 -33062,4100,34831 -70004,49330,6206 -17331,75995,34457 -71718,86569,78088 -58925,91889,81798 -35359,56724,70558 -41285,35883,96872 -42956,27172,57561 -79360,84610,67508 -99363,92588,44477 -39757,44157,41100 -42493,22319,61553 -27084,16939,1662 -14767,97940,29872 -75865,78925,1826 -66712,81761,41139 -90332,40513,66448 -42730,84596,12917 -56441,50851,60617 -17087,63607,46261 -89317,46528,28802 -74025,84931,5612 -96827,88307,15235 -89419,53018,97136 -22586,23288,28267 -70275,4956,85941 -99128,56853,40285 -18485,9337,89882 -80539,77748,12809 -53825,38619,83783 -63025,7883,82145 -83724,34506,91426 -93862,68208,76526 -65908,64759,31228 -42826,47675,29413 -23175,72036,63337 -5030,62272,78170 -69923,48075,8191 -47491,58965,32506 -68850,84352,41354 -88935,76952,43611 -49333,27375,95306 -78300,5938,20715 -62268,98740,89690 -20271,82447,20919 -54226,47217,79071 -98813,65884,88782 -18059,15832,66195 -79966,68849,16174 -95858,70026,1541 -6917,79328,28050 -15883,58059,37991 -98963,26566,80454 -237,65911,75990 -13198,10150,38092 -34998,3177,6318 -66046,71827,93294 -78134,85755,97725 -43606,90318,25493 -25295,15102,55105 -37479,33650,30845 -85140,72498,17264 -58319,64578,27600 -86755,2302,68798 -12897,87530,64740 -58797,96920,42995 -79865,90204,64512 -13847,14862,51523 -16168,83683,92615 -75271,32288,37848 -29624,19718,44783 -40139,33427,69800 -96847,37815,96947 -52122,19861,35523 -96665,50733,24876 -83504,15478,74412 -51064,74117,94678 -90558,60932,46608 -81170,60357,43859 -65767,91891,91013 -27242,81960,16359 -46369,85682,53722 -27045,11692,40498 -39184,55424,2817 -7447,47849,16498 -6771,52890,12270 -56404,79678,76258 -51994,44488,48796 -38292,85437,3684 -36367,84308,14192 -49858,62292,73987 -87623,3287,85978 -73597,21511,13016 -11974,13313,25105 -49412,32756,76490 -7515,31716,90380 -5215,21964,58462 -58211,58061,39607 -49790,28045,93038 -61551,25165,16143 -17744,6013,69024 -5583,16718,88539 -54283,29686,45057 -27678,31147,81616 -50076,826,60979 -44580,26949,79069 -4236,63031,28086 -33306,13057,81984 -72820,13703,45862 -34759,57709,11374 -9122,51469,57315 -55118,43874,35167 -60323,31058,48121 -30216,80714,32126 -54992,10085,63781 -4805,47767,87991 -12074,8329,71223 -3597,47761,97173 -12032,39133,11233 -80234,44615,46962 -47376,63102,31203 -32542,22354,95720 -91956,88363,36866 -92884,21915,48634 -93930,75183,82803 -65656,47744,62662 -79113,58176,7955 -1378,86533,61895 -23900,86937,17092 -12159,94462,80800 -17154,99143,79929 -70556,22549,74082 -66708,69377,68190 -19884,8376,61550 -29023,76495,36947 -98308,74199,77381 -76548,13409,49130 -82108,63144,32096 -70362,6378,64277 -75562,68681,56522 -32857,40115,47042 -73785,20182,44279 -15094,14339,12156 -65516,12356,15341 -55977,22643,61401 -83381,74630,30809 -82521,48688,55815 -57934,16733,42752 -78364,28191,17100 -15949,50826,47479 -84313,29625,77224 -4487,4263,49540 -97804,29912,38825 -76975,36898,65486 -79809,73889,5347 -7810,86410,39824 -75792,92582,32908 -52623,70799,79760 -22625,91139,66281 -85760,11385,65931 -27003,95214,96354 -20181,12703,21310 -89890,56037,49090 -83834,20989,45862 -69129,40114,5379 -10018,38490,52529 -48076,65630,72098 -62871,96056,58731 -83823,88063,33230 -96362,41370,62351 -2360,58174,96489 -50797,79261,27982 -45196,9580,1465 -85338,32546,96059 -37256,2744,35682 -50787,50484,24467 -41860,13636,82802 -53585,34541,65024 -7706,41586,30527 -32962,61588,83431 -89850,98554,86137 -45299,83209,1913 -16273,44053,30396 -71418,69058,10037 -68311,10414,64835 -77807,15757,4041 -83440,94301,40791 -96621,99539,18555 -17502,17287,83806 -20946,64955,43063 -15192,9040,69697 -18099,46464,99083 -2693,42845,55549 -81193,95378,94613 -12061,57980,51406 -91962,87545,63133 -49725,9671,42983 -32114,70266,42702 -74403,21979,20390 -99601,81399,83567 -3466,35286,20782 -25213,90741,56470 -3586,72992,94746 -10165,5772,4920 -2779,96181,66659 -93657,88805,91717 -2836,39048,53012 -92355,34981,64377 -32016,25640,9746 -21747,16851,86417 -55206,36642,17472 -46942,76101,80852 -24836,68044,21320 -8844,67471,53197 -21191,14782,7546 -56935,34019,56208 -10348,58596,80758 -63353,85054,6799 -12364,78925,87938 -8347,7685,97470 -1563,95528,59904 -42890,25011,40086 -78593,11163,96107 -61732,22330,37617 -2595,89245,26128 -26090,56273,97076 -99174,4082,3460 -48659,24903,73456 -23345,6379,88241 -91590,39851,9235 -8081,1151,4606 -2916,48124,87281 -31137,28125,81054 -64978,1285,15146 -61602,24406,72140 -93585,28933,2015 -79111,42802,70619 -16330,21724,81602 -85272,51390,92541 -15325,32239,81967 -45574,28352,40968 -83225,23414,73611 -14139,25405,67148 -74704,24247,19975 -10103,17272,8125 -7504,16417,74226 -75393,86090,24250 -33917,90595,550 -17262,94525,73120 -1717,98671,54405 -25,48326,21333 -83269,43443,44014 -22296,58576,33256 -63479,78639,14851 -96456,35770,95787 -89673,84774,81637 -33347,81432,91593 -85100,84990,22480 -66097,57459,46954 -42954,27739,92329 -18397,70122,46047 -31660,80497,4736 -91002,60552,49548 -7595,46921,19996 -12380,48385,70009 -94923,45618,36196 -16401,75336,29109 -2015,66230,52359 -69384,12447,70564 -52118,2481,99138 -85196,8142,93367 -17437,69472,58882 -58647,42107,93331 -38818,22131,48181 -43516,19014,52024 -55595,64736,81817 -1569,71192,36114 -72446,80121,88388 -22385,21380,62461 -90341,66290,41783 -14197,97612,99036 -67668,79651,45999 -43324,55153,74961 -28530,4554,41346 -27932,80508,84863 -65083,52647,85182 -88396,49433,81024 -76264,99781,27781 -56348,72389,28739 -39936,31025,96939 -97523,10413,78833 -78015,62922,52493 -2245,39898,76829 -75355,79937,55897 -97922,40231,95610 -38348,28436,49823 -24112,64468,4050 -24018,27579,35524 -58722,26914,55929 -13866,253,54514 -21032,89964,4281 -59805,61027,75188 -85233,99633,64652 -60926,60969,4708 -39443,9570,54979 -45527,82006,66021 -95265,40127,13259 -81870,74382,97641 -41907,99358,40606 -40114,1148,34030 -38291,95152,97552 -47800,6858,7381 -18673,6526,65627 -6793,63553,45361 -47220,78516,5094 -12858,19152,59037 -27145,61378,33557 -98015,34931,91636 -32989,58642,42724 -26727,88552,20421 -45718,83574,60204 -10679,77300,64225 -11043,40605,2114 -6602,23538,498 -58544,4260,9517 -71074,20952,31277 -63816,3486,26801 -34780,28009,82131 -1818,90854,32605 -9968,7806,55957 -8445,95854,43405 -95558,68362,4327 -3749,84154,84038 -78047,77153,59054 -28640,17140,46958 -77270,39407,3691 -16565,86561,24802 -77089,72661,34104 -4827,80869,3137 -18723,20289,25400 -45110,54068,74426 -5779,27972,73057 -8641,19755,14819 -30401,51083,87089 -21894,75742,83259 -46894,93761,89960 -24408,21871,36323 -30448,47359,83517 -10047,85762,82452 -27151,82140,28083 -89569,93676,43952 -94606,42622,31389 -27450,53153,71453 -62771,8267,47410 -73162,6742,90532 -66534,64660,59571 -91632,55151,28222 -97574,87242,63222 -1736,17989,44839 -62445,79224,59532 -504,56279,13993 -23050,70356,51760 -56224,63692,61521 -68958,80266,83087 -36251,92245,96131 -71766,79134,25518 -34820,42253,64962 -30523,2035,88243 -44274,78287,2625 -99327,76790,73194 -5953,30864,98449 -58008,96393,59736 -5601,36611,93681 -66475,56884,65432 -34070,48135,7479 -40737,38744,42624 -6678,18753,12885 -77,64413,40809 -83977,69185,58298 -33635,6712,32984 -44556,23051,3919 -68858,14742,40449 -37100,69040,18211 -38791,78887,20546 -36842,36768,5191 -45569,44414,15170 -12579,65439,25527 -32289,61682,2110 -36841,59949,28933 -32028,12195,67998 -35047,77630,89711 -73011,91221,63358 -46945,81804,34423 -86175,94501,87736 -96533,97476,1048 -48738,92892,64732 -6460,91759,12190 -60348,54811,45470 -19332,3238,26289 -18454,37178,79433 -24949,76068,82542 -73338,46837,58056 -91273,15670,96538 -48748,60112,69938 -77215,10457,57299 -41781,63863,11847 -46233,67503,97496 -90461,27845,65631 -51689,41306,27664 -71745,16001,732 -36766,8778,83954 -21694,5084,16519 -98134,7621,87922 -2415,90371,78079 -58280,15639,10860 -90773,28864,55577 -93108,97074,27928 -29830,80080,88610 -55545,83797,95511 -21914,14155,50095 -89587,28752,75666 -60291,2712,18661 -72660,30564,59684 -14900,2859,66341 -40023,88458,22851 -26232,31189,39892 -1683,72697,99200 -44194,69244,3984 -46260,8388,54300 -79623,34868,79042 -77380,98913,61322 -82029,73672,79643 -53903,29044,38509 -82203,49345,4975 -45267,84093,89046 -72217,3516,91658 -48826,28305,39522 -72252,24679,12661 -65895,51504,95055 -28110,672,80140 -47522,69674,25987 -74179,25586,3934 -84070,44985,27877 -29141,74269,93548 -86291,51777,83757 -60924,98097,17250 -90209,26377,77022 -29017,64770,81652 -84131,25087,64962 -96857,66562,67361 -90585,26582,63251 -46702,21168,87615 -75447,44338,15086 -8446,66506,92985 -21165,99848,72196 -93870,90559,2365 -17969,8983,26107 -15116,53565,22104 -28507,19074,4502 -53292,92824,51787 -82702,95935,38405 -28281,99559,94690 -72670,283,40387 -88584,61080,2076 -22448,43434,7187 -2952,4047,99068 -7974,12852,499 -62420,99122,16812 -6813,10595,15339 -25389,15790,96931 -74110,60375,44615 -16620,23273,68517 -60291,20708,38303 -99377,93159,22785 -93525,58254,93787 -20837,80308,70460 -68612,27879,87104 -71305,97383,34267 -61939,76762,15886 -97683,33004,35539 -42145,4704,91656 -14808,36689,71799 -32717,12323,47135 -50240,76974,8231 -75799,85448,61738 -94539,84078,19280 -7698,30600,68537 -45769,48843,33653 -96870,65134,30542 -96979,14987,75275 -36741,39369,43350 -88133,37494,91835 -87234,23897,53525 -66238,34015,78186 -5230,79513,94762 -55433,53379,12977 -37769,40412,90961 -12782,30093,34271 -17123,12319,48348 -1819,11274,14741 -91867,73849,38421 -81907,56692,77936 -4837,59942,35794 -59629,59877,40020 -54371,24925,7322 -21646,35216,26232 -64723,63855,1021 -14844,47397,83879 -42552,50906,74443 -82653,24824,49660 -6407,39351,30433 -23656,50447,53105 -89227,72959,71099 -7224,57097,68103 -48756,60308,51341 -47462,48779,8402 -44460,16581,30688 -23930,57915,41131 -7258,30193,79218 -87940,89653,66329 -73295,4984,48222 -97100,47489,77245 -14421,17028,10435 -31699,21917,39952 -91655,42735,72609 -86237,40816,55662 -43507,21725,34496 -67400,64636,39080 -92059,92330,77041 -35134,50087,79970 -68004,41682,3009 -17610,11618,34437 -73628,43319,64573 -30495,95261,56399 -66191,1864,32994 -56998,19291,77007 -37401,83544,24392 -77745,53733,75061 -57933,81433,23571 -40136,18788,2600 -36152,10333,73469 -31001,61608,33448 -55218,29322,28259 -81911,75959,1178 -67561,19729,92147 -64132,21530,63995 -89254,61407,93259 -65672,67425,86001 -77837,10982,89282 -70936,71460,46596 -95394,76056,55349 -66343,73321,14785 -49178,67174,41010 -60813,38771,10897 -47421,35149,93914 -84030,14409,36058 -95082,69866,20025 -59286,99849,68610 -19344,91853,69720 -77547,93817,11382 -91404,73403,31949 -3330,10144,93368 -54986,22936,20176 -54971,82490,86831 -53845,73830,69316 -23885,77851,63157 -62082,46454,46039 -31022,7928,4986 -2552,27465,78787 -52120,58664,50366 -41962,90889,38907 -58766,43075,97084 -66757,97718,65157 -52923,23254,37364 -71325,80139,904 -19111,26011,20724 -4457,76880,57867 -45735,35142,25197 -77086,22720,78185 -37500,80965,93898 -88596,56846,78055 -96834,7850,11857 -76293,41028,16035 -48372,21173,64884 -28969,22124,32536 -72524,37700,40478 -83137,56770,85366 -47875,38170,78712 -11933,46345,45684 -3910,25418,50831 -35849,6604,85496 -41107,68749,95235 -94441,74841,21404 -91794,65951,27529 -44663,3688,95393 -77249,58184,57177 -48047,28829,9619 -46259,54161,91290 -64249,78091,91827 -73352,39494,36471 -18066,28201,69867 -17196,93950,65208 -11156,24592,36547 -2481,35874,26552 -15762,79992,67460 -97951,21601,4033 -69591,99282,31693 -85375,84461,31372 -62140,46891,74355 -28667,39836,62584 -2674,36055,71277 -95827,21130,98623 -32838,96720,50781 -54176,78411,9317 -36254,86296,61790 -11374,59779,86003 -39057,40194,58058 -4809,38328,46114 -38308,16503,24496 -3780,26909,52235 -10922,14253,55820 -29243,70622,57336 -38158,61465,20167 -32618,59205,56780 -10782,34434,5595 -64863,84860,85134 -30653,18807,90894 -43109,54109,97496 -95740,67640,79760 -41981,66870,67698 -84674,63189,97003 -62625,51302,38692 -14056,10767,32137 -78769,17047,9491 -21543,45908,36405 -73794,66895,93628 -69363,68444,50649 -89832,49076,3097 -75245,54060,82106 -24276,56468,47245 -22311,20907,89965 -44836,30593,40045 -75846,20238,16781 -20656,32674,94106 -40802,50103,83657 -27434,10932,30162 -72554,71925,3970 -76881,46838,41886 -19453,36798,2224 -47581,92428,66536 -977,73472,28609 -24638,80854,96404 -95078,64795,50394 -97087,62817,97221 -96263,9152,15700 -9197,30594,59844 -93152,13984,67948 -10628,33838,49116 -49106,90919,11349 -55654,76035,14135 -98402,764,91644 -2781,77227,75113 -16571,18521,23196 -76467,81961,78032 -96113,64076,66902 -61513,22398,16596 -75334,33423,34297 -86604,35218,44306 -70230,37498,6650 -71025,16550,54137 -55458,36261,34909 -62839,12840,53040 -84351,87243,54511 -87932,15633,20502 -1075,69252,3641 -59974,47685,71366 -40536,28711,50337 -37734,44467,74701 -67345,542,99999 -76594,75604,56864 -79693,73166,68737 -72773,7092,17152 -86941,83451,6395 -55673,15109,60686 -79414,38113,34303 -85573,90847,70663 -87522,64310,71977 -1413,89558,92045 -18347,64054,45274 -90225,94315,67461 -33517,68256,47691 -66740,15565,43962 -32099,27313,70789 -78932,79958,24578 -89282,75813,31839 -49247,35393,52839 -20711,93047,69200 -89508,25473,17547 -77440,64312,46249 -8869,779,98007 -24953,23442,11262 -61964,50817,27869 -8999,82161,83617 -70330,30450,38083 -48322,78201,85911 -17362,3237,37153 -19126,85037,65869 -47722,79585,41736 -75266,61878,73726 -46520,31539,13415 -28264,85229,59271 -77989,56731,49339 -69765,7680,32312 -12002,52388,52501 -88607,13115,64021 -99371,61697,92937 -40635,64783,57191 -611,60837,78337 -44653,89599,8900 -93283,7378,43805 -26817,80327,80941 -36150,607,70734 -10849,43791,86016 -52933,24001,51542 -60326,27459,5481 -96193,58906,42590 -80272,737,63037 -67159,37151,38049 -96100,77713,81135 -50720,32253,9837 -33683,93117,34808 -75894,92517,83345 -48756,56970,91636 -45445,46984,23594 -39976,16007,6223 -4533,44967,70487 -36990,31998,4913 -94120,67774,51553 -64898,72288,66383 -35683,29820,87520 -52848,20708,9678 -61123,16018,60472 -1280,21345,38345 -32263,50713,17902 -6133,83203,51478 -24561,89272,62541 -93317,81250,1729 -17419,11448,68038 -45941,8715,89819 -82219,27901,27987 -35880,3088,39912 -16485,78376,86825 -12529,29327,300 -85726,61386,80453 -32142,45021,6977 -1672,17985,99384 -41861,58314,70313 -86173,9417,67747 -36214,69295,47584 -49486,65091,45782 -29917,8258,49261 -95540,1728,76396 -76773,55900,91635 -58731,9009,18518 -66176,72354,62922 -82620,58228,22569 -23138,70543,17444 -23778,36970,47975 -14040,55559,5569 -60372,45465,36550 -96640,30738,679 -25627,84121,83608 -88881,96345,3205 -871,31245,28276 -76386,51292,95923 -70999,68869,5732 -61813,42964,16301 -81393,66093,59343 -1466,92655,98648 -48535,51201,3507 -84623,25412,63168 -22184,59246,76896 -69492,23068,98918 -85393,73288,86934 -4588,4907,78250 -22234,22908,27316 -48748,5735,43565 -57398,64990,24277 -43435,79352,55819 -56151,24364,2633 -58076,94436,79244 -49671,92070,25875 -45586,35009,20658 -35881,54448,89218 -37643,9222,28337 -45327,88053,13160 -87802,88377,62857 -56860,45459,36554 -73766,99786,68397 -41728,45558,88367 -98380,14029,2115 -57768,35536,36023 -71539,84869,53667 -16431,53382,76965 -37017,33319,74871 -96323,94954,58006 -71043,56387,45593 -64266,63660,54757 -33413,64268,83913 -63177,32021,13207 -42858,70925,28527 -41384,91659,29622 -80039,40668,80502 -97950,62218,72997 -63623,34970,17480 -53205,51159,64066 -72590,16752,31495 -86222,84380,57074 -9030,43579,61644 -89647,51399,59748 -99669,76008,39545 -19881,59511,23797 -64382,25832,75722 -33691,5027,60125 -49765,57615,48705 -48315,41167,13774 -97557,2018,94856 -21240,78303,95541 -80115,91673,80307 -29419,26631,98245 -34849,82172,63116 -26079,26569,40406 -91752,44444,7935 -36759,35015,55368 -25026,64985,95779 -94312,84222,94586 -85238,41077,16199 -76631,12193,49306 +98004,50283 +98004,51502 +98073,51502 +98073,52727 +98144,52727 +98144,53937 +97953,53937 +97953,55168 +98003,55168 +98003,56406 +98033,56406 +98033,57473 +96926,57473 +96926,58748 +97199,58748 +97199,59926 +96895,59926 +96895,61220 +97084,61220 +97084,62314 +96426,62314 +96426,63395 +95789,63395 +95789,64490 +95244,64490 +95244,65829 +95432,65829 +95432,66934 +94907,66934 +94907,68050 +94423,68050 +94423,69341 +94345,69341 +94345,70156 +93192,70156 +93192,71485 +93153,71485 +93153,72568 +92590,72568 +92590,73702 +92113,73702 +92113,74741 +91467,74741 +91467,75567 +90483,75567 +90483,76688 +89978,76688 +89978,77537 +89068,77537 +89068,78372 +88163,78372 +88163,79469 +87609,79469 +87609,80612 +87093,80612 +87093,81578 +86346,81578 +86346,82422 +85463,82422 +85463,82939 +84244,82939 +84244,84206 +83804,84206 +83804,84848 +82735,84848 +82735,85434 +81634,85434 +81634,86745 +81168,86745 +81168,87730 +80395,87730 +80395,87950 +79018,87950 +79018,88564 +77968,88564 +77968,89681 +77272,89681 +77272,90032 +76045,90032 +76045,90883 +75148,90883 +75148,91125 +73882,91125 +73882,91934 +72952,91934 +72952,92557 +71910,92557 +71910,92993 +70774,92993 +70774,93784 +69804,93784 +69804,94065 +68601,94065 +68601,94737 +67564,94737 +67564,94644 +66234,94644 +66234,95260 +65172,95260 +65172,96308 +64228,96308 +64228,96569 +63027,96569 +63027,96815 +61826,96815 +61826,96343 +60465,96343 +60465,96835 +59336,96835 +59336,97723 +58262,97723 +58262,97006 +56916,97006 +56916,97227 +55731,97227 +55731,97435 +54540,97435 +54540,98266 +53388,98266 +53388,98391 +52167,98391 +52167,98195 +50936,98195 +50936,98172 +49715,98172 +49715,97959 +48500,97959 +48500,98135 +47273,98135 +47273,98219 +46040,98219 +46040,97295 +44907,97295 +44907,97942 +43605,97942 +43605,96967 +42520,96967 +42520,96937 +41300,96937 +41300,96652 +40124,96652 +40124,96994 +38801,96994 +38801,96419 +37687,96419 +37687,95965 +36552,95965 +36552,95897 +35300,95897 +35300,95312 +34211,95312 +34211,94929 +33056,94929 +33056,94007 +32118,94007 +32118,93804 +30894,93804 +30894,93729 +29593,93729 +29593,93046 +28568,93046 +28568,92453 +27503,92453 +27503,91601 +26586,91601 +26586,90840 +25632,90840 +25632,90635 +24336,90635 +24336,89546 +23599,89546 +23599,89479 +22173,89479 +22173,88691 +21234,88691 +21234,87455 +20651,87455 +20651,87191 +19306,87191 +19306,86273 +18485,86273 +18485,85089 +17918,85089 +17918,84736 +16587,84736 +16587,83568 +16032,83568 +16032,83102 +14760,83102 +14760,82116 +14026,82116 +14026,81313 +13084,81313 +13084,79817 +12987,79817 +12987,79115 +11922,79115 +11922,78148 +11187,78148 +11187,77151 +10493,77151 +10493,75950 +10112,75950 +10112,74905 +9511,74905 +9511,74201 +8326,74201 +8326,72904 +8152,72904 +8152,71838 +7581,71838 +7581,70676 +7210,70676 +7210,69798 +6230,69798 +6230,68607 +5921,68607 +5921,67692 +4935,67692 +4935,66370 +4983,66370 +4983,65240 +4534,65240 +4534,64208 +3759,64208 +3759,62870 +3992,62870 +3992,61715 +3622,61715 +3622,60663 +2780,60663 +2780,59343 +3127,59343 +3127,58209 +2581,58209 +2581,57040 +2155,57040 +2155,55761 +2518,55761 +2518,54592 +2022,54592 +2022,53344 +2362,53344 +2362,52146 +2079,52146 +2079,50925 +2365,50925 +2365,50265 +94901,50265 +94901,48488 +1659,48488 +1659,47308 +2494,47308 +2494,46043 +1812,46043 +1812,44875 +2401,44875 +2401,43591 +1950,43591 +1950,42377 +2134,42377 +2134,41191 +2472,41191 +2472,40153 +3483,40153 +3483,38963 +3684,38963 +3684,37617 +3317,37617 +3317,36454 +3697,36454 +3697,35377 +4342,35377 +4342,34263 +4837,34263 +4837,32955 +4800,32955 +4800,31869 +5379,31869 +5379,30923 +6262,30923 +6262,29782 +6675,29782 +6675,28650 +7119,28650 +7119,27415 +7379,27415 +7379,26415 +8095,26415 +8095,25406 +8781,25406 +8781,24145 +9061,24145 +9061,23300 +10005,23300 +10005,22154 +10494,22154 +10494,21597 +11796,21597 +11796,20131 +11881,20131 +11881,19735 +13328,19735 +13328,18722 +13998,18722 +13998,17795 +14776,17795 +14776,16811 +15496,16811 +15496,15841 +16243,15841 +16243,14681 +16822,14681 +16822,14162 +18004,14162 +18004,13340 +18903,13340 +18903,12715 +19963,12715 +19963,11815 +20802,11815 +20802,11108 +21793,11108 +21793,10828 +23078,10828 +23078,10062 +24016,10062 +24016,9070 +24823,9070 +24823,8392 +25837,8392 +25837,7547 +26764,7547 +26764,7731 +28238,7731 +28238,6379 +28922,6379 +28922,5921 +30062,5921 +30062,5661 +31282,5661 +31282,5137 +32386,5137 +32386,5118 +33678,5118 +33678,4277 +34673,4277 +34673,4403 +35989,4403 +35989,4090 +37156,4090 +37156,3656 +38292,3656 +38292,3559 +39512,3559 +39512,2594 +40549,2594 +40549,2472 +41771,2472 +41771,2323 +42984,2323 +42984,2689 +44258,2689 +44258,2443 +45448,2443 +45448,2139 +46639,2139 +46639,1555 +47830,1555 +47830,1845 +49064,1845 +49064,1634 +50286,1634 +50286,2188 +51494,2188 +51494,2386 +52697,2386 +52697,2595 +53892,2595 +53892,2621 +55101,2621 +55101,2661 +56313,2661 +56313,2728 +57528,2728 +57528,2364 +58828,2364 +58828,2818 +59987,2818 +59987,2845 +61236,2845 +61236,3836 +62244,3836 +62244,3791 +63518,3791 +63518,4250 +64651,4250 +64651,4284 +65928,4284 +65928,5346 +66839,5346 +66839,5849 +67939,5849 +67939,5650 +69343,5650 +69343,6127 +70473,6127 +70473,7026 +71396,7026 +71396,7311 +72621,7311 +72621,7898 +73695,7898 +73695,8360 +74844,8360 +74844,9323 +75689,9323 +75689,9834 +76813,9834 +76813,10909 +77552,10909 +77552,11764 +78426,11764 +78426,12198 +79619,12198 +79619,12720 +80766,12720 +80766,13911 +81353,13911 +81353,14300 +82639,14300 +82639,15444 +83238,15444 +83238,15925 +84480,15925 +84480,17167 +84951,17167 +84951,18280 +85528,18280 +85528,19271 +86225,19271 +86225,20163 +87036,20163 +87036,20724 +88286,20724 +88286,21775 +88917,21775 +88917,22924 +89395,22924 +89395,24077 +89844,24077 +89844,24888 +90823,24888 +90823,25962 +91392,25962 +91392,27042 +91944,27042 +91944,28174 +92391,28174 +92391,28956 +93550,28956 +93550,30107 +93978,30107 +93978,31501 +93820,31501 +93820,32387 +94861,32387 +94861,33531 +95288,33531 +95288,34727 +95560,34727 +95560,35758 +96349,35758 +96349,37174 +95847,37174 +95847,38217 +96640,38217 +96640,39523 +96391,39523 +96391,40646 +96922,40646 +96922,41796 +97381,41796 +97381,43019 +97440,43019 +97440,44222 +97609,44222 +97609,45404 +98016,45404 +98016,46605 +98352,46605 +98352,47838 +98266,47838 +98266,49062 +98278,49062 +98278,50283 diff --git a/src/main.rs b/src/main.rs index b79317e..fc39b79 100644 --- a/src/main.rs +++ b/src/main.rs @@ -78,36 +78,48 @@ use crate::util::UnionFind; #[unsafe(no_mangle)] #[implicit_fn::implicit_fn] pub unsafe fn p1(x: &'static [u8]) -> impl Debug { - let v = util::uints::<i64>(x).array_chunks::<3>().collect_vec(); - let k = v - .iter() - .copied() - .ι::<usize>() - .array_combinations::<2>() - .sorted_by_key(|[(a, _), (b, _)]| { - ((a[0] - b[0]).pow(2) + (a[1] - b[1]).pow(2) + (a[2] - b[2]).pow(2)).isqrt() - }); - let mut uf = UnionFind::new(1000); - for [a, b] in k.into_iter() { - uf.union(a.1, b.1); - // if (0..1000).map(|n| uf.find(n)).all_equal() { - // return v[a.1][0] * v[b.1][0]; - // } - } - - (0..1000) - .map(|x| uf.group_size(x)) - .sorted() - .rev() - .take(3) - .product::<usize>() + let p = util::uints::<i64>(x) + .array_chunks::<2>() + .collect::<Vec<_>>(); + let mut i = fimg::Image::<_, 1>::alloc( + p.iter().map(|[x, _]| *x).max().unwrap() as u32 / 12, + p.iter().map(|[_, x]| *x).max().unwrap() as u32 / 12, + ); + i.points( + &p.iter() + .map(|[a, b]| (*a as i32 / 12, *b as i32 / 12)) + .collect::<Vec<_>>(), + [255], + ); + i.points( + &[ + (98278 / 12, 50283 / 12), + (98278 / 12, 4250 / 12), + (63518 / 12, 4250 / 12), + (63518 / 12, 50283 / 12), + (98278 / 12, 50283 / 12), + ], + [129], + ); + i.save("hm.png"); + i.show(); + return p + .into_iter() + .array_combinations() + .map_w(|z @ [[x1, y1], [x2, y2]]| { + // dbg!(z); + ((x2 - x1 - 1).abs() * (y2 - y1 - 1).abs()) + }) + .max_by_key(|x| x.1) + .unwrap(); } -unsafe fn p2(x: &[u8]) -> i64 { - fn sq(p1: [i64; 3], p2: [i64; 3]) -> i64 { - (p1[0] - p2[0]).pow(2) + (p1[1] - p2[1]).pow(2) + (p1[2] - p2[2]).pow(2) - } +pub(crate) fn sq(p1: [i64; 3], p2: [i64; 3]) -> i64 { + (p1[0] - p2[0]).pow(2) + (p1[1] - p2[1]).pow(2) + (p1[2] - p2[2]).pow(2) +} +#[unsafe(no_mangle)] +pub(crate) unsafe fn p2(x: &[u8]) -> i64 { let mut p = x.as_ptr(); let end = p.add(x.len()); @@ -130,35 +142,160 @@ unsafe fn p2(x: &[u8]) -> i64 { (points[0][i], points[1][i], points[2][i]) = (x, y, z); i += 1; } - (0..1000) + (281..955) .map(|i| { - let former = from_fn(|j| points[j][i] as i64); - let (dist, retval) = (0..1000) - .filter(|j| i != *j) - .filter_map(|j| { - let d = sq(former, from_fn(|i| points[i][j] as i64)) as i64; - Some((d, points[0][i] as i64 * points[0][j] as i64)) - }) - .min_by_key(|&(d, _)| d) - .unwrap_or((i64::MAX, 0)); + // let former = from_fn(|j| points[j][i] as i64); + // let (_dist, _retval) = (0..1000) + // .filter(|j| i != *j) + // .filter_map(|j| { + // let with: [i64; 3] = from_fn(|i| points[i][j] as i64); + // let d = sq(former, from_fn(|i| points[i][j] as i64)) as i64; + // // println!("{former:?} <-> {with:?}: {d}"); + // Some((d, points[0][i] as i64 * points[0][j] as i64)) + // }) + // .min_by_key(|&(d, _)| d) + // .unwrap_or((i64::MAX, 0)); + // dbg!(_dist); + + let [_x, _y, _z] = from_fn(|j| points[j][i]); + let x = i32x8::splat(_x); + let y = i32x8::splat(_y); + let z = i32x8::splat(_z); + // result of min distance + let mut dist = i64x8::splat(i64::MAX); + // result of the multiply + let mut retval = Simd::splat(0); + let [(x_, xrest), (y_, yrest), (z_, zrest)] = { + [ + points[0][25..905].as_chunks::<8>(), + points[1][25..905].as_chunks::<8>(), + points[2][25..905].as_chunks::<8>(), + ] + }; + // let mut rmin = [i64::MAX; 16]; + // let mut reduced = i64::MAX; + for (x_, y_, z_) in izip!(x_, y_, z_) { + let x_ = Simd::from_slice(x_); + let y_ = Simd::from_slice(y_); + let z_ = Simd::from_slice(z_); + let one = (x - x_).cast::<i64>(); + let two = (y - y_).cast::<i64>(); + let thr = (z - z_).cast::<i64>(); + let d = one * one + two * two + thr * thr; + // let min = izip!(x_.to_array(), y_.to_array(), z_.to_array()) + // .map(|(x, y, z)| { + // sq( + // [x as i64, y as i64, z as i64], + // [_x as i64, _y as i64, _z as i64], + // ) + // }) + // .collect_array::<16>() + // .unwrap(); + // rmin = min + // .zip(rmin) + // .map(|(x, y)| if x.min(y) == 0 { y } else { x.min(y) }); + + // dbg!(d); + let m = d.simd_lt(dist) & d.simd_ne(Simd::splat(0)); + // dbg!(d); + // reduced = reduced.min(m.select(d, Simd::splat(i64::MAX)).reduce_min()); + // min_by_key ( distance ) + dist = m.select(d, dist); + // println!("{rmin:?} {dist:?}"); + // assert_eq!(rmin, dist.to_array()); + // dbg!(dist); + + // points[0][1] * points[1][0] + retval = m.select(x.cast::<i64>() * x_.cast::<i64>(), retval); + } + // dbg!(rmin, reduced); + + // let (dist_, retval_) = izip!(xrest, yrest, zrest) + // .filter_map(|t| { + // let d = sq( + // [_x as i64, _y as i64, _z as i64], + // <[_; 3]>::from(t).map(|x| *x as i64), + // ); + // Some((d, _x as i64 * *t.0 as i64)) + // }) + // // .chain(izip!(dist.to_array(), retval.to_array())) + // .min_by_key(|&(d, _)| d) + // .unwrap(); + // dbg!(dist, retval, dist_, _retval); + (dist, retval) + // todo x8? + // let dist = dist + // .to_array() + // .into_iter() + // .zip(retval.to_array()) + // .min_by_key(|x| x.0) + // .unwrap(); + // let rest = retval; + // let (dist, retval) = izip!(xrest, yrest, zrest) + // .filter_map(|t| { + // let d = sq( + // [_x as i64, _y as i64, _z as i64], + // <[_; 3]>::from(t).map(|x| *x as i64), + // ) as i64; + // Some((d, _x as i64 * *t.0 as i64)) + // }) + // .chain(izip!(dist.to_array(), retval.to_array())) + // .filter(|(d, _)| *d != 0) + // .min_by_key(|&(d, _)| d) + // .unwrap(); + // println!("{i}"); + // assert_eq!(dist, _dist); + // assert_eq!(retval, _retval); + // println!("pass"); + // (dist, retval) }) - .fold((0, -1i64), |(best, mxd), (rmin, set)| { - if rmin > mxd { (set, rmin) } else { (best, mxd) } + .fold((-1, 0), |(_scdist, _scretval), (dist, retval)| { + // we do a lil maxxing + // eprintln!("dist = {dist:?}\nretval = {retval:?}\n_dist = {_dist:?}\n_retval = {_retval:?}"); + let (scdist, scretval) = dist + .to_array() + .into_iter() + .zip(retval.to_array()) + .min_by_key(|x| x.0) + .unwrap(); + // eprintln!("min of new {scdist} {scretval}"); + // let m = Simd::splat(dbg!(dist.reduce_min().max(scdist))).simd_ge(_dist); + // eprintln!("{} >= {_dist:?} {m:?}", dist.reduce_min()); + // eprintln!("dmatched = {:?}",m.select(dist, Simd::splat(0))); + // eprintln!("rmatched = {:?}",m.select(retval, Simd::splat(0))); + // dbg!(real); + + if scdist > _scdist { + (scdist, scretval) + } else { + (_scdist, _scretval) + } + // m.select(dist, _dist), + // m.select(retval, _retval), + + // if dist > mxd {} }) - .0 + .1 + + // .reduce_min() } -const ISIZE: usize = include_bytes!("inp.txt").len(); -fn main() { + +pub(crate) const ISIZE: usize = include_bytes!("inp.txt").len(); + +pub(crate) fn main() { + // dbg!(sq([75262, 24842, 97390], [69492, 23068, 98918])); use atools::prelude::*; - unsafe { println!("{:?}", p2(include_bytes!("inp.txt"))) }; - unsafe { println!("{:?}", p2(include_bytes!("../1"))) }; // 8141888143 - unsafe { println!("{:?}", p2(include_bytes!("../2"))) }; // 83173 * 97891 - unsafe { println!("{:?}", p2(include_bytes!("../3"))) }; // 8465902405 + unsafe { println!("{:?}", p1(include_bytes!("../input_day_9"))) }; + + // unsafe { println!("{:?}", p2(include_bytes!("inp.txt"))) }; + // unsafe { println!("{:?}", p2(include_bytes!("../1"))) }; // 3200955921 + // unsafe { println!("{:?}", p2(include_bytes!("../2"))) }; // 8141888143 + // unsafe { println!("{:?}", p2(include_bytes!("../3"))) }; // 8465902405 } #[bench] -fn benc(b: &mut test::Bencher) { +pub(crate) fn benc(b: &mut test::Bencher) { let i = boxd(include_bytes!("inp.txt")); b.iter(|| unsafe { p1(i) }); } |