Problem Statement
From each square in the grid, you can only move to adjacent squares. Two squares are adjacent if they share an edge. You can only move between two empty squares if the absolute difference of their heights is less than or equal to 1. If the height difference is 0, it takes 1 minute to make the move, and if the absolute height difference is 1, it takes 3 minutes.
You can always move to a building from any of its adjacent squares and vice versa, regardless of height. This is because all buildings are taller than the highest terrain, and each building has entrances and exits for all its adjacent squares at the correct heights. Moving to or from a square containing a building takes 2 minutes. The delivery boys are allowed to enter buildings even if they are not their final destinations. Note that the pizza place itself is also a building.
Each delivery boy can only carry one pizza at a time. This means that after each delivery, the delivery boy must return to the pizza place to pick up another pizza if there are more deliveries left to do. You are given a
Definition
- Class:
- PizzaDelivery
- Method:
- deliverAll
- Parameters:
- String[]
- Returns:
- int
- Method signature:
- int deliverAll(String[] terrain)
- (be sure your method is public)
Constraints
- terrain will contain between 2 and 50 elements, inclusive.
- Each element of terrain will contain between 2 and 50 characters, inclusive.
- Each element of terrain will contain the same number of characters.
- Each character in terrain will be 'X', '$' or a digit between '0' and '9', inclusive.
- terrain will contain between 1 and 20 '$' characters, inclusive.
- terrain will contain exactly one 'X' character.
Examples
{"3442211", "34$221X", "3442211"}
Returns: 8
Only one pizza boy is needed for this single delivery. The pizza boy must first take two minutes to go from the restaurant to the cell to its left. Then he must climb from the cell of height '1' to the left cell of height '2' , taking 3 minutes. The movement between two cells of height '2' takes one minute. He finally needs two more minutes to go from the cell of height '2' to the only building in the area.
{"001000$", "$010X0$", "0010000"}
Returns: 13
This time there are three buildings, and an optimal solution is as follows: 00:00 -> Pizza boy #1 takes the pizza assigned for the left building. 00:00 -> Pizza boy #2 takes the pizza assigned for the right building. 00:04 -> Pizza boy #2 delivers the pizza to the right building. 00:08 -> Pizza boy #2 arrives back at the restaurant, takes the pizza for the top-right building. 00:10 -> Pizza boy #1 delivers the pizza to the left building. 00:13 -> Pizza boy #2 delivers the pizza to the top-right building.
{"001000$", "$010X0$", "0010000", "2232222", "2222222", "111$111"}
Returns: -1
The irregular terrain blocks deliveries to the bottom building.
{"001000$", "$010X0$", "0010000", "1232222", "2222222", "111$111"}
Returns: 28
This time, there is a possible path connecting the restaurant and the bottom building.
{"X$$", "$$$"}
Returns: 14
{"5433321123442201000000001100223222221134433323554","0013333323555677788877755446766766554555455533334","1123335545445676667788787766678999987665566666766","9999977767766777777555556655555554565444534444555","8665678786543312221233333100000012211223322333200","33210000000000$0010122221233332332122000000000000","311112231112111113345445779988X886887777788898999","3232201100234344443444423355788999888766666667889","3343322234565544335766765444445554667999998787777","4555542000012333455445554468999978888877899988887","5544445555566776666678777777877555566533353344444","3333333334544333444311012344467765655444443222333","3333334566578766788664455332232222243322223322344","0111110000112233355554557777677888877654310120133","120000102212$565554433333222222222433333444554321","5455555553335566545553323222233233433333322222011","4433343344322222000011112222344532223333555556666","4566764444423320010000110112333433346799999898986","666022222223442244434544555444665556776666433$466","8998766667777767777766665566665466642356668776668","776766779889999$98899999889988$887899999977777654","6665543445665334555666666667544434444545311112$44","6664678889999999$$8978777998877888899986665566787","7678998899988878998999788999899999998879998888777","6666667789999999999998755555554455444545555432334","3201133334446665676666677756667766664454332223344","3333344453311334433344667777653334454566899777778","6777789886667877755444444444442132344566788878988"}
Returns: 1202
{"43321101000000","10001123322211","10$1121111120$","2111$01000011$","10012001112134","6446676655$444","67754421100000","32221332444322","33335546667778","2$223335444577","44444445001100","43$21133201111","55543222223111","223333$0200000","222233444$4445","99888889876555","9$999999999999","556677687768$9","55445665555545","X9889$99998886","99999999999999","11333455667899","22212335543111","00111221001222"}
Returns: 433
{"42100022100001","55465568899997","88977544443356","8899989999999$","9999999778999$","89987766667$66","44$34345654456","45455766544445","77566555454456","76555766677776","887777$8877865","9999765444$4$$","45555444566554","3333211111111$","2100000000$000","10000011121010","11224444434232","5$442X$3401011","55566533332111","4446533100$001"}
Returns: 323
{"222011111112100100000000100","446776646665555433221011210","33320021112454321$1$3433343","566666674333212000$00231243","0011234440$1223211210223233","000000012112332323556422322","0000X0000110000110122345554","0002211111$122344676$54$464","000000011122222222311000123","443355565543332011223343443","311100000001133334445534433","35444334433335577664333222$","3332100002355$7677533333444","100011011111001123222221333","113322110010111113356677546"}
Returns: 235
{"99998887899987777999999899999998879999886778","X9887688888989876654565577787544443433344466","55445666677899999998789799889999999978988756","55556644466565555555655575334444468887788888","68798987899999999989989999999999999899989988","77666778876555577777666554454668999899998987","75546665555566566665556668888978888887777877","75333323431222222211121133321112213210112111","77676777889878766777665666654222011002222221","66656001112222333354555555455444555555677877","66567787778668999999999989889999988688889876","77789999888977777665666787789988877766686665","78899865444556666664234446666666777766666666","88778677779999977766656666777787778866788776","24554453101322212210100000000224445666666545","2222231211111002333444445666666666555566787$","65577877999899997899999766766666644665567766","56444445555554333100000100224455454578899998","43222222444422111232333579998888998776665566","45555554442121111112233533134332344422333334","22122110011122344556768999999998666556766765","12202244421345445555444567777766789887879989","66655545554322222234333444556655555557778998","44335555544444423355655567999999877777778877","55555445444433344446667677$77777555565444467","32332000110001002322001220100000001100123333","02233444566566677876556655654455555553343222","01220000010000111113343332221110011321123435","33333544322122243333467677778898888787676766","21222333333444455677798787787665797767778988","00000001111222222444422222223334666677899899","00000000001000101122201000001111111122223322","75445467678788766657667887667644344443444433","66676766667897689999998999987765689777766766","55655565321111100002211111222122121122223334","54555666655667778899889997866435666666566766","99887766544455666666676657766677777777677766","99999999898887755557789888888777789999999876","11110112210122112122323345444445567765577555","22244456667778888878999886566678776888889988"}
Returns: -1
{"5665755","4666444","45455$5","$886$55","777$765","2333445","1110133","2333333","3443465","6668875","$556654","00$1$34","0001$12","000$$01","00$0124","3335444","3332221","$$11X00","1$343$3","0101233","1222222"}
Returns: -1
{"7777877542344","$767897778877","7799723333356","00$0120002222","0010012221112","0000001012320","7643322311100","9998888779999","6677887788999","6687755776567","554$545577777","6656678867667","354445456655$","3332444324445","8887666676555","X888999999978","7767989879878","77775565$4446","8777799899987","9866667677665","6766765$66445","6644432333343","6666678778755","6788999999788","55544565666$7","555688888$998","1245557899999","1$00000001110","5444$43222110","4444344332335","557$555434435","5578$77799999","999888888899$","999$778998889","8899999999989","997888$888886","7777655655567","77878887$7889","9998888777788","9777989$98999","9888889998999","9998866889888","9999899999888","9999866555443","2$11100012234","2211$01233210"}
Returns: -1
{"9999789889","99$7777789","888788$656","454$4$4556","44$1100000","54443$1100","5433133$12","5555332232","122$224300","220$000000","221$021001","2332100022","1122233334","33$3233444","344$554445","32$5445666","34$5555455","4687756655","$666445434","8X88756664","7755555544","223232233$","1$1$100000"}
Returns: 477
{"5554444444666667776666665556676","5555455544222000010000000222322","897775534433333222312234432$111","788766555666555$676655535555677","4577777777$77888989999977778887","$665667788888899989897776788999","6789899998899878999988877667798","8999990111133222222112120121111","878665444422222222$101011112111","66645656$7777777787889999989999","9887777664455543335656565667888","9999$9865$7755775$6645566675567","123331112334443434$433133444567","1000000010000112233312221111122","2211232210000000000000000000011","222243X22222222210211111233$$$3","2313433556666654543334455421122","222222122200001$231354322100000","444$434423443112122333221111000","44211122$3333322210$00000011100"}
Returns: -1
{"8898$X8899000000$00001010000013221101$22","8877777899899$9989987666766$54$333333134","98888876655577$7666434455557788788888878"}
Returns: 174
{"45666777777766X678877$7767667","33$44567765554456656678799866","$33$122311000000000222121000$","30001000023321221000210$11$11"}
Returns: 153
{"877899899999999999997877778898999999998886445444","778887767678889999989989999898887777555543333445","566666666678887899998899877875335444555555532344","546776775$55544333453323335433332211112333433333","1$110010012111110$123468876675566555555564555553","111001333321000113356667756767777798888877779889","433322000000001011100022455444454557688898878999","43321211210120122$34545545323334556665$555778775","222233210000$$1011212321110111111110000011111335","011124423443111111000000011100000110001000001112","100000012000111100011001100234456655556666655544","0012122222000100$3233579998888998889787654577776","99977664444445455444446677767777867766677887$756","999789898899999988889999999889$78899999999987654","000000000000000110111200222233556676677555555555","011122211100000011333344564445455777777778766556","010000011221112100000022222434544677799999999766","011000000000011221100122212234$22233322110001333","565333555677666566554444422101111112232322331223","555545533111110011022222000013343222110112211243","122123320000001223222224444322221121113543334233","000001101122200000011$22213222222022334544444554","888998879999999998977876433244334345565443333345","976555544432200001100021101011000000000010000000","999998$77677776667776543311100002210000100010000","999999899X9$887788889777798999999998876555555666","899887777544457777666666555544555676443343456656","776656543444333211221233432221333344543334332223","8999999$8887777777779989799999986566787765555455","988788875565556422112200001111200002233434443332","443233345431000100000121234443543323321111000012","433433554667787878776775655555531002223355434557","312246677999999998788999999$99999999899998888888","200001110001223112222200001101222234655444335554","100000011111011113311344444310000000211111221023","01335576655465555333334577778777887778867$555554","011001111000002211111111333222211100001233444434","001102333221111222311200000011122223444$65555467","899999999988887899998688876677999888988878889987","888999778888999999989998999989999999988888777666","776653332221111111000000001000000022445665577877","789989999888667776664223444223333334554442222222","678888876677788999999998766677999999875555754333","444432231222000011100000000233333100023543423233","332210111001110000012433333211120131766777676544","999999887765665666677777777765444445501100000001","878888877787889999999878765542200000111111100022"}
Returns: -1
{"889","888","567","432","233","112","000","$13","022","00$","000","000","100","00$","012","000","00X","0$$","001","001","010","111","123","333","334"}
Returns: 31
{"322333112233312100000001001112244444444","$21001001000000111111000001100001210000","11223$445556888878866556656666655420000","01323322200000100123311011$002210111111","997776666777755677543332234434433334453","975532344444445777766565666555643346$67","000010011022233333$43444455554556666676","00011102100001242234666667$67$876799998","34333322232345566777666677775$4553556$7","33455566566676665444444333111$01X00$$11"}
Returns: -1
{"3311332345566655","223101113434$101","0000000000000101","0101210000112211","0010100224322323","0000000000231000","0111100000000100","1100000000011221","7666643431012221","6675554444445566","656$665676655666","7788988998789875","3121100101211135","3111211222112332","7877666554456442","7666875444443433","443$$22323445422","5576567577766556","87789999888876$6","8789999989989998","8654566667779999","7666789999987988","46X6776667779998","5555543332221000","0000000111221100","0000111111112344","00001000123$4455","0110000000111100","2222100000000000","2211110020020112","4433422334442222","5555666545577899","5579$77898889999"}
Returns: -1
{"78786655454544432222","33444543122333323221","33221000000022233320","11211122211X00000000","11333343243444555544","22234556677677755455","221$3211121212210001","33442233222221110111","34445776678888887777","55787789998777778998","65778888887888678776","67999999865566666667","6555667766555533322$","79990011000010000011","00000011010001223566","00000000013333355555","00000001100233464333","55544445777766544453","43222222211001221220","33455556654454311110","555665556666644$5555","45656554454445544555","533122111$1112245434","66678888886776544455","77767655666679998998","34557877765686778999","33232111111000000001","00000000000010000011","00002223333333333332","33222322223333333332","32232333556667866688","21000000111113344687","21121122446665444554","577755443332345$4444","56655554443344455666","7755688$898899776666","88887678987899978888"}
Returns: -1
{"9$X999999","99888$555","455555555","43$43211$","445321000","2232200$0","3$3333200","$$1100$22","$12122343","111111223","12$121343","122000000","12000000$","2344$5554"}
Returns: 268
{"666433221111211100110001000001010000122100","899999976766653222110113321000122111123333","66568799999888998888X999999998878898776544","766788888889999999998999999999977889999999","9999988886688988888889999999$9999999877889"}
Returns: 12
{"211124444455443","000012221211000","000000000000000","110000010110110","112113332332222","$22110011111000","211011001111011","2222$1332013334","654445543233343","766666533344446","766899999988898","899999998655777","888788887656866","889999999999999","677776666899899","433345555577999","777788768899999","566566555555566","675666778886756","666757988789987","888899998888776","876545643455334","221100010010113","222222222454444","111100111222112","223433333331111","666432222221221","55666X766677898","322333344334567","355677777777777","777899889976677","787776788877777","667665644446887","666556655567655","887766788987655","888877776667777","888866778878887","677667668888997","787877777999887","666666666777766","544555444356756","789999999999999","899999888999999","876887766655755","766656666666676","665423333556664","110000100244433","100002446545544","000112222444445"}
Returns: -1
{"7656444$5545$332444455444343333431233211X12221123","77211112000000011123333333334$4455678888677886533","000023345443221000122011233343322222000$110001211","000000001200011222210010000000$000000022232111011","00000000111133221001222233332232342210000001$1131","4333222111121110100000122111$10011111001110000000","4455567777977899989987889765577778997666555453224"}
Returns: -1
{"011000000000000000000$22200022133210000000","0001101112013333201$2211110000000000000000","12223454434335554444$466665544456422221000","76554$555665444210012223444445554331210000","677555554555767778889999889979988887766555","333332331124567657797777999986664445576555","3211100000001100112210001110000100$$000011","531100000011121110011023444444455435533122","6768888777778$9777999999988999998889989999","777767888866666899888999999979899999999999","676777765543232222334556555544345444333333","789999999989999866778999999887777786665553","7777777888876677787777$9999999999999998899","54555442334234443233345556666667788999$999","5422110002$331101132100000$122322120122111","777888877866778788876666666556444433223322","777799999887865677877776667877888665576899","888899754457878767999999889978899989999999","778899889997556786667776545555544454344455","877889999999977787555554422212332232211123","799999898876655665543223323333432333220001","566555444443344322111001200011000000100100","554434666445421111123335556667666667666899","888787799777567677766566778876666667677799","766888989989998999999998999876656655555544","777777777677988888897889999888888211222233","554454334454555453444543332222223200112111","445789998788888768898887777555333335554323","5$3566666888779898655577777777666777555567","9999999999999998888$87888888766656789999$7","756666533333346656677777899786553112334444","001111111245554222222222202000022222233333","011$00123222111112212434224344321222213445","888666765576677675543233233334444455554344","88998999988$777776688899999999976655556666","455676667777666776666544444454433355778777","4323455577776665344433345576679887999999X9","566533333344444444577788998866799999999999","534556777777798877777766787898899999978998","200111000113345556777$87777766777789999999","122223544667888889767554568775756664333333","989999999999999989988777766665577989876544"}
Returns: -1
{"87679$8878$$77$666","76656$43344555$666","67899888889$767$87","542$333$223$667787","5666$56777770001$3","4443323344$4X22223"}
Returns: 171
{"7$7755555555678865544","222222111122221000122","222222134443111000000","653420000010011111000","544555566688998776444","667789998998655654455","556787778889888877999","110222333332334457899","000100133444$56667566","09$999876878889777776","990000$33100011122456","9979998898666X5555576","999999988778899999998","788899999999887888788","88888778899777$676666","686778999999999999888","777556653453233455566","888$98777654333466666","879$99899899999999999","999999999999899998889","999989877676777899999","788998899987789$89999","899998899998989999887","86677554444433$455457","888877655768889999999","00000111222455667$889","000232110110000000000","00001110000111100$100","000001000010001244200","322333200000001111000","566554565544346667566","566544445553444667766","667667654567778779975","000001111221211111334","12220000012210022212$","112221112$110$0012221","000111234457765555534","443454676899875433455","233434221112100001211","00000$000000000100111","000023$3222222122344$","443444567667$78866655"}
Returns: -1
{"111112322221000","443320000000000","4434454445553$3","566665344333445","557988$888899$8","876556$89999778","899988999999876","777899998997677","899999789988999","345543444568999","332222322232224","999765565555564","999999999977666","998788988888777","887777764443333","65433232$223454","676566666788776","666666675456665","776656775565556","545645555555677","224556566677700","233432000010010","223332223233333","11001000$100012","001111334433434","555554333224323","798875543344444","543333233334564","566666777666666","879999989988777","999986666666888","867655557778999","6553323343X3332","444444432212222","433434654333443","001222221100221","001110100000000","101110011100001","220000231111111","444331100010000"}
Returns: -1
{"9999987555$444421332344","99989$88888999999997799","44456554$56789998999999","44556544$54455565667999","76667999999999978887988","79997778877556676666666","00$01112233566677798886","$1111122323333223$4333$","12110022224464444444564","00011110011333332111333","887$8999998866666543544","8999899886655553333333$","11111000122211113455544","11011233122100000221222","012233445566656776654$3","22111323212243200000000","4333211221111110000$000","21122333221123344667777","77545422124468866899777","5544554333X342222$11000","22222222221000011112221","13220000133324311122233","12222110011100002232122","01000000021100000011222","0000123442232101$200$22","11111100$23334222221100"}
Returns: -1
{"568$89999998$9999998888889778878$88","3445$43$2222445555566779988998998$6","222202235555X4554455644445555444344","34434464455567644554556778999$76664","3333333444334676666667777987777665$","56655432112221111223444334664454565","55664334566888$99866664566688866555","566776778899998777775788877$7876645","654443333434221111100122122343110$0","665654443320010$0012231101111000000","4422135555778887777878887887679$899","550122011000000000$0122345555576679"}
Returns: 474
{"9987788999888799999977766666666666666545432211111","6766677990100112210002333343321224333344344334345","66777679988887778999999$8789999999998899988998865","6423333333333343221000000011000000012222331000123","7666655543333332344556555444444554334433333334323","8689899999999$99988999999998888876654544466665564","2354422222111111243333222333321111123443232333444","1000000000000000000000000001111110121333222223100","6666655557776566666554322333212200101111223320000","5556778899766656667776789888777776666554433321234","3344332334656776788998777766666667686556666646554","5443445554455555643312110001110023443244667999998","8999887776566664332331122356665777666X75677888988","9999889997765644457667897777776678898999998688999","2123544554422222001112233345445556667899999999999","0121100002100111111000000000133555655445556444334","222322344220000000110210001110000000001111002222$","2200100000000001110000010000111134454555554333101","6668887666565688888887555565455433433332432222122","7777$97678889989998889997679999787667665566776665","4244444444446667889865677566888899999998898786666","3311121122111000102244434333454245776666467778778","3466545545566665554444444334446777888988998997788","3544554454333344554444546776889988766666654343322","4566556788988889999998777666776666655575666543111","4555555544444553443444455666432222123333444344433","76677767777764$6653455556566655644433224333344443","7777778899998778899999999999999999999999889999999","4443334564355666643311011333333233444555667877788","5444433234554433332222234342344432$22222221211100","3110022000002212221000000001111001211123232101100","1111000$00000000000000002221000233334445678878999","2223453333545665656766668889999999989999889998999","31000021100$0022333234545555677666677788999998876","01133454444444656667777799$8888867788976555444455","00001233233355655566777543433$2222222234446553464","5567887778766778987666777776664454345556644444446","5532456766687776888877799998886767776665443223333","8999988775445566675555666667999876654322222222244","88889898888778$8877876776799977788665445442112112","98764566677654333356676555555556778899989887544$3","9999999999998877787655566555576688888888889998866","6775666566666655556666455555556777666675678755556","6554422222212001224432222244455555788899777577777","7889887989999977554544221111211121121100011122455","7687788999999888888778788888777899897677787788767","8999999756576666444344333333355467889988875555678","88777888999987664666555668999999999$9999999888888"}
Returns: -1
{"543334443","555776555","333566667","331000000","356422210","223434544","001344455","100112334","124454664","221112200","332000000","344444442","544432332","544423333","433434343","434444444","0022235$4","000000000","555554231","677988866","546665455","565456545","779898987","766655564","976654334","899988888","332344577","333444322","544443322","688886676","324667677","444556466","766667665","888998998","999989877","999999999","78999998$","788666766","553456666","432100002","444555432","423343333","245555453","20X000121","332221111"}
Returns: -1
{"0$245","$0221","11$11","$$000","111$$","10100","10101","$0001","1$021","21000","2$4$5","334$5","33433","44442","33344","223$2","23333","3$3$3","2222$","00$01","21$22","X4222","66677","7888$"}
Returns: 455
{"676577765766$76766$545345666545554$35443","6654544433232123333210111111011001222134","310110210000$1221110011101002221$2234466","3342111$21111002210111100000000100000000","2333213233100111112222200000000001110100","4688999887778877778887668777777889$99999","210100002355445555445$76$65555$667899999","22222221$0000122224434566667X77777654545","2223311112244333345443333322344455213344","799888877666644444433320$001222221100001","8888999999$87654444466644455454332110002","98$99997656643$4333334444$66654445667788","444567$8879999999978777667788999999999$9","456788886$655331344232210011000112000011"}
Returns: 553
{"99864445555664678889888777666665433101112","123435664668866555433332444$3333222333443","11112223312344221123202100000011100000000","11221110010100000000222100000211010000112","11242332111011100011000001211100001122211","99987688876656666643322233322222220000000","99999998686666667779888899978899899999999","78899888999978887888999999999998877899899","779999987677665$677875$433310000123544554","00001111122111001001210111123354444454444","02111221101222221100000011111000000000000","12211234444422255554333332223312223321110","44567777766655550111000000000000111000000","44434444332100000232210011334432111110000","44576766565555444312222221110100020122333","97777788997767767754332443445433211012223","99876777654332111000223433456432200000122","2443444433222121120$000002111113331211212","23333453333333344356876665344432220000000","42200112132122310222334432222233553232210","44420021213333444443334445765567677776666","86677899889976665432333333122221234456556","77754445533312322244442100000111122222000","11211101111000011111112110222223234442100","0001110012344345776666653334442332223$443","554333$221X113321100000122223333210011223"}
Returns: -1
{"1$223$3322110222112212223456779977666899998888877$","1100000000112101121000233$333332211121111000000000","1101665433223$322211010100244433422$221$20100$0000","45556000011122211222221X22445554667875566645776776","$4543332112110000000010011$11234243432222$45555555"}
Returns: 292
{"9$","X8","88","$8","66","55","$5","56","55","3$","33","33","23","33","33","$3","3$","01","0$","00","01","00","00","00","00","$0","10","22","22","$$","00","00","00","2$","44","33","33","42","22","$2","22","11","11","$2","11","02"}
Returns: 382
{"22201000000110000011100000122221","00000113322310001112222133332222","55445555544322231X02444211000011","6666655554566666899999$999977989","54443223112222334467667789999999","57775677779999999998878987776677","77$8999999989999876656556$777666","77899999988999988776666755543331","77642100110$000000000$3355621121","57787555544333333324443332220110","55545544545444333333332210000000","323222$322421011112221$233324331","45557777866777998864554555543211","43345566665545555556566665544434","21000001222323222320000224555333","2210021122233$43$455544556666645","34456665555566666577656666676877","44666654467755544343333543333334","43222111332354544545554464333324","33432211112331111222334446677666","44345456555677765434655668788776","56666555433211132211$01222112443","7755543568777798877666$667877554","99999999777775557775554678877799","000001001002332244665767$7799999","$1345566678888888899999998778998","99999998999788879999$99978999999","9897899999877788887768998886667$","34442334456666666$644677778$7999","34444222210011110011101122211200","10001112210011000000012231000000","00011113355443554467776666666666","54555554233344466665644334666766","77779998655657766788899988999998","87888888777778889989878899888777","88886654423311010000000000222211"}
Returns: 916
{"77776655554332112322000111000001000124322","00000002123322322000000000000000000012222","01121232224433443433445655566666566667999","99999999999989878778899998888779899988899","99999898888897666779787778888887555777777","89988886677899988999999997899998899989997","98677555555344344566655443$678878$7876555","66677887887777765657766667888898997644355","53345555555444234321222000210001000110223","76554455466554444443322334444333355544543","77887766544444445555555442332111024224444","89999866555567777988898999999877877775444","88886643321112222010000100000111122221102","00001100000001221100000000000000000011111","1332000000100210000000123566644322$444554","67999987899889999897676688887668997778764","55444687777656644455777657876655655687999","64433557888766888898889878767766899999999","88665434444435532221111232100001101244221","55444555332333333332232100000000001132211","55422212011021111122211111111133223211001","45443333233222210001101100001002011000000","44566877665566533333212211222221111222221","11100002223333211100111222111100010000111","11100011223223444544656555454434444334444","21013444333433243233234443444444555655534","22333344455445668788877778667999866667777","10011022222211110000000012333234555555567","11000000000110110120111022333111133455668","57643554556567899998899998899999999999878","33433435666788999999999999998898899887777","55556655533345554433110013222443333577767","55444443454233222221122345466555567788866","667789999999999888X9976446556655544457776","77889876555567788877533223322233334443444","677779999999999899897787012$3456756655444","21110012112333222222110000110000000011100","21000122233435543334443331011233344543210","21000001233334457766667788999899999976553","10110000000011001000000000211124554211101","10001112211345566556667866543222223211111","23433222221002312333344444310232122112011","23333124333443332221123233211223344321100","00110000220000010001223333333333100001000","01233101111111110000000000011233344344211","56553321110000000000000000112200000000111","656666889999999777$7999998666787555432000"}
Returns: -1
{"11$121200","110111122","2433$2332","111100000","000000000","001224333","354445434","332223345","335667766","220001223","666644444","677886777","988887766","9886X6767","799999877","677754666","53$344334","566777755","999877666","9888$8877","768$78887","777788765","002333344","000000122","100011122","001122242","244$4$343","201000022","655431211","899999998","988677799"}
Returns: -1
{"7$6642112$","0112000$$1","1100010100","44$53$00$0","44$3222$0$","450$120000","1100000X00","0$0$100000","0111000000","2222000001","44$$57776$","$5566$7$5$"}
Returns: 209
{"2222443456665534555445455","3355444442234432000000224","4555554544344456668775423","6665455666655454333344323","5555666544456678766676667","X334333334433443346677777","5544545433545553334454455","5555666777766666666777766","4444443223310000000000000","$422222$12222321244443101","4433333332223567766644465","55555566788779999987666$5","6667888999899878866688999","2333555665767777888899989","2222443333444443232233333","1223233544332111111223333","1000111000000000011100010","4443233343322111112222212","4344433333322102235677767","7788888999988877797766776","6899987766779999754545666","6655455421124453344455556","0011111111011112221000000","0000000000000000000111000","0110001333346666544667779","5688999899987766678999879","6666777667778766666678877","0000000000123455689888999","0022001001134466665554444","4443444332211001211112345","3343222221221101223334554","5322220000000000000011113","5545657766444344455656667","9888999799889999999899888"}
Returns: 55
{"88999998$8888888778000","7886666655433111010000","$77776X66676666$766554","222111100133224$332334","21224555$5422234432$33","4433311012333122434323","3354334455556777788899","$33343$666665668889$99","33566664446677776677$6","$567777666776666654577","4321111001111112222200","5667654422335532332220","5444443442101011120$$0","101000$000$00000111100","121011$001232223333434","4455664444553233324445","55556677$9999997799999","66888899998878779$9999","6799999997776664433212","8766565555433223232333"}
Returns: 548
{"111111110011222X233224566","2344455442133231011101233","3211112223111133333455543","4344455555554445357799999","3344677777778888$999999$9","1134443434322111100001111","3443223443211100100001011","4454324454343233332321111","0110001122101111211000000","1111343334334544555545567","6777898899998866665455577","5666432122222211120001100","31110000100121111122$1232","2200023354456653323355557","7788889889888998999888898","7777546555555555567766655","1100000010000111000002235","2332344444677765544334322","3333334445432222222100000","4445578889999999987776899","5444555678999998776688889","4565576666766443433243333","2344444443444435543444423","4444457666778988889999998","5545788899987787889999998","4433432$33322111000011122","2222221011012000000121112","2345566776577$88765578999","3443244223566778998898898","2321100200123457788999999","9999899888977777677999999","8776766655666555555678887","6677765667555576667778878","6799999999999998887865787","9888999999888777765355556"}
Returns: -1
{"56677766668877576776655456877787789999999999999888","10001100222324346668988899755578888778776666778987","12000001222122455553444345556679888876664665545555","55667766667875533100000002234357555433222222454565","444321000000111000110001113$4444554345467899899998","66553311000112466766687888898898887667655678776677","77665444222111122200011321110000012466766667888876","54333565555422221121010133322445665457566$78676655","5577766676578875433322345665776$667789988876578999","01000001100000012222210112221122234677675435467679","00000110000222211224456432113310100110100100000111","0111111223344333211$133332322322232222243444442221","0011100011120013455766554443333333211$001010000111","6565543$222210001011221213333333233222111100011102","77999987679999989978778766555566555445423433221$32","78898889999877777689889999993320000000001111133222","00000110001001222111100000223011112113322345557887","00000111110000000000000011110022323322200000132357","11101000000212222111$01333211344220232233333333554","77X655675554432200000110001233$2122100132344343354","88898888888886665544466444333433332334444334554422","11246653544556688766666667654445555555553322200002","12011100223334322223444333333444432222333332211222"}
Returns: 724
{"33344232011","22222221000","01220011220","0222211121$","00000331011","21122100001","31002243212","212$3322310","110000000$$","21101112334","3$222134443","33333444443","76655333322","77899999$99","$567$788889","8999$9899$9","68889999988","56655355322","2$233333333","23333443333","55666654322","X5433444332","22110000012","21223321245","53232333444","45566555323","33223334344","2211101$100","12201100000","22$10000002","65544443222","77899776667","77778999999"}
Returns: -1
{"21223455676653","0$000000012223","3324332234433$","233355$43566X6","34565554456666","35666$88887888","$1111999999777","5567990000110$","$323221100001$","5$4443344$5643","87645555754443","99889999877778"}
Returns: 187
{"6444555567765543332$","656788$999$899999$$9","77999887866677778$99","$X$66$7655$$89$7$8$7","76601234$654$$4446$6"}
Returns: 364
{"67554555667666766665432222211000$000211100001$","66656778999$9999999999999888878877778899999999","6777899999777899999999998899888888998877999999","888700000000001222212234444433433343555553$455","9888888888755666666654645666676767888998987765","868777778755$56666656655544653331222200100000$","11110122322443333223110000112111$1111100000000","0121120243346775555666655667544432444333333333","0000111000010122233555556557877764312110133223","0112233433221011111223355556655467755555557778","6788988888899999989898999999998999888899888788","5677788988899777666666644535665553444456445557","9999999999998998898664444566565556677767888877","9998899998899978887666543546442244233333334577","7787899989999998888866677788778898778989977787","7877888888888888X87899999989899998999999999999","1011211100122346788999999899999999977777899889"}
Returns: -1
{"77766$676$43223322111","7X899999899$999976557","356676687$78999999997","444454444$33335442331","1001$101223334355443$","12346686764223$221233","110000012222222000233"}
Returns: 132
{"99999998999999999999999899999999887666778889","99998786899999999999987655665557677565555788","22222334555555577878777888899899999998887778","13332223433322100011111111222111010010000111","01000100000001122220000000000233333211000000","11000001212201111123334654577889999998899999","767777666444546777788999988999$8899999999999","78777766765756455553444333434454444456788989","32123344444444434456678887777788888999998897","11112433222233333323222111222210221210011111","53322011000111223311122334444210011110234322","66642321121322223444333232223343200000000000","44334432434423465467643332110000000001111110","44565444442333455433444443444333333445322201","0000100000001$2345$7554444344444332233421121","01222232110113343333443334332222221001100000","55555643344443433222222211123322110000222331","65554335444442101000222322233332444455445653","33333320100000113122334454333443555555455444","33323455555666554444422222222333333333321000","44444666776555421222122212222333333321110000","43333446556688899997779999999$88998899998988","454445555555544432122221176667878889988899$8","88998665334445546533435567000011001000001112","8$888888877789999999999888899999999889888864","88998889999999888887688776789999999999999999","000000$0001234443433223323332112222345556889","10001100000021121200000012010011000000000001","01245544544443222321233332345454333444244222","00000012110001X00246667888999977778998887768","67767767899999899989988888999999888888889999","66644434455755668889987789987777899989999999","45665667765665455433100112223456678899899889","33543222001245644323224455565543223233455677","66467789997767777888887779889988888777799997","65555444554533344556778987786666455433433334","3345566656666534$$55446666676655686645554544","24466689988988899999999999999899875666687888","66788999988878987765555566555554555567999988","44443234567654233333322221112201211223222333","66555555433432101110222211222001121001122332","67665456677776644334210100100000011111122211","01000000001110010000022222222321110110011112","00001110000010000000000001123200100011123221","5531002210011121$000123334545556675434322111","664554444446445555543323222112222466$6665556","76777889999999899997899986654565644667788886"}
Returns: 918
{"4221331110000000001222212223323554210110000010000","2112211221211111211122223333332223433333210111110","3332222433334233223555655355433322312111000011111","7676776777778888878644332333532210000000000111111","8664333334444445444555444443455$45466555555666777","$667676666667898777777667899988998888877779999988","6555443332200000011100022211233333333323332112223","3221122000012212222112232000000100000011000000111","3332235555777776566665555555557865555579999888876","2213232223345553445655555678977776778977888888777","2202210100022021013100000001000000000000000122321","3335687667667886554333334432334344564444335423321","3$21346664444567778999999988998899997888887667888","0121343566678876666666666678999998998888877889988","0000000000000002211223346666779887665545544577777","1112454233111000000000000112243344455565555344557","001111000111122200000000012222232245555677778$998","9999988879988899999987666788787886435557768899999","7666553456667776666666657778888667777767655666799","8999998999787666655666687777754556668999999989889","8888688889999999998665555445546655444434454210001","7778777776667888886686555422221123334444443453321","7766644443444434565666687999999898999999999999999","9999999999988999999888999999999999999898667777999","7766566655543211223331000000000002200123332234331","000000000000111$101210000011243334677554334444222","0000001222223445555555666423222211122011234467655","1001002313332120000000000101222223344456667888877","34444$4344445554444445422101233344455688777654454","4454466554444655543554432212211111100002446555454","43322222232344444432223322$1223356665679988776778","33324455444667777899999$99877998888999999$9999999","55333000024442100$0000000011001121211122222013444","5644333333344567677877777778888888899978888887765","3345557677666755544332222000011111121000110212334","554643334334545433334332201122X000000111232332344","3445668998989977777865445555444333332110000000100","1100002111100111112213334323322000000011111210000","1100000000000023556798777753322355654444455444444","8888888999999877566798898877578888777799887976554","$999888999999886666778888899999777777777899998878","7764456655566689999999999998889999999998899999999","7777777777788888$8788$776654444444668999875444445","6779998$89999999999999999998899998899989$76666655","778899998877$666677756777877776443122100022123323"}
Returns: -1
{"20","2$","33","22","$1","$0","$1","$$","23","2X","00","$0","0$"}
Returns: 51
{"$9887888877677888999$9899988887889999988998879","77999999788889998756$653544421111000$011000000","7776434444444553222342333332333223331111210000","777755$665654332222111010000000012343312333233","3344654322232011111000000000001100100000002344","3333322222111110000110134322200000000111001101","2245533322122221100000111111222244322210011121","122200000021001112$110010022233555553321333554","2111111110011012222244332222122000000101111235","1111000000122200000000000011212201000000010000","7887666666665778987999999999999999988889753211","6666455421101000001102354434333555466555767766","9989999998886777667766454343311011000001233567","8776666566544431112100001112344333222101100001","656655$44444654445$6X233444444445555555$544111","1210000001110111222222011222100000121000000000","1000001122100110000000000000$00124442221011100","1111122200011222232000222234222456555554554444","45567$7755555467777675555778897777766666666656","334355566555577865534444$333333443333244434432","0000000000001110123333344221102122222000000133","0013355566668889977776456766668999998886$67888","5565554444454344556666877667667666568899987788"}
Returns: -1
{"9778887665555446788878756889799999987788898","9789998887788987999987768889999998888999998","1210012233333556667654554555544445777778788","1233431121222323220010011110132322$21000132","1111220010000121110110000001122222122211111","2211222232222212334455X21122221111000000000","2232110000000011211121211100000012222234221","3333444442222220000113224456776886666556777","1000001124445554657988887999999988899999987","3443111111012$5544544444222$110012244443332","0000000112212221001100000000000000100111100","22335555778886777776687788887888$6665577898","4433554566899989999988779999989888787778898","455444445554333$454432100100100000012211000","2222112221212221111121011101210011111000111","1233234433332211000001134553333322123212224","5444456797678889867653221222120020211012333","4446677766667889998889887877777777766689767","9999998877899988888888899977667899989888778","9999989987777766432111112455544554555555555","7656666664467777999999999999998999766667655","5$54566555533344333223432210001111220100001","3455566677675534433100000000001002122222111","4332022233332234333321222335445555444566888","8776566667788999999999998999999999999999888","8886775455443433211120000134444444567766645","4455787667767888777775321223333133333455565","4444566666777776655654444546666777765766776","6676766788878899878998888776655687887776766","7666433345565446444445443333334454444311012","9999889988999998999987679999975444322100001","8889788888877889888778989999888887888998898","2222111000122223243333454555666777778889888","1000011000000000001211101000110000000000000","199988888777677667$887667999755544443220000","9900000134444577788766554443135666$68877655","9997867778877776556666665655544445566556445","9999999988998876665446777776676545433233311","888$887764333211111231100010001110000000000","8777777655444$467999999999986665$4445444444"}
Returns: -1
{"4222111334564333324567665555546555431","21111000100000$0112333221000000001311","4343342332100011122222331000101221234","11100000022332211122344$3332333332334","3333544334444456655421011122232210100","2111346555331110000012222110101221000","0001300122221110000123454344222433334","0000233465453544444333466887766644444","0002221333456655444444432100002224444","0012122321001211233322211111111223234","000$0111313322200000110$1122221111011","3331100012111101124443323101223320$11","3222212222113222211123568899999999899","2224454555565577789899988778887689889","3334454566666555556799988875677765446","4331222331$21224644556666555666556667","44444$7764222323322232222102222333322","9887777898999977665644444211111223333","9998899$999988886555$666776777653322$","2333564444344433442234445677787887643","2133222210000000023332132222211211133","466666776776765433$33333355444555$55$","4678888888888998789999998899$76777866","444334655577$899999999999988899997786","4445766756777766778879988888888899888","5555556444444576555567887776776777999","5556666567777777767668678777778775556","99977877778889877865566$6544566665555","9999999877766467777888866777666466554","4442233333210011200000000011100123434","44433X2111233232222111211011111222124"}
Returns: 1778
{"00$34$4435$445554","$135$645$5$5567$8","55788889888788988","5$56677$788888899","33557898889777789","23$66000100$12222","200111122X2200201","23332234221211111","875433210$1221$10"}
Returns: 212
{"00122222223322212333211222222223X332101","011222100000210110000000012121232232344","11101000000000024$431224445566645555665","000023333323422323$34321111000001211001","65689888987655655554$433444445553333331","666788888999999888889999889999889999988","665444666544653210211112355566779989988","678899999976666666777898788898778877787","675555555444468899999999999999888766677","678766656667777667999878888667555666667","555677653333322221233323333234423324456","565544566778776665446466865444223444442","00011112222100010000000$123221223455543","00011$000000111101111222211111122121000","0000000000012$1234454333333200011221111","000000000001100121000000001110111111234","$2110000000011100$000000000000011122234","121111224434344331223222222100222333222","44433212200134576665544434675666554432$","445566455554454443223311100000023445554","000000133545566667888865565565444554443","023334444322221112332333333554554555544","679899977778899999999877667655555454455","665666556687777788887898876665645555677","110100000000111111221244444666777787777","11001112111122223322221100112223446665$","789999888999999999899887566666666655445"}
Returns: 780
{"999998887888999$778768899988877","2234555555777678886755787888887","2223444356643333321112112222112","2223357998998211111112342342112","1100000022332202101111000121223","0001111000221210121000011000111","1000011011100000000112232001111","0124444435665433333111233222222","0002221010100000000100112233333","55555$6878888776777677765332321","655566777775554432001100233$334","01111333454444466454344443244X5","$000000000111133455555564321000","21233333320000001101$1112111000","2321112221100000111001124310111","2220000000001220$00012321$20011","3445664324665532232221100000000","122222001$000000000000110000000"}
Returns: 225
{"X$","$$"}
Returns: 6
{"$X","$$"}
Returns: 6
{"$$","X$"}
Returns: 6
{"$$","$X"}
Returns: 6
{"X9","9$"}
Returns: 4
{"X9010101010101010101010101010101010101010101010101", "15199999999999999999999999999999999999999999999990", "09090101010101010101010101010101010101010101010191", "19191999999999999999999999999999999999999999999090", "09090901010101010101010101010101010101010101019191", "19191919999999999999999999999999999999999999909090", "09090909010101010101010101010101010101010101919191", "19191919199999999999999999999999999999999990909090", "09090909090101010101010101010101010101010191919191", "19191919191999999999999999999999999999999090909090", "09090909090901010101010101010101010101019191919191", "19191919191919999999999999999999999999909090909090", "09090909090909010101010101010101010101919191919191", "19191919191919199999999999999999999990909090909090", "09090909090909090101010101010101010191919191919191", "19191919191919191999999999999999999090909090909090", "09090909090909090901010101010101019191919191919191", "19191919191919191919999999999999909090909090909090", "09090909090909090909010101010101919191919191919191", "19191919191919191919199999999990909090909090909090", "09090909090909090909090101010191919191919191919191", "19191919191919191919191999999090909090909090909090", "090909090909090909090909$$$$9191919191919191919191", "191919191919191919191919$99$9090909090909090909090", "090909090909090909090909$99$9191919191919191919191", "1919191919191919191919$9$$9$9090909090909090909090", "0909090909090909090909$9999$9191919191919191919191", "1919191919191919191919$$$$$$9090909090909090909090", "09090909090909090909099999999191919191919191919191", "19191919191919191919101010101090909090909090909090", "09090909090909090909999999999991919191919191919191", "19191919191919191910101010101010909090909090909090", "09090909090909090999999999999999919191919191919191", "19191919191919191010101010101010109090909090909090", "09090909090909099999999999999999999191919191919191", "19191919191919101010101010101010101090909090909090", "09090909090909999999999999999999999991919191919191", "19191919191910101010101010101010101010909090909090", "09090909090999999999999999999999999999919191919191", "19191919191010101010101010101010101010109090909090", "09090909099999999999999999999999999999999191919191", "19191919101010101010101010101010101010101090909090", "09090909999999999999999999999999999999999991919191", "19191910101010101010101010101010101010101010909090", "09090999999999999999999999999999999999999999919191", "19191010101010101010101010101010101010101010109090", "09099999999999999999999999999999999999999999999191", "19101010101010101010101010101010101010101010101090", "09999999999999999999999999999999999999999999999991", "10101010101010101010101010101010101010101010101010"}
Returns: 72994
{"09010101010101010101010101010101010101010101010101", "19199999999999999999999999999999999999999999999990", "09090101010101010101010101010101010101010101010191", "19191999999999999999999999999999999999999999999090", "09090901010101010101010101010101010101010101019191", "19191919999999999999999999999999999999999999909090", "09090909010101010101010101010101010101010101919191", "19191919199999999999999999999999999999999990909090", "09090909090101010101010101010101010101010191919191", "19191919191999999999999999999999999999999090909090", "090909090909$$$$$$$$$10101010101010101019191919191", "191919191919$9999999999999999999999999909090909090", "09090909090999999999999999999999999999919191919191", "19191919191010101010101010101010101010109090909090", "09090909099999999999999999999999999999999191919191", "19191919101010101010101010101010101010101090909090", "09090909999999999999999999999999999999999991919191", "19191910101010101010101010101010101010101010909090", "09090999999999999999999999999999999999999999919191", "19191010101010101010101010101010101010101010109090", "09099999999999999999999999999999999999999999999191", "19101010101010101010101010101010101010101010101090", "09999999999999999999999999999999999999999999999991", "1010101010101010101010101010101010101010101010101X", "09199999999999999999999999999999999999999999999990", "09090101010101010101010101010101010101010101010191", "19191999999999999999999999999999999999999999999090", "09090901010101010101010101010101010101010101019191", "19191919999999999999999999999999999999999999909090", "09090909010101010101010101010101010101010101919191", "19191919199999999999999999999999999999999990909090", "09090909090101010101010101010101010101010191919191", "19191919191999999999999999999999999999999090909090", "090909090909$$$$$$$$$10101010101010101019191919191", "191919191919$9999999999999999999999999909090909090", "09090909090999999999999999999999999999919191919191", "19191919191010101010101010101010101010109090909090", "09090909099999999999999999999999999999999191919191", "19191919101010101010101010101010101010101090909090", "09090909999999999999999999999999999999999991919191", "19191910101010101010101010101010101010101010909090", "09090999999999999999999999999999999999999999919191", "19191010101010101010101010101010101010101010109090", "09099999999999999999999999999999999999999999999191", "19101010101010101010101010101010101010101010101090", "09999999999999999999999999999999999999999999999991", "10101010101010101010101010101010101010101010101010"}
Returns: 30281
{"X$", "00"}
Returns: 2
{"X0", "$0"}
Returns: 2
{"$123456789$98754321$123456789$", "111111111111111111111111111111", "$$$$$$$$$$2222222222222222222X" }
Returns: 323
{"X$$$0$", "$$$$2$" }
Returns: 44
{"010101010101010101001010101010101010101001010100", "010101010000000000000000000010101010101001010100", "010101010101010101001010101010101010101001010100", "0101010101$1010101001010101010101010101001010100", "010101010101010000000000000000001010101001010100", "01010101010101010100101010101010101010$001010100", "01010101010$010101001010101010101010101001010100", "0101$1010101010101001010101010101010101001010100", "21741254125612784100$000000000001010101001010100", "010101010101010101001010101010101010101001010100", "000000000000000000000000000000000000000000000000", "010101010101010101001010101010101010101001010100", "000000000000000000000000000000000000000000000000", "010101010101010100001010001010101010101001010100", "000000000000000000000000000000000000000000000000", "0101010101010101010010101$1010101010101001010100", "000$000000000000000000000000000000000000$0000000", "010101010101010100001010101010101010101001010100", "000000000000000000000000000000000000000000000000", "0101010101$101010X001010101010101010101001010100", "000000000000000000000000000000000000000000000000", "010101010101010101001010101010101010101001010100", "010101010101010101001010101010101010101001010100", "000$00000000000000000000000000000000000000000000", "010101010101010101001010101010101010101001010100", "010101010101010101001010101010101010101001010100", "001010101010101010100101000101010101010100101010", "000000000000000000000000000000000000000000000000", "010101010101010101001010101010101010101$01010100", "001010101010101010100101010101010101010100101010", "010101010101010101001010101010101010101001010100", "010101010101010101001010101010101010101001010100", "010101010101010100000000000000000000000001010100", "010101010101010101001010101010101010101001010100", "010101010101010101001010101010101010101001010100", "010101010101010101001010101010101010101001010100", "000000$000000000000000000000000010101010$1010100", "010101010101010101$01010101010101010101001010100", "010101010101010101001010101010101010101001010100", "010101010101010101001010101010101010101001010100", "010101010101010101001010101010101010101001010100" }
Returns: 323
{"X$$", "$$$" }
Returns: 14