Statistics

Problem Statement for "CornersDecoding"

Problem Statement

Corners compression is a method of compressing black-and-white images to a list of so-called corners which works as follows.

The image to be compressed is a rectangular grid of pixels, where each pixel is either black or white. First the image is padded with a row of white pixels on the top and on the bottom and a column of white pixels on the left and on the right. All the following processing is done with the padded image.

Image rows are numbered from 0 (top row) to H-1 (bottom row), and image columns are numbered from 0 (left column) to W-1 (right column). Each pair of indices (i, j), 0 <= i < H-1, 0 <= j < W-1, defines a 2x2 block of pixels (i,j), (i+1,j), (i,j+1) and (i+1,j+1). To perform the compression, we consider all 2x2 blocks in the image. Blocks which contain an odd number of black pixels are classified as corners (the corresponding blocks are shown in the image below).

The compression result is the list of corners - all pairs of indices (i, j) that define a 2x2 block which is a corner. The image below shows 3 separate images with all their corners marked.


The set of corners resulting from this process, together with W and H (the dimensions of the padded image), uniquely identify the original image. To prove this, note that the image can be restored using the following process. Start with a HxW grid of pixels and set the color of the boundary pixels to white (these are the pixels of the padding rows and columns). If the rest of pixels are scanned, for example, in row-wise order (each row scanned from left to right), each pixel is the bottom-right pixel of a 2x2 block, with the other three pixels in this block being known (since they have been scanned earlier). Thus, the color of this pixel is uniquely defined by whether this block is a corner, since one color makes this block a corner, and the other doesn't.

You are given the list of corners in int[]s rows and cols. The coordinates of the i-th corner are (rows[i], cols[i]). Return the number of black pixels in the image which could have been compressed to this list of corners. If no finite image exists that could have been compressed to the given set of corners, return -1.

Definition

Class:
CornersDecoding
Method:
blackPixels
Parameters:
int[], int[]
Returns:
long
Method signature:
long blackPixels(int[] rows, int[] cols)
(be sure your method is public)

Notes

  • You are not given the dimensions of the original image (W and H), so the set of corners can be decoded to several images, but all these images will differ only due to extra white rows and columns on the bottom and right sides of the image, so they all will have the same number of black pixels.

Constraints

  • rows will contain between 0 and 50 elements, inclusive.
  • cols will contain the same number of elements as rows.
  • Each element of rows and cols will be between 0 and 100000, inclusive.
  • All corners will be distinct.

Examples

  1. {}

    {}

    Returns: 0

    Empty set of corners means that the image is all-white.

  2. {0, 0, 5, 5}

    {0, 5, 0, 5}

    Returns: 25

    This example represents the first image from the problem statement - a solid 5x5 square of black cells.

  3. {0, 0, 0, 0, 4, 4, 5, 5}

    {0, 1, 4, 5, 1, 4, 0, 5}

    Returns: 13

    This example represents the second image from the problem statement. Note that several corner blocks can overlap, i.e., have common pixels.

  4. {1, 1, 3, 3, 5, 5}

    {1, 3, 1, 5, 3, 5}

    Returns: 8

    This example represents the third image from the problem statement.

  5. {0, 0, 1, 2}

    {0, 2, 3, 4}

    Returns: -1

    No finite image could have been compressed to the given set of corners.

  6. {0, 0, 100000, 100000}

    {0, 100000, 0, 100000}

    Returns: 10000000000

    max area test

  7. {1, 1, 3, 3}

    {1, 3, 1, 5}

    Returns: -1

    test of ivalid image (scanned rowwise doesn't close)

  8. {1, 3, 1, 5}

    {1, 1, 3, 3}

    Returns: -1

    test of ivalid image (scanned columnwise doesn't close)

  9. {0,1,0,1}

    {0,0,1,1}

    Returns: 1

    min test

  10. {0}

    {0}

    Returns: -1

    min invalid test

  11. {0,0,1,1,2,2,3,3}

    {0,1,0,1,3,4,3,4}

    Returns: 2

    unconnected image

  12. {5160,1223,16625,16625,5160,2266,13416,13416,1223,2031,16625,3746,2031,11400,13416,16625,2266,13416,3746,3746,5160,1430,1223,1223,11400,5160,3746,1430}

    {41,8478,7095,8478,11448,2860,25623,2860,25623,25714,41,8478,4480,21760,11448,1440,21760,4480,7095,25714,8478,11609,7095,11609,7095,21760,21760,1440}

    Returns: 183473841

    #11-40 are random valid images, generated as two independent sets of rows and columns, shuffled.

  13. {8052,3108,10696,4205,9154,10696,29952,9154,3108,3108,29952,4205,3108,10696,8052,29952,10696,29952}

    {7700,4032,7700,3120,2256,2256,3120,3120,2256,6936,2256,6936,7700,1200,4032,7700,3120,1200}

    Returns: 129699928

  14. {3291,1300,1300,1300,4494,3291,4494,1300,4494,3291,1337,3658,3291,962,962,1337,4494,3658}

    {19562,6612,1976,4250,19562,6612,5820,5820,6612,5820,1976,5820,1976,1976,19562,19562,4250,6612}

    Returns: 30230496

  15. {3485,23765,21271,4796,4796,12672,2873,13260,6217,3485,13260,951,21271,6217,6217,13260,6217,21271,3485,951,23765,13260,3485,21271,12672,2873}

    {182,7128,17100,91,15139,91,7128,12514,7128,12514,17100,3750,74,182,91,74,12514,15139,91,15139,15139,7128,74,12514,74,3750}

    Returns: 160506441

  16. {0,16842,11520,5429,4784,1791,16842,3304,10656,27907,30954,20328,17124,5429,27907,10656,27907,30954,4784,17124,1791,20328,11520,30954,1791,0,17124,17124,1791,3304,30954,27907}

    {3333,5856,3736,758,3333,9,3736,3658,758,3333,6192,9,9,6192,5553,2431,3736,758,5553,3333,3658,4122,758,2431,3894,3894,5856,2431,3736,9,4122,2431}

    Returns: 86317138

  17. {9711,25461,8695,23976,7740,40932,546,23976,19844,37858,546,16860,8924,19844,2208,33858,8695,9711,1528,16860,33858,8924,57000,1528,9711,19844,15575,8924,25461,2208,40932,40040,37858,57000,14016,19844,23976,40040,16860,9711,23976,1350,1350,49129,14016,49129,8924,7740,15575,16860}

    {0,6322,7675,0,4222,1536,996,4853,3142,9557,8364,6322,4853,4222,4222,7675,9464,2752,9557,996,0,2240,1536,2752,9464,7675,2240,1536,8364,7216,8364,8364,2240,479,4222,1536,7216,6028,2240,6322,6322,9464,0,996,6028,9464,3142,479,996,7675}

    Returns: 247288209

  18. {4788,11111,9790,9889,9790,1353,8536,15778,3010,15778,1353,9790,9475,1353,8536,8536,9475,3871,2756,17578,7787,5760,17578,3871,9790,5760,2756,7787,11111,17940,3871,2756,3010,9889,3871,9889,7020,8536,7020,4788,5760,17940,5760,11111,9889,11111,1353,2756}

    {475,161,438,130,321,100,475,374,100,290,198,290,142,514,514,178,198,142,130,161,425,151,514,151,100,196,321,374,438,100,290,198,198,316,438,196,514,151,151,178,438,321,425,316,321,392,392,290}

    Returns: 3762808

  19. {9027,1682,17084,14729,22588,15118,5184,8138,17084,22200,15118,22588,22588,5184,15118,14729,12834,15118,60,22200,5184,12834,60,22200,14729,1682,22200,22588,14729,9027,8138,5184}

    {2400,21150,2400,21150,3400,8556,22462,3400,7791,22462,7791,28210,2400,2312,2400,7791,1670,0,7791,8556,21150,28210,2312,21150,0,2312,2312,1670,28210,19418,19418,28210}

    Returns: 343023143

  20. {4300,3375,11598,3375,8520,13902,5757,7660,6840,4300,11868,5757,6560,13552,13552,6840,8520,6560,7660,9119,9464,6560,1231,11598,4300,3924,3924,9464,12077,3375,9119,4300,13902,6560,1231,12077,9464,3375,10375,10375,11868,9464}

    {18786,20513,18192,17750,3958,3958,18786,2952,20513,24308,4770,22885,24308,3958,18192,2952,19981,19981,21843,21843,4770,17750,22885,17750,22885,3958,15074,24308,4928,19981,2952,17750,18786,22885,19981,15074,18192,18786,24308,4928,18192,2952}

    Returns: 102683496

  21. {6032,7196,6032,3452,3452,0,3452,6448,3452,0,7196,7196,0,6032,7196,6448,6032,0}

    {4,9324,4580,4,1622,4,3732,5063,2475,8784,8784,1622,9324,3732,2475,4,5063,4580}

    Returns: 26458512

  22. {68,42,42,69,3,72,42,69,20,20,68,34,69,10,69,3,5,20,34,5,3,42,68,80,72,68,72,80,3,72,10,80,34,20,68,34,80,68}

    {5984,5984,5598,859,7520,8146,4893,13698,5550,13698,5942,13520,13629,5598,441,859,5550,13629,5942,13629,8146,5942,441,5942,5984,1008,13698,14885,13698,1008,5984,13629,4893,13520,14885,5598,5598,7520}

    Returns: 507763

  23. {6511,12924,4316,4849,10990,8305,7602,1841,5175,4316,7602,4316,5175,8305,6511,10990,8305,1935,6511,10990,5288,5044,7602,5288,5288,4849,1935,1935,8305,4316,5288,6511,12924,10990,1841,7602,5044,1935}

    {200,226,392,526,200,348,348,375,526,75,250,368,200,219,458,110,195,458,110,348,368,458,195,348,75,250,368,195,375,200,219,226,494,458,368,494,195,392}

    Returns: 2665673

  24. {5240,4128,5494,904,4888,9088,11088,4128,9672,9088,9672,545,5494,14420,5240,4128,545,4888,11088,904,14420,545,545,4128,14420,14420}

    {15750,8748,5055,8424,8424,14382,8748,14382,8512,7795,5055,5672,15750,5672,8748,7795,15750,14382,11542,8512,11542,8748,14382,8424,15750,8424}

    Returns: 77752110

  25. {5498,5250,5250,7934,1065,5498,1065,1065,7934,742,5498,742,1065,5498}

    {3920,7340,3920,1846,2630,7340,3920,1846,6024,7340,6024,3920,7340,2630}

    Returns: 15605900

  26. {4907,2262,5413,1263,3031,3159,1263,3719,5115,3719,4186,1599,5602,1275,5413,3031,1599,3159,6751,1599,1263,1304,4597,1134,4392,2262,3031,4597,6751,5413,1263,3719,1134,4907,4392,1275,4971,4186,1275,5115,1275,5602,3719,4971,5115,1304,3031,5413,5115,1599}

    {2805,2461,2665,3802,1800,1662,1662,229,4141,4141,1800,332,3802,3287,2461,2556,2556,229,7139,2494,7139,0,4680,332,2556,623,2461,1800,1800,7139,2494,2805,1662,332,4680,2494,332,7139,2461,3369,1662,2494,0,2665,0,3369,3287,0,2556,623}

    Returns: 23854034

  27. {4323,11664,11664,11664,1900,9408,2134,17756,1900,17238,4323,17756,9408,4698,1900,11664,1900,17238,4698,2134}

    {12294,33960,57350,1216,6100,12294,12294,54992,1216,1216,54992,1216,6100,33960,54992,6100,57350,12294,6100,54992}

    Returns: 610130526

  28. {1265,1992,5502,35649,37845,1992,1992,1265,36900,1392,5502,36900,1392,1392,35649,37845,1992,5502,5502,1392,37845,37845}

    {3120,3120,6257,3120,6720,1169,6303,1169,6720,1169,1169,5590,3120,6720,6257,6303,5590,10982,6720,6257,10982,6257}

    Returns: 237458236

  29. {8222,7120,7637,3234,7120,2058,3664,3234,7120,2898,2058,8888,7441,6215,6872,6872,3664,2898,7441,3664,2898,0,2058,3347,5807,2058,6215,7006,2898,7006,6215,7637,8222,2554,7637,6872,0,3347,7637,5807,2554,7441,7120,7441,8888,6215,6872,3664}

    {4268,7957,2908,6949,5088,6949,8812,4577,6949,4577,5638,4268,4268,6949,4490,3566,4536,7957,3566,4490,1889,4268,9148,9358,9358,9358,4490,7957,9148,8812,9148,5088,9358,9148,4490,2908,7957,5638,4577,8812,4577,1889,4536,7128,2908,7128,8812,2908}

    Returns: 29566829

  30. {3994,9440,1880,3000,2454,3994,7312,5510,7740,5085,7740,336,3994,2314,3000,9440,7740,2454,9440,336,5560,5510,3994,2314,5085,7740,5560,2454,336,336,2454,9440,1880,7312}

    {4356,2270,1218,2270,1218,4563,2270,4563,2376,3954,4563,3954,4386,4386,2376,4563,3159,2201,3159,1218,2376,1218,2270,743,743,1001,4386,2376,2662,4386,1001,2201,2662,4356}

    Returns: 19745069

  31. {66215,7788,29568,88110,7788,29568,88110,64521,64521,66215,66215,66215}

    {629,11214,629,31487,31487,3745,3745,3745,31487,31487,3745,11214}

    Returns: 1884403737

  32. {29281,14899,24357,25648,29281,21242,14899,14899,39636,29281,1768,24357,1768,29281,21242,29440,14899,1768,25648,24357,29440,39636,1768,24357,25648,25648}

    {18900,489,48180,15435,15435,21054,3336,51153,48180,489,51153,15435,18900,3336,51153,18900,21054,15435,51153,489,48180,489,3336,3336,48180,18900}

    Returns: 1394948016

  33. {5152,17834,47005,47005,17834,17834,5152,256,7291,47005,47005,17834,7291,256}

    {32130,34020,32130,38150,38150,3905,3905,3905,32130,3905,34020,32130,38150,38150}

    Returns: 1124368005

  34. {30420,8624,8624,8385,8055,30420,8385,45472,45472,8385,11375,8055,41041,8624,8055,29328,11375,8385,29328,30420,8055,30420,8624,41041}

    {27588,5676,31720,31720,31720,31720,22610,22610,2870,954,2870,12584,5676,27588,18236,22610,18236,35805,5676,954,35805,5676,12584,22610}

    Returns: 579899122

  35. {5337,2199,12906,12690,2199,11162,7542,4191,11162,7542,5337,5337,4434,12906,12906,4191,3946,11162,12690,12690,5337,12906,7542,2199,4191,3946,12690,3946,3946,7542,10184,1672,4434,2343,2199,1672,11162,2343,4191,10184}

    {29951,29951,8030,12075,23373,24070,14287,24070,2002,2002,24070,18528,2002,24070,12075,14287,38045,10325,8030,27456,12075,18528,27456,14287,8547,23373,38045,14287,2002,45520,8030,18528,45520,8030,8547,45520,12075,45520,18528,10325}

    Returns: 212817132

  36. {65645,47336,65645,28294,43340,29486,12667,15015,12667,5453,65645,27540,5453,5453,1218,29486,47336,15179,27540,5453,14084,1275,14084,27540,23680,23680,12667,15015,28294,12667,27540,15179,15015,1275,14084,15179,1275,1218,43340,65645,23680,15179,14084,23680,15015,1275}

    {41650,16592,18560,2046,2046,2697,5306,39347,16324,39347,16592,16592,12384,16072,25276,426,2046,41650,21384,426,426,18560,21384,5306,12384,16592,10353,41650,2697,18560,16324,12384,5306,426,25276,5306,12384,2046,18560,32524,16072,32524,41650,10353,32524,32524}

    Returns: 1083924727

  37. {14900,1378,28152,15048,23274,23274,14900,14900,14900,65241,65241,15048,1378,28152}

    {27683,19045,19045,27683,27683,12378,19045,12378,9984,12378,19045,12378,9984,27683}

    Returns: 446718135

  38. {4976,17112,17112,17680,16121,1755,4976,4277,1755,17112,17112,9786,1755,16121,4277,1755,17680,4976,4277,16121,4277,16121,9786,4976}

    {1284,49010,9228,49010,70152,70152,31410,70152,22140,70152,1284,22140,96,1284,9228,49010,22140,18611,31410,49010,18611,96,1284,22140}

    Returns: 625920457

  39. {6246,28170,6246,28170,28170,1116,28170,54272,6246,1116,54272,6246}

    {26586,26586,16284,2263,16284,16284,3492,16284,3492,3492,3492,2263}

    Returns: 932777196

  40. {69,3428,3369,1576,308,69,1576,9630,69,3417,8592,9873,8592,3417,69,9630,3528,3528,3528,3428,308,308,8592,3528,8592,9873,3428,3369,308,3428}

    {9632,1300,20064,20064,77616,50505,1300,21280,77616,32565,62968,21280,32565,9632,1300,20064,20064,9632,62968,9632,21280,50505,50505,1300,56525,30625,50505,21280,30625,56525}

    Returns: 259193247

  41. {13269,13664,9078,7586,11168,13664,9056,10496,6128,6128,13269,10496,4305,9056,2216,10496,6128,4482,13269,4482,2584,2216,4488,13269,4305,15675,4482,9078,9078,2584,2216,2216,15675,6128,7586,11168,4482,9078,10496,4488}

    {6840,50934,35796,11730,11730,15912,38,50934,15975,24244,50934,11730,6460,0,50934,0,34006,34006,24244,24244,6840,0,11730,9240,34006,38,0,6460,6840,52917,34006,52917,52917,35796,15912,24244,52917,15975,6840,9240}

    Returns: 411549057

  42. {0, 0, 12000, 12000, 14000, 14000, 16000, 16000, 18000, 18000, 20000, 20000, 30000, 30000, 32000, 32000, 34000, 34000, 36000, 36000, 38000, 38000, 40000, 40000, 60000, 60000, 62000, 62000, 64000, 64000, 66000, 66000, 68000, 68000, 70000, 70000, 80000, 80000, 82000, 82000, 84000, 84000, 86000, 86000, 88000, 88000, 90000, 90000, 100000, 100000}

    {0, 12000, 0, 14000, 12000, 16000, 14000, 18000, 16000, 20000, 18000, 30000, 20000, 32000, 30000, 34000, 32000, 36000, 34000, 38000, 36000, 40000, 38000, 60000, 40000, 62000, 60000, 64000, 62000, 66000, 64000, 68000, 66000, 70000, 68000, 80000, 70000, 82000, 80000, 84000, 82000, 86000, 84000, 88000, 86000, 90000, 88000, 100000, 90000, 100000}

    Returns: 920000000

    max test for N*H

  43. {0, 0, 50000, 50000, 50001, 50001, 100000, 100000, 0, 0, 50000, 50000, 50001, 50001, 100000, 100000}

    {0, 50000, 0, 50000, 50001, 100000, 100000, 50001, 50001, 100000, 100000, 50001, 0, 50000, 0, 50000}

    Returns: 9999800001

    one more large area test

  44. {3990,5992,3372,1802,7472,3372,3372,1802,5992,3990,1242,1242,3990,5992,1802,1242,7472,1242,7472,3990,7472,3990,1242,3990,1802,1242,3990,3990,5992,3372,1242,1242}

    {26452,40848,23373,67796,17520,3552,51958,35750,35750,67796,35750,3552,23373,51958,26452,26452,51958,17520,23373,49593,26452,40848,49593,35750,4732,51958,4732,14674,14674,27990,23373,27990}

    Returns: 172672304

    #43-52 are random valid images (more complex)

  45. {4698,58480,2108,59241,58480,11344,58480,4698,2108,2108,58480,58480,58480,11344,58480,59241,59241,4698,4698,58480,59241,4698,2108,4698}

    {7476,9061,2670,6460,4517,6460,6460,4517,9061,4920,9720,2670,0,9720,7476,9720,2670,9720,6460,4920,4517,0,4517,2670}

    Returns: 369845397

  46. {67860,15180,12720,15180,38847,67860,2112,15180,38847,28096,28096,28096,80,28096,15180,12720,28096,12720,28096,12720,12720,15180,80,38847,80,67860,2112,12720,67860,67860,12720,2112,80,15180,38847,2112,67860,15180,15180,12720}

    {2946,7062,9225,3086,9225,13395,13571,880,1612,8222,13571,12236,8222,12155,13571,2090,13395,2946,3444,13395,1612,2946,3444,13395,880,2090,3086,3444,7062,12155,8222,2946,1612,1612,13571,8222,880,3444,12236,880}

    Returns: 474439075

  47. {4736,7712,15572,3900,14715,7712,24700,7712,4736,5717,14715,4736,5717,14715,3900,24700,4736,12288,7712,4824,15572,12288,24700,3900,5717,3900,7712,3900,5717,4736,4736,4824,14715,3900,7712,4736,7712,3900,4824,4736,4824,7712,24700,3900}

    {41548,14320,44103,12650,19328,41548,6648,3492,3553,41548,65730,19328,14320,9290,41548,37741,12650,6648,38415,12650,3553,19328,14320,38415,19328,3492,8928,870,44103,8928,44103,870,37741,14320,37741,870,65730,44103,8928,37741,9290,12650,870,8928}

    Returns: 565084966

  48. {4396,21675,21449,21449,3068,21449,21675,2751,3068,21675,3861,21675,2751,2751,21449,21675,21675,3068,21675,4396,21675,2751,3068,4396,4396,3861,3068,3068}

    {430,2610,7776,430,7361,6222,1978,1978,7776,1748,6952,6222,2610,1748,7361,430,6952,6735,7361,1978,316,430,1978,6735,2610,7361,316,2610}

    Returns: 58397767

  49. {2997,2997,24141,4094,2997,4094,27160,17577,2997,24141,2370,2370,4094,4094,24141,17577,42651,27160,24141,2370,42651,17577,2184,37050,2370,17577,37050,20654,20654,27160,27160,2184}

    {2096,25680,49414,2096,1610,41745,49414,25680,49414,2096,25680,2096,206,1610,1610,41745,49414,26964,25680,206,1610,1610,25680,206,41745,26964,49414,41745,49414,206,25680,1610}

    Returns: 1002044091

  50. {9682,44935,9682,21060,9682,23776,9682,2351,16775,21060,16775,2351,16775,104,18018,23776,16775,104,23776,21060,23776,18018,44935,21060}

    {12360,32809,1318,3975,3975,32809,32809,47793,32809,12360,1318,32809,3975,32809,3975,1318,33160,1318,47793,1318,3975,1318,3975,33160}

    Returns: 1415484306

  51. {10965,3060,2984,10965,2984,3060,21197,2984,10965,10965,98,98,2984,21197}

    {28476,3542,28476,4922,3542,9971,4922,4922,9971,3542,9971,4922,9971,3542}

    Returns: 176868583

  52. {400,400,400,400,274,882,434,434,744,50,848,386,848,400,434,386,274,882,996,459,544,274,400,274,848,386,848,459,996,882,544,996,434,400,400,400,50,882,386,274,848,996,400,274,400,744,400,848}

    {1166,16536,11815,11158,49352,40350,49352,14181,40350,49352,49352,40350,64676,40138,40350,16536,11815,11815,30780,30780,11158,3608,49352,36716,36716,64676,13345,11158,64676,11158,49352,16536,36716,3608,40350,14181,1166,64676,30780,64676,40138,13345,36716,40350,64676,11815,30780,16536}

    Returns: 35896820

  53. {23661,45474,20979,18004,23661,48576,3364,18004,2976,56296,56296,2976,3364,12992,48576,1818,20979,23661,2976,2976,1818,56296,18004,23661,2976,20979,20979,45474,2976,20979,48576,18004,48576,20979,56296,12992,18004,18004}

    {1634,4172,4223,4223,528,1634,3244,3244,4223,4172,1580,3244,4172,3244,4474,1580,3616,4172,2378,4474,2378,4223,4474,1580,3616,4036,528,3244,4036,4474,3244,2378,2378,4172,4474,4474,4172,1580}

    Returns: 112326799

  54. {4324,35025,3760,64703,5148,3760,27324,27729,64703,30720,85457,38720,3640,3640,5148,1992,27324,3640,27324,21204,21204,24955,47064,21204,3640,35025,27324,30720,47064,1992,38720,47064,1992,85457,24955,21204,47064,1992}

    {6684,458,0,458,7632,470,3475,7660,3563,8847,458,2848,470,8847,2483,6684,470,0,7632,2848,8196,0,2848,3475,8196,3563,2627,2684,0,458,7660,2483,2848,2483,8847,2627,8847,470}

    Returns: -1

    #53-66 are random invalid images, generated as valid images without several corners

  55. {30360,343,57,2184}

    {50381,20216,17400,4692}

    Returns: -1

  56. {59}

    {6384}

    Returns: -1

  57. {22796,3380,3380,7560,46922,22796,3380,22796}

    {10106,10106,5047,5047,6716,6716,26040,21242}

    Returns: -1

  58. {5242,1440,1412,986,10355,1412,986,1412,8174,1440,10355,10355,1440,10355,3264,6374,8174,3264,986,5242,10355,6374,986,10355,1440,9834,1412}

    {10701,45252,10701,867,45252,35711,38171,43780,43780,18521,805,10701,38171,38171,35711,7315,45252,805,43780,38171,43780,805,35711,35711,867,45252,18521}

    Returns: -1

  59. {26566,25685}

    {19602,43806}

    Returns: -1

  60. {24495,30576,9142,30576}

    {9163,5060,27522,9163}

    Returns: -1

  61. {4891,2784,5494,2784,7202,5494,2784,5494,43214,2784,43214,24258,5494,43214,33696,4891,4891,2784,24258,7202,43214,4891,33696}

    {9400,2993,6532,18216,23184,9400,9400,34,34,6532,23184,34,23184,37440,23184,34,39330,37440,18216,9400,6532,2993,2993}

    Returns: -1

  62. {723,1632,723,4779,5677,7434,723,723,5677,4779,5677,1632,5677,1632,1088,5677,3031,4212,4779,7434,1632,723,1632,4212,1022,3031,4212,723,5677,7434,1022,4779,7434,1088,4212,3031,4779}

    {6192,1398,1398,1398,16796,10674,28704,145,1398,3531,10674,28704,6192,2640,6274,2640,3531,1398,16796,18984,6274,6274,6192,3531,3531,16796,10674,3531,3531,28704,145,6192,6192,145,16796,6192,18984}

    Returns: -1

  63. {1647,260,1620,19656,1620,1647,21,260,1620,19656,21,9009,21,19656,21,21,21,19656,19656,1620,9009,1620,260}

    {30012,8811,27786,10335,10335,28832,35074,30012,38556,28832,38556,35074,8811,30012,2640,30012,28832,8811,27786,30012,8811,28832,28832}

    Returns: -1

  64. {44555,966,3350,23716,966,23716}

    {2470,6745,4825,26163,2470,2470}

    Returns: -1

  65. {2760,14256,7720,22936,13855,13855,22936,28234,14256,28234,75012,21240,6372,7720,2760,28234,13855,14256,21240,75012,14256,22936,13855,6372,36075,28234,6372,21240,13855,36075,22936,7720,2760,6372,6372,22936,21240,22936}

    {26676,18145,10262,24004,24004,18145,10262,24004,1933,10262,1933,13678,10262,5132,14644,13678,26780,13678,1933,26780,8281,5132,26676,14644,1966,26676,8281,1966,8281,26780,13678,1933,10262,1933,24004,8281,10262,26676}

    Returns: -1

  66. {15275,11918,9565,8316,8316,9565}

    {4266,4266,3072,3072,4266,8584}

    Returns: -1

  67. {7427,5148,7427,7427,8792,5961}

    {26390,7293,6762,15153,24840,10212}

    Returns: -1

  68. {54416,30214,42716,9237,56476,62225,14599,9870,26487,36780,29485,31464,38342,55944,32245}

    {18848,28008,17223,22290,27060,30076,29990,22656,10668,36075,22160,33381,1408,45988,36350}

    Returns: -1

    #67-70 are just random sets of numbers (invalid images).

  69. {29518,2620,10600,32870,7308,38764,14459,39841,27698,5616,7314,37200,40716,10630,44224,37120,40286,28992,67,788,30584,3887,20424,33673,6370,21214,48301,33935,17496,19866,41262,19024,5263,4176,31774,13029}

    {6237,35572,27000,30136,43764,27857,49472,6140,1868,69230,15772,40452,30348,50540,46140,68988,54313,22176,62026,56214,16985,34286,50181,8719,6898,52240,15912,13702,23517,48446,14985,31944,7243,51360,36685,16081}

    Returns: -1

  70. {31785,23628,1204,26827,28367,10373,35409,28190,8692,18402,27346,20085,24674,9536,13081,17653,9282,31202,21829}

    {20321,32730,31448,26011,6954,12500,13974,36527,3843,13353,28416,13680,6516,33810,20541,36540,20294,30234,31845}

    Returns: -1

  71. {7113,13790,12857,10645,9314,10214,7682,13712,2680,10048,10320,3016,1195,5174,9325,9230,11124,12863,812,8514,883,1280,138,5994,5585,5187,14448,7955,9259,8222,9387,12766,914,6074,4867,9670,6482,5652,6759,2848,1398,4115,5189,5472,9695,5702,3676}

    {25434,27150,27705,26279,20511,8150,7507,1567,5171,1540,21758,24152,27007,108,8553,15215,9471,28416,3051,3846,12655,29766,25819,17941,8525,9971,24721,563,456,6387,15813,20142,3555,24392,12962,19142,14389,21579,10514,26850,26121,7723,5928,18659,3726,3678,5522}

    Returns: -1

  72. {4,4,3,0,1,0,4,0,2,2,0,4,3,1}

    {1,2,4,3,4,0,3,2,0,4,1,4,0,0}

    Returns: 8

    ...... .X.X.. ..X.X. .X.X.. ..X.X. ......

  73. {1,1,5,2,0,4,2,3,3,3,0,2,3,4,4,1,5,4,2,1}

    {4,3,0,4,5,2,1,2,1,4,0,3,3,3,1,2,5,4,2,1}

    Returns: 21

    ....... .XXXXX. .X.X.X. .XXXXX. .X.X.X. .XXXXX. .......

  74. {1,6,7,2,4,8,3,9,8,5,7,0,4,2,5,9,3,0,1,6}

    {0,9,0,9,9,0,9,0,9,0,9,0,0,0,9,9,0,9,9,0}

    Returns: 45

    ........... .XXXXXXXXX. ........... .XXXXXXXXX. ........... .XXXXXXXXX. ........... .XXXXXXXXX. ........... .XXXXXXXXX. ...........

  75. {11,0,0,0,0,0,11,0,11,11,11,0,0,0,0,11,0,11,11,0,11,11,11,11}

    {7,8,11,4,1,0,9,5,8,1,6,10,6,3,9,5,7,0,10,2,4,2,3,11}

    Returns: 66

    ............. .X.X.X.X.X.X. .X.X.X.X.X.X. .X.X.X.X.X.X. .X.X.X.X.X.X. .X.X.X.X.X.X. .X.X.X.X.X.X. .X.X.X.X.X.X. .X.X.X.X.X.X. .X.X.X.X.X.X. .X.X.X.X.X.X. .X.X.X.X.X.X. .............

  76. {0,8,2,3,6,8,3,6,0,3,2,5,2,0,5,0,8,3,8,3,5,3,2,8,5,6,5,8,5,2,0,0,6,2,6,6}

    {5,2,3,0,8,5,8,2,6,5,2,2,5,2,6,0,3,3,6,6,8,2,8,0,5,3,0,8,3,6,8,3,6,0,0,5}

    Returns: 36

    .......... .XX.XX.XX. .XX.XX.XX. .......... .XX.XX.XX. .XX.XX.XX. .......... .XX.XX.XX. .XX.XX.XX. ..........

  77. {0,2,0,0,4,1,5,1,5,3,1,1,2,3,0,4}

    {4,3,2,3,3,0,4,2,0,0,1,4,4,3,0,1}

    Returns: 14

    ...... .XX.X. ..XX.. ..XXX. .X..X. .XXXX. ......

  78. {7,7,6,5,5,2,1,0,4,2,6,6,8,1,1,8,0,6,7,0,3,0,3,8,5,4,8,5,6,8,4,3,7,3,0,8,3,1,4,3,0,2,6,3,5,5,0,3,2,0}

    {11,6,9,12,0,4,1,3,3,0,12,8,0,6,9,12,9,5,5,0,10,4,8,3,6,2,5,10,3,4,5,4,12,2,1,8,12,0,0,5,2,2,11,9,8,1,12,1,6,5}

    Returns: 62

    .............. .X.X.X....XXX. ...X.X.XXXXXX. .XXX..XXXXXXX. .X.X.XXXX.X... ..XXX.XXX.X... .XXXX.X...XXX. .XXX.XX..XXX.. .XXX.X...XXXX. ..............

  79. {7,4,2,0,7,4,0,4,1,3,5,5,4,7,6,3,7,1,2,0,6,6,0,6}

    {1,2,4,0,2,1,1,5,6,4,7,6,7,7,1,3,0,4,5,7,2,3,2,4}

    Returns: 36

    ......... .X.XXXXX. .X.XX..X. .X.XXX.X. .X.X.X.X. .XXX.XX.. .XXX.XXX. .X.XXXXX. .........

  80. {0,5,4,7,9,3,10,8,8,3,9,2,0,5,2,6,7,10,8,1,7,9,7,6,8,9,1,2,4,2}

    {4,2,2,4,1,2,3,4,2,4,2,1,3,3,4,0,3,0,0,2,0,4,2,3,3,0,1,0,1,2}

    Returns: 22

    ...... ....X. ..X.X. .XXX.. .XX.X. .X..X. .X.XX. ..X.X. .X.... ..X.X. .XXX.. ......

  81. {8,6,7,11,0,11,9,2,7,9,8,10,0,3,6,2,6,7,9,10,3,3,6,1,3,9,1,7,4,4}

    {0,4,3,1,0,4,3,0,2,2,4,2,4,2,0,3,2,4,4,0,1,4,1,3,3,1,4,0,3,2}

    Returns: 27

    ...... .XXXX. .XXX.. ...... ..X.X. ..XXX. ..XXX. .XX... ....X. .XXX.. .X.XX. ..XXX. ......

  82. {4,0,3,2,1,4,2,3,2,4,3,3,2,1,1,4,4,1,0,1,1,2,0,2,0,3,3,1,1,0,4,0}

    {5,7,10,1,4,11,4,5,2,10,4,0,7,0,2,3,7,9,3,11,5,3,9,8,5,11,8,3,7,1,4,11}

    Returns: 17

    ............. ..XX..XX..XX. .X.XX........ .XXX....X.... ....X.XX...X. .............

  83. {1,3,3,2,1,0,1,2,0,2,2,0,3,0,3,3,0,3,2,2,1,0}

    {0,6,7,4,7,6,3,7,1,5,2,3,0,7,2,3,4,1,0,3,5,0}

    Returns: 10

    ......... .X..X..X. ..XXX.X.. .X.X...X. .........

  84. {1,3,1,0,2,3,3,5,2,0,5,2,1,5,5,3,4,0,1,4,0,2}

    {3,3,5,0,0,1,0,1,3,4,3,2,2,0,5,4,3,3,1,5,1,5}

    Returns: 10

    ....... .X..X.. .XX..X. ....X.. .X..... .X..XX. .......

  85. {8,8,11,13,6,0,6,8,8,5,7,0,0,10,10,5,3,4,13,5,0,9,13,4,7,6,13,9,7,2,5,7,2,3,6,11}

    {10,6,10,13,8,0,7,9,7,7,8,13,10,9,8,6,4,5,3,3,3,7,10,6,5,5,0,8,6,4,4,9,3,5,4,9}

    Returns: 99

    ............... .XXX.......XXX. .XXX.......XXX. .XXXX......XXX. .XXXXX.....XXX. .XXXXXX....XXX. .XXX.XXX...XXX. .XXX..XXX..XXX. .XXX...XXX.XXX. .XXX....XXXXXX. .XXX.....XXXXX. .XXX......XXXX. .XXX.......XXX. .XXX.......XXX. ...............

  86. {0, 0, 1, 2 }

    {0, 2, 3, 4 }

    Returns: -1

  87. {1, 1, 3, 3, 5, 5 }

    {1, 3, 1, 5, 3, 5 }

    Returns: 8

  88. {0, 0, 5, 5 }

    {0, 5, 0, 5 }

    Returns: 25

  89. {1471, 631, 9084, 2900, 7061, 6423, 7637, 3967, 3366, 9326, 6925, 5130, 499, 2475, 120, 3216, 1964, 414, 3737, 8645, 662, 4327, 1387, 826, 5277, 2288, 9633, 433, 4603, 7838, 1087, 6769, 9722, 5619, 6234, 3212, 1590, 3560, 9741, 3407, 2263, 762 }

    {1471, 631, 9084, 2900, 7061, 6423, 7637, 3967, 3366, 9326, 6925, 5130, 499, 2475, 120, 3216, 1964, 414, 3737, 8645, 662, 4327, 1387, 826, 5277, 2288, 9633, 433, 4603, 7838, 1087, 6769, 9722, 5619, 6234, 3212, 1590, 3560, 9741, 3407, 2263, 762 }

    Returns: -1

  90. {66056, 63283, 39516, 39516, 68728, 37315, 15634, 34749, 34749, 39516, 47080, 32661, 15634, 37315, 32661, 37315, 39516, 37315, 63283, 47080, 47080, 37315, 89041, 39516, 47080, 32661, 15634, 15634, 32661, 68728, 32661, 39516, 37315, 89041, 39516, 34749, 66056, 68125, 68125, 15634, 39516, 89041, 32661, 32661, 34749, 34749, 89041, 15634, 34749, 32661 }

    {90244, 23155, 74032, 29259, 62799, 23155, 23155, 62799, 90244, 90244, 29259, 74032, 74032, 90244, 34528, 11949, 34528, 16880, 29259, 16880, 74032, 62799, 90244, 11949, 90244, 16914, 29259, 62799, 16880, 11949, 90244, 16880, 16914, 40291, 62799, 11949, 74032, 62799, 74032, 11949, 23155, 23155, 29259, 23155, 16914, 29259, 16914, 90244, 40291, 11949 }

    Returns: 3234108223

  91. {0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9 }

    {0, 2, 3, 6, 9, 10, 4, 5, 7, 10, 0, 2, 3, 4, 6, 7, 2, 4, 1, 4, 8, 10, 5, 8, 9, 10, 1, 3, 5, 7, 8, 10, 0, 3, 4, 7, 8, 10, 0, 2, 4, 5, 6, 7, 8, 9, 6, 7, 8, 9 }

    Returns: 38

  92. {0, 1, 0, 1, 2, 2, 3, 3, 4, 4, 2, 1, 2 }

    {0, 1, 3, 3, 1, 3, 3, 4, 4, 5, 5, 6, 6 }

    Returns: -1

  93. {0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700, 2800, 2900, 3000, 3100, 3200, 3300, 3400, 3500, 3600, 3700, 3800, 3900, 4000, 4100, 4200, 4300, 4400, 4500, 4600, 4700, 4800, 4900 }

    {100000, 99900, 99800, 99700, 99600, 99500, 99400, 99300, 99200, 99100, 99000, 98900, 98800, 98700, 98600, 98500, 98400, 98300, 98200, 98100, 98000, 97900, 97800, 97700, 97600, 97500, 97400, 97300, 97200, 97100, 97000, 96900, 96800, 96700, 96600, 96500, 96400, 96300, 96200, 96100, 96000, 95900, 95800, 95700, 95600, 95500, 95400, 95300, 95200, 95100 }

    Returns: -1

  94. {1, 1, 3, 3, 5, 5, 99999 }

    {1, 3, 1, 5, 3, 5, 7 }

    Returns: -1

  95. {0, 0, 0, 0, 100000, 100000, 100000, 100000, 123, 123, 123, 123, 99956, 99956, 99956, 99956 }

    {0, 100000, 1234, 23456, 0, 100000, 1234, 23456, 3, 1456, 3567, 100000, 3, 1456, 3567, 100000 }

    Returns: 2021029888

  96. {0, 0, 100000, 100000 }

    {0, 100000, 0, 100000 }

    Returns: 10000000000

  97. {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 100000, 0, 100000 }

    {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 100000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 1, 100000 }

    Returns: 9995300575

  98. {0, 2, 4, 6, 0, 6, 2, 4 }

    {4, 4, 4, 4, 2, 2, 0, 0 }

    Returns: 12

  99. {0, 0, 1, 1 }

    {0, 1, 10, 11 }

    Returns: -1

  100. {10, 10 }

    {100, 1000 }

    Returns: -1

  101. {0, 100000, 0, 100000 }

    {0, 0, 100000, 100000 }

    Returns: 10000000000

  102. {1, 1, 1 }

    {2, 3, 4 }

    Returns: -1


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: