BR6PLNFLH52ISLMGDXB675WOVUHCJQDXAMF7FT2CHVA2SD7L3NUAC readtable =: 3 : 0d =. 1!:1 yd =. toJ dd =. cutopen dd =. 0 ". each dd =. > d)pre =: 25 " 0NB. this isn't quite correct, because it includes 0, but I already know that 0NB. isn't an input, so whatever.ck_expanded =: 3 : 0last =. _1 {. yavail =. _1 }. ylen =. # availNB. matrix of 1s with 0s along the diagonalwanted =. -. (i. len) =/ (i. len)NB. (avail +/ avail) is all pairwise sums of availsums =. wanted * avail +/ availNB. (a e. b) = a `mem` bNB. (~.) = nubNB. (;) = flattenlast e. ~. ; sums)NB. Don't panic!NB.NB. (_1 & {.) = lastNB. (f e. g) x = (f x) e. (g x)NB. (f @: g) x = f (g x)NB. (_1 & }.) = all but lastNB. (+/ ]) x = x +/ ] x = x +/ x = all pairwise sumsNB. (i. @: #) = range 0 to len-1NB. (i.@:# =/ i.@:#) = 0 matrix with 1s along diagonalNB. (-.) = boolean negateNB. (-. @: (i.@:# =/ i.@:#)) = construct 1s matrix with 0s along diagonal ofNB. size len(input) by len(input)NB. (f * g) x = (f x) * (g x)NB. (+/ ])*(thing two above) = matrix of sums excluding diagonalNB. ~.@:;@:(above) = flatten and dedup all sumsck =: (_1&{.)e.((~.@:;@:((+/ ])*-.@:(i.@:# =/ i.@:#)))@:(_1&}.))NB. (|:) = transposeNB. (1+pre 0)&(-.@:ck)\ = apply [ck] and negate to every continguous (1+pre 0)NB. sub-arrayNB. # = "select" -- 0 1 0 # 1 2 3 = 2NB. ((pre 0) & }.) = drop (pre 0)solve_one =: (|:@:((1+pre 0)&((-.@:ck)\)))#((pre 0)&}.)NB. This solution doesn't actually work, because for some godforsaken reasonNB. it insists that (bad = sums) is a length error, regardless of how much INB. insist that (bad) is a scalar. However, pasting these lines into the REPLNB. gives the right answer, so whatever.solve_two_expanded =: 3 : 0data =. readtable < ybad =. solve_one dataNB. once all elements are greater than [bad], we don't care anymoredata =. (|. +./\ |. bad >/ data) # datalen =. $ dataprefix_sums =. +/ \ datasums =. prefix_sums -/ prefix_sumsloc =. (bad = sums) * (i. len, len)row =. <. loc % lencol =. loc |~ lenspan =. (row - col) {. (col+1) }. data(>./ span) + (<./ span))
24273132629141625153264122211287448134734518331145391014211615172019622231287262413252729182835423031321433214636371519406320223867343943415329444576845035554256744873495888516364696870717778868595901141388391136206153971211191091151201311391371412071811551631731761742101803051922123693032282062242342293172512803502782963183793283363824973543723864403984185245874794304537076968126976645965747717226821175690758114072682678481689799288310669091112117911701296131820881238138013001995137214661416144818961510154221121986172517803008194919753412228227212408273428282864301834592672278828202882295832283322423132674670350536744957425746834383552246905129508054065460549255546247817556081016281959663649565896772788810278880397638640138039073109281018297701054010486108661095211046144111442212103175411698118573130841891824897146601652817876174431771318843192551955919952249082031035824213522536324036231493118825187267632774429612395653887040023321035744138795388143515636968380983920739511445014166243459642339197747185655584833651950547996661490745829707131076912672596907174667797607212473254866961345598616312035785121115595109017955211463749913510028610313510674912141314051313633013856913938314119517285914232514537815188415724517181718698219865617128423770418064220227019465619580724364824033030540520988427684327489931038627571327976430262348324528770339331229726230912936709147152041215437529845554137644938291266821147070649306945021448478358528548672797785255061255547757833659032658496559683260639167371166435311350599574337886039422689732811005691759361102131892092093499713789291476397971510103733910422041796700196389411338131163301117529113443261385435128010213380641423714193465224820881760113173087122857931680281197233623063552421133190650720088492013714384484721711522761778358678825013652297114233859233302212618166266553730109735061092310399534111523440394349098442694504310828365261738788434807720391535639202214022563688981644682668460337608815368068584635706491528049567586931378627078389363206114968651514765443896851546709301171436017675180753146075728387794199838362278355777942784849082911275124910397211150853955098695924649872038112275411107172612385751126301151476819113658748139445571339593513995147152480181481878115104298196587462077852718696436162191991577836123309610235461331865495818976010206227122250215326625262209437643132349736048062250158662847752927054683273404922739108228214716299230793931914830882659319975603964020034433319344747976186587937630968392776704599545039598722399197744595963043445917643978764799844754445765532305825909737562648035681344906080573876950116581377956956327962880219775507427371098968908116106136242721057657690863812101801479197444106093952795184968336569114508460696676499115878617120785830107676347111368377151624261118943533136591208127045911134985984127701074154459380131788335141013881142619105148426612156427134149014403281505291158715940180042190189459643239295604191042038228464834236664447300828020219044724226619880298985723255534741245989444373035355290504275259489409268714955272802216280802738283632986291045717394416056305441537307730343371084228338758130599549062380501681573630236410086762501267050527168722519872744528204364517665597373803594586244275574156492532291625540292147578243753102843577268594321885642372757467870359648725461317188064419966764648847370984235898697547411013252149060952191106448117937255484914095741891469191114546350510499572229479600869484822971152400245107258377211069703281118535900129911509816001473541510582995182872467512211671761209659134132301423822204253531594970770206649598618201909601797564410180556493219984395191851351225183942927723551226392169649473340507986125429308562021066069266298324021795541002225506228232819503432196066952821314530243082631025326733723060596453280462990447023228453392535180341516173036177553703603129342615042874236449942094167624311386049534640090787504190715542420062016953373032765865226357559326982579214648594405060328703291710058459880405252140840496349968254914227636135802714913641697262197916349692042932777075365370182910727220884712724812355175054895557654072959112236326427869574096819979429283913357118605680497105567695071250971383513364023478104549224459368560010113374108031021564052210743563603110993023961171121439712355594348132380827061344067634614672364031266787590521446900826314726374267186131376991515956251419911008689160693683882257123487021724154358169970162081797424050719584200532198234824552011212361321314942918204678624062740677919123656316868218428659992281051679328113040377255936770542790968460928167050613365152300302919538253035653568920343105747994175387468831228930902482791742264858090278344534671151654101915564837754701537558441039400520629387747455675640579986019509775674064231072840544653382792702204130144743654305367744160932535033616635478905958456076735222847322925656042431343263505957329655395057019303092980768787371941712809938407761050397778138427058798691694448063204895782211823831828907144241556129838141623427965421176569560671752427536381050776962249208992584510786085648524298691457010829242124711904286736415099919577215417170826433085573745214367793275912904546303013682049954114006836578123850369823814889149781716510253825516208099327516050121840116284387278827020365302720193358178822594937731419716762206919995078233022412056358820038234709221113279320928571199735822733528861129188933581861656773481026586596257128321717129426911382881127272339578927688886532249382291760647213723481532492486606330939271621843228464630232258221167632334509118936001149485739711840439946779954435940033312942239754996916141108357553942450291068041151514030154600269413349320125118249644911742260814203735766940421107559530560746554183722460054961226111158211611200760023395651163273780740764826995725268259370653363197492789472013218083764592730286589399908658310196571776581093907121755868132673781132827421819480906510946282259871584083601805098190471639148310785652294291315437788302103828634202211317283731181091449485711112395333660712148539194141149846217622126470981854012322088844051264712735301145457364373415366913193771940793482580152919729029914549924123272151385550776235372413032423973299640801631663825302380829777405816450831604433851903607814211685157145119430027335052578945748934212973582773322154028223182223177858829287729204484822737995542292364700137036271970514762827939100256002496921619706399636396233829841897026262991683731704684358733951830866562376293606377963103327674698574537613996530353574666558807358808589394837619347318943774818988176470868157666748365567190794072738561238585569273467953742136645544438580681147449697741305855505465399744638499691265548111132233252166267673345290831645306666132279643659758734343306070845940255636340322337466747421315776693034200732810335537616168514135445527162752452755116013331339028483500564843924304605422678475575494141126670507963690770803724128569715974296114062392746538935558094205913547710432310614373125595985512645859999293313365711435210387165711654234868680173074073263271352615567612912046719374585141742013164161303814535495117646796346708135444477452841909817251282514014165997307150103100021692544090639605216331058114257164172735237102073131524109217505274068501177051930786191807103519852818790684552804188648894307761899060356292238038722567419197844577951702345548701270025084864729536237009542432652855475774745325572875050714311091805534793182882990775531191244091992394550723933593171935907592629024475999476325155840706703134136811642634036251192876327483316379673392254759221135210467147120355763092670296393957572995936861719751332