Trapping Rain Water II

Hard

Given an m x n integer matrix heightMap, where each cell is the height of a block in a 2D elevation map, return how many units of water the map can hold after it rains.

Water flows between cells that share an edge (up, down, left, right), not diagonally. It spills off the map at the border, so a cell holds water only if it is walled in on every side. The water above a cell rises to the height of the lowest point it would have to cross to escape off the map.

This is the 2D version of Trapping Rain Water from Week 1.

Examples

Example 1

Input:  heightMap = [[1,4,3,1,3,2],[3,2,1,3,2,4],[2,3,3,2,3,1]]
Output: 4
1 4 3 1 3 2
3 2 1 3 2 4
2 3 3 2 3 1

There are two small ponds in the middle row, both at water level 3. The left pond covers the cells of height 2 and 1 and holds 1 + 2 = 3 units. The right pond covers the single cell of height 2 and holds 1 unit. 3 + 1 = 4.

Example 2

Input:  heightMap = [[3,3,3,3,3],[3,2,2,2,3],[3,2,1,2,3],[3,2,2,2,3],[3,3,3,3,3]]
Output: 10

The border is a wall of height 3 all the way around, so everything inside fills to level 3: eight cells of height 2 hold 1 each, and the center of height 1 holds 2.

Example 3

Input:  heightMap = [[5,5,5],[5,1,5],[5,2,5]]
Output: 1

The wall around the center is mostly 5, but the bottom-middle cell is only 2. Water spills out there, so the center fills only to 2 and holds 2 − 1 = 1.

Example 4

Input:  heightMap = [[5,5,5,5,5],[5,1,1,1,5],[5,1,5,1,5],[5,1,1,1,1],[5,5,5,5,5]]
Output: 0
5 5 5 5 5
5 1 1 1 5
5 1 5 1 5
5 1 1 1 1   <- the border cell on the right is only 1
5 5 5 5 5

The ring of 1s around the middle block connects to the border cell of height 1 on the right, so every drop drains away. Notice that the top-left 1 sees a 5 straight up, down, left and right, yet holds nothing. Water escapes along winding paths, not just straight lines.

Example 5

Input:  heightMap = [[8,8,8,8,8,8,8],[8,2,2,2,2,2,8],[8,2,9,9,9,2,8],[8,2,9,0,9,2,8],[8,2,9,9,9,2,8],[8,2,2,2,2,2,8],[8,8,8,8,8,8,8]]
Output: 105

A lake with an island. The 16 lake cells of height 2 fill to the outer wall's level 8 and hold 6 each, 96 in total. In the middle of the island, the cell of height 0 is walled in by 9s, which are higher than the lake, so it fills all the way to 9. 96 + 9 = 105. Ponds in the same map can sit at different levels.

Constraints

  • m == heightMap.length
  • n == heightMap[i].length
  • 1 <= m, n <= 200
  • 0 <= heightMap[i][j] <= 2 * 10^4
TypeScript
Loading editor…
Test cases33
Case 1
heightMap = [[1,4,3,1,3,2],[3,2,1,3,2,4],[2,3,3,2,3,1]]
Case 2
heightMap = [[3,3,3,3,3],[3,2,2,2,3],[3,2,1,2,3],[3,2,2,2,3],[3,3,3,3,3]]
Case 3
heightMap = [[5,5,5],[5,1,5],[5,5,5]]
Case 4
heightMap = [[5,5,5],[5,1,5],[5,2,5]]
Case 5
heightMap = [[5,5,5,5,5],[5,1,1,1,5],[5,1,5,1,5],[5,1,1,1,1],[5,5,5,5,5]]
Case 6
heightMap = [[7]]
Case 7
heightMap = [[1,2,3,4]]
Case 8
heightMap = [[1],[2],[3]]
Case 9
heightMap = [[3,3],[3,3]]
Case 10
heightMap = [[9,9,9],[9,0,9]]
Case 11
heightMap = [[2,2,2],[2,1,2],[2,2,2],[2,1,2],[2,2,2]]
Case 12
heightMap = [[1,1,1],[1,5,1],[1,1,1]]
Case 13
heightMap = [[12,13,1,12],[13,4,13,12],[13,8,10,12],[12,13,12,12],[13,13,13,13]]
Case 14
heightMap = [[5,8,7,7],[5,2,1,5],[7,1,7,1],[8,9,6,9],[9,8,9,9]]
Case 15
heightMap = [[14,17,18,16,14,16],[17,3,10,2,3,8],[11,10,4,7,1,7],[13,7,2,9,8,10],[13,1,3,4,8,6],[20,3,3,9,10,8]]
Case 16
heightMap = [[9,9,9,9,9,9,8,9,9,9,9],[9,0,0,0,0,0,1,0,0,0,9],[9,0,0,0,0,0,0,0,0,0,9],[9,0,0,0,0,0,0,0,0,0,9],[9,9,9,9,9,9,9,9,9,9,9]]
Case 17
heightMap = [[6,6,6,6,6,3,3,3,3],[6,1,1,1,6,3,0,0,3],[6,1,1,1,6,3,0,0,3],[6,6,6,6,6,3,3,3,3]]
Case 18
heightMap = [[8,8,8,8,8,8,8],[8,2,2,2,2,2,8],[8,2,9,9,9,2,8],[8,2,9,0,9,2,8],[8,2,9,9,9,2,8],[8,2,2,2,2,2,8],[8,8,8,8,8,8,8]]
Case 19
heightMap = [[8,8,8,8,8,8,8],[8,2,2,2,2,2,8],[8,2,9,9,9,2,8],[8,2,9,0,3,2,8],[8,2,9,9,9,2,8],[8,2,2,2,2,2,8],[8,8,8,8,8,8,8]]
Case 20
heightMap = [[20000,20000,20000],[20000,0,20000],[20000,20000,20000]]
Case 21
heightMap = [[9,4,9,9,9,9,9,9,9],[9,0,0,0,0,0,0,0,9],[9,9,9,0,9,9,9,0,9],[9,0,9,0,0,0,9,0,9],[9,0,9,9,9,0,9,0,9],[9,0,9,0,0,0,9,0,9],[9,0,9,9,9,9,9,0,9],[9,0,0,0,0,0,0,0,9],[9,9,9,9,9,9,9,9,9]]
Case 22
heightMap = [[7,1,7,7,7,7,7,7,7,7,7,7,7,7,7],[7,1,1,1,1,1,1,1,1,1,1,1,1,1,7],[7,7,7,1,7,7,7,7,7,7,7,7,7,1,7],[7,1,7,1,1,1,1,1,1,1,1,1,7,1,7],[7,1,7,7,7,1,7,7,7,7,7,1,7,1,7],[7,1,7,1,7,1,1,1,1,1,7,1,7,1,7],[7,1,7,1,7,7,7,1,7,1,7,1,7,1,7],[7,1,7,1,7,1,7,1,7,1,7,1,7,1,7],[7,1,7,1,7,1,7,7,7,1,7,1,7,1,7],[7,1,7,1,7,1,1,1,1,1,7,1,7,1,7],[7,1,7,1,7,7,7,7,7,7,7,1,7,1,7],[7,1,7,1,1,1,1,1,1,1,1,1,7,1,7],[7,1,7,7,7,7,7,7,7,7,7,7,7,1,7],[7,1,1,1,1,1,1,1,1,1,1,1,1,1,7],[7,7,7,7,7,7,7,7,7,7,7,7,7,7,7]]
Case 23
heightMap = [[20000,12000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000],[20000,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,20000],[20000,20000,20000,3,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,3,20000],[20000,3,20000,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,20000,3,20000],[20000,3,20000,20000,20000,3,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,3,20000,3,20000],[20000,3,20000,3,20000,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,20000,3,20000,3,20000],[20000,3,20000,3,20000,20000,20000,3,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,3,20000,3,20000,3,20000],[20000,3,20000,3,20000,3,20000,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,20000,3,20000,3,20000,3,20000],[20000,3,20000,3,20000,3,20000,20000,20000,3,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,3,20000,3,20000,3,20000,3,20000],[20000,3,20000,3,20000,3,20000,3,20000,3,3,3,3,3,3,3,3,3,3,3,3,3,20000,3,20000,3,20000,3,20000,3,20000],[20000,3,20000,3,20000,3,20000,3,20000,20000,20000,3,20000,20000,20000,20000,20000,20000,20000,20000,20000,3,20000,3,20000,3,20000,3,20000,3,20000],[20000,3,20000,3,20000,3,20000,3,20000,3,20000,3,3,3,3,3,3,3,3,3,20000,3,20000,3,20000,3,20000,3,20000,3,20000],[20000,3,20000,3,20000,3,20000,3,20000,3,20000,20000,20000,3,20000,20000,20000,20000,20000,3,20000,3,20000,3,20000,3,20000,3,20000,3,20000],[20000,3,20000,3,20000,3,20000,3,20000,3,20000,3,20000,3,3,3,3,3,20000,3,20000,3,20000,3,20000,3,20000,3,20000,3,20000],[20000,3,20000,3,20000,3,20000,3,20000,3,20000,3,20000,20000,20000,3,20000,3,20000,3,20000,3,20000,3,20000,3,20000,3,20000,3,20000],[20000,3,20000,3,20000,3,20000,3,20000,3,20000,3,20000,3,20000,3,20000,3,20000,3,20000,3,20000,3,20000,3,20000,3,20000,3,20000],[20000,3,20000,3,20000,3,20000,3,20000,3,20000,3,20000,3,20000,20000,20000,3,20000,3,20000,3,20000,3,20000,3,20000,3,20000,3,20000],[20000,3,20000,3,20000,3,20000,3,20000,3,20000,3,20000,3,3,3,3,3,20000,3,20000,3,20000,3,20000,3,20000,3,20000,3,20000],[20000,3,20000,3,20000,3,20000,3,20000,3,20000,3,20000,20000,20000,20000,20000,20000,20000,3,20000,3,20000,3,20000,3,20000,3,20000,3,20000],[20000,3,20000,3,20000,3,20000,3,20000,3,20000,3,3,3,3,3,3,3,3,3,20000,3,20000,3,20000,3,20000,3,20000,3,20000],[20000,3,20000,3,20000,3,20000,3,20000,3,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,3,20000,3,20000,3,20000,3,20000,3,20000],[20000,3,20000,3,20000,3,20000,3,20000,3,3,3,3,3,3,3,3,3,3,3,3,3,20000,3,20000,3,20000,3,20000,3,20000],[20000,3,20000,3,20000,3,20000,3,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,3,20000,3,20000,3,20000,3,20000],[20000,3,20000,3,20000,3,20000,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,20000,3,20000,3,20000,3,20000],[20000,3,20000,3,20000,3,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,3,20000,3,20000,3,20000],[20000,3,20000,3,20000,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,20000,3,20000,3,20000],[20000,3,20000,3,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,3,20000,3,20000],[20000,3,20000,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,20000,3,20000],[20000,3,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,3,20000],[20000,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,20000],[20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000,20000]]
Case 24
heightMap = [[2,2,8],[7,2,8],[0,7,6]]
Case 25
heightMap = [[1,6,2,8,1,4,5],[4,6,1,4,2,1,3],[9,0,7,2,8,0,7],[6,6,4,5,5,4,2]]
Case 26
heightMap = [[16,3,2,10,12,17],[0,13,2,13,4,5],[5,19,6,17,2,17],[17,14,12,16,17,10],[8,1,6,3,19,4],[9,18,18,2,18,15]]
Case 27
heightMap = [[62,50,66,15,72],[8,1,43,51,46],[42,9,70,99,15],[33,39,40,36,18],[21,66,16,30,31],[42,11,57,85,13],[28,43,48,23,33],[26,12,100,89,58]]
Case 28
heightMap = [[2,8,6,5,8,7,5,2,8,7,9,7],[1,7,6,4,3,1,6,4,3,3,6,0],[7,2,6,9,9,9,2,4,5,1,7,8],[5,5,2,9,0,1,3,0,7,6,6,5],[1,2,3,5,7,4,1,5,5,0,0,0],[5,6,9,6,4,0,5,4,8,8,3,6],[5,9,3,4,2,8,6,1,3,0,7,4],[2,6,6,9,9,6,1,3,5,2,6,1],[4,1,4,1,7,4,6,5,2,8,4,1],[4,4,3,1,2,1,5,6,4,1,7,4]]
Case 29
heightMap = [[27,3,20,39,41,17,35,43,9,33,45,5,4,3,32,44,40,31,28,23],[24,30,5,3,29,2,21,34,43,18,27,40,50,17,2,37,9,9,50,41],[10,43,43,33,38,7,34,30,42,42,26,18,9,17,2,16,34,14,38,21],[12,39,41,24,10,30,5,39,49,20,42,7,6,43,0,15,48,6,37,9],[27,34,21,6,15,4,50,10,16,38,8,10,33,48,21,8,18,48,15,8],[9,44,4,47,33,1,19,43,13,3,13,15,16,8,38,31,15,30,46,49],[25,47,31,36,37,13,49,31,22,11,5,35,47,28,35,4,32,43,10,5],[29,26,46,22,5,38,14,34,43,18,28,13,36,25,50,20,6,19,29,15],[11,26,48,27,40,50,29,27,50,50,15,9,29,47,4,12,32,22,4,5],[35,5,9,32,20,32,9,9,13,7,20,44,32,25,35,28,37,39,0,12],[4,15,7,21,29,45,37,27,24,17,37,27,43,13,9,27,2,32,11,14],[50,9,5,3,32,28,37,11,43,50,45,49,34,0,5,26,35,40,34,5],[3,7,5,3,42,43,2,32,38,1,44,12,49,0,23,43,15,25,9,49],[31,0,46,5,23,24,19,36,14,28,14,6,21,14,8,21,3,18,47,1],[37,31,49,20,22,0,32,35,43,43,35,14,12,36,20,26,14,3,43,2],[50,35,4,41,50,34,10,46,5,7,28,6,47,25,30,8,14,41,6,39],[8,27,47,26,7,20,19,0,23,1,1,32,1,19,8,27,37,40,1,28],[35,11,9,47,21,43,3,5,48,2,24,45,10,36,25,41,47,47,25,12],[22,47,4,13,4,33,43,24,36,19,44,46,46,7,2,39,8,36,35,42],[36,5,29,38,0,48,41,5,40,24,29,9,50,45,49,0,16,40,3,32]]
Case 30
heightMap = [[12400,7649,11671,15990,1561,16997,6278,1575,3468,11156,11917,12191,15125,3072,17634,10316,6125,15877,14439,15696,6978,5373,11306,2594,19335],[16804,13499,18187,16537,10758,4106,19619,17104,6890,9326,4429,17045,9406,10253,18293,13466,4416,11332,9558,13500,15785,12031,13259,54,2048],[5093,7582,18893,15873,13202,10823,6239,8352,11809,5296,9003,4944,14879,19160,12716,9719,9357,10748,17299,12606,18047,15445,14571,16625,5929],[4898,19142,12279,14880,3519,5512,12586,11955,11322,12869,5556,10181,13135,4391,18827,12859,12954,12551,13604,15258,19121,17580,17181,7042,15141],[14484,7248,11034,230,14644,4985,14438,2972,4875,13380,13179,747,3111,7921,15160,11159,13474,2734,856,19119,10436,10260,1299,13688,18013],[287,5560,14229,4819,10304,6381,5574,2523,17559,13372,16395,13877,17656,19385,9023,11103,7837,8274,11428,16060,15555,2718,18120,12058,5893],[6250,16312,5022,7848,14516,7461,19349,829,9344,11286,9866,12232,18724,9275,12826,974,12443,8479,6823,12806,17843,8526,18811,1667,7794],[11699,14112,5294,6088,1244,14338,15919,4486,8057,1993,10786,6805,10036,9198,15152,9263,4882,13391,6571,12903,10536,10624,6052,13103,7645],[1203,16532,989,17830,13832,1339,1006,4195,5650,13278,16732,2667,10158,12706,11747,401,12994,17865,12397,17649,16683,2927,2688,16684,18197],[17948,7331,15777,2025,1071,16863,17056,14757,13094,1433,1454,7984,1155,15689,1918,14593,2229,18618,17667,17734,14035,11369,1589,7803,3613],[10001,9488,12273,18088,12770,17998,16359,7292,18909,7630,2253,7605,17759,7758,1582,4249,14137,12525,14589,12596,1833,1885,15763,14977,5316],[1195,14796,16811,4329,5446,17289,6838,17743,751,4029,16936,5466,7156,12519,4662,18607,1717,4706,2762,9862,5040,8225,15244,16222,19891],[1397,7675,9500,5490,4769,3795,12467,16955,18494,9021,7350,4994,4403,12289,8591,9811,16575,6173,7025,8150,18847,15710,10733,12878,9092],[13263,18699,14259,564,8807,19937,13174,16567,7540,3508,722,10069,9289,4162,4857,4837,3500,14951,9813,997,15867,4009,13555,11573,13392],[9453,5860,18826,11867,19125,7253,220,12915,17729,12941,17002,16906,2475,13225,19214,1269,6546,5464,7176,15834,7031,16728,14918,12816,1493],[13643,9730,18972,243,17170,9889,14734,5304,18096,8928,1833,9476,18537,10414,15560,9574,10003,9300,7162,3633,17555,14827,13939,17458,3002],[11866,268,12702,12057,7622,11507,9687,14326,18718,18309,5155,11850,6904,3700,3275,10644,19485,13740,11795,39,15937,18959,8546,1878,16429],[2768,13289,9850,4282,16655,3413,3209,243,2077,696,11093,13972,1274,3272,4429,17878,6171,14047,14642,1664,1913,18998,175,7850,8897],[11924,18269,10864,2762,15580,14232,4194,1614,2293,7871,4827,18730,12203,8803,11384,1397,14256,17985,5011,1625,17743,14480,10619,3655,7692],[18645,15898,9770,5045,7228,16038,11089,16563,7687,11692,2210,15902,7358,14148,11529,6518,10879,17724,16933,6695,1048,19807,191,10537,8956],[7510,9888,15940,7401,18826,10420,8037,5453,5436,5187,1475,19629,3773,8668,10975,5510,17790,6268,6404,3829,4318,19493,14459,7602,576],[6250,16245,18728,14461,8144,8540,3302,5961,18244,7395,10399,14697,11894,95,12050,10105,11589,3910,4072,7022,10322,6030,18871,16142,4218],[6059,13905,3257,4159,9532,16526,16240,2521,13259,14112,14175,9,450,7604,16832,11572,5234,15886,17177,19498,13794,4852,17893,12892,17919],[5962,11141,4331,17014,10486,12403,9887,9722,129,5818,4168,9132,6434,2736,7461,8121,11882,15399,18367,13158,8147,6811,4672,7299,16580],[19860,6042,9385,15736,1426,10162,13952,13006,4956,4065,18149,14012,14263,13871,12530,6999,18792,2192,18123,15158,13731,14211,19471,6063,15729],[18555,3320,7352,13998,1447,7683,17610,8608,12288,17159,6056,15756,18704,7692,9378,486,18089,18939,11303,9307,6125,12694,6832,6815,14774],[8852,11028,13071,960,9104,8296,17826,9923,11010,5924,15832,11512,7520,17827,10485,10357,7920,17408,19581,9206,9804,9353,17964,7881,7829],[3690,12064,2087,6979,2005,15321,2759,5065,15322,4295,6847,13422,5568,11897,3596,5282,15855,9156,4528,14262,11920,14071,16653,6422,14161],[13361,13665,2975,3291,9047,10601,19390,4537,255,12491,18932,9552,8270,5284,7134,4345,5953,9364,19642,8082,8821,13942,14908,4668,14234],[16372,4281,3751,3447,17792,12888,13693,18916,2126,12638,12181,11011,352,15311,1164,13134,19910,16107,17831,5627,5910,12899,4714,11838,2848]]
Case 31
heightMap = [[0,9,9,6,1,4,2,7,2,0,4,9,8,7,8,1,0,3,9,5,3,5,1,5,0,5,1,7,5,9,5,2,2,5,9,0,6,3,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,3,4,4,1,4,9,3,9,8,0,4,3,5,0,8,6,8,6,6,5,8,8,1,7,6,9,8,3,3,8,1,7,4,9],[4,7,5,3,7,4,8,8,1,3,3,3,1,8,8,4,6,0,2,4,8,2,7,4,8,1,5,6,4,6,6,5,2,9,6,7,7,0,5,8,3,1,5,4,0,6,8,6,1,7],[8,9,2,5,2,5,7,4,2,4,6,8,7,1,4,4,7,8,7,5,4,7,0,6,6,8,2,4,5,5,3,1,3,0,5,2,8,7,1,3,2,9,0,1,8,8,0,5,5,4],[1,7,3,4,9,3,6,6,9,5,1,9,2,8,7,0,5,7,9,7,6,6,0,1,3,2,4,7,3,1,8,4,1,9,7,6,6,3,9,6,2,3,7,1,3,3,8,9,1,3],[9,8,9,2,6,2,7,0,2,6,4,1,3,5,0,4,8,2,8,9,9,3,4,5,0,9,1,6,8,3,6,7,4,1,2,7,1,6,3,0,9,2,5,3,3,5,7,0,3,5],[9,7,5,6,4,7,5,8,8,1,4,2,0,6,8,0,1,8,1,0,6,9,6,3,5,8,6,8,3,0,6,0,5,8,8,5,7,4,1,1,6,8,2,7,8,8,7,9,6,6],[2,4,9,1,3,3,4,5,5,8,2,6,8,4,8,3,4,9,0,3,2,1,1,0,6,9,5,7,5,1,2,6,7,8,2,0,0,7,2,5,0,0,5,8,7,6,5,6,3,4],[3,1,6,1,2,6,6,2,8,4,7,6,1,7,2,6,7,5,1,5,0,4,1,1,6,0,9,1,2,8,2,9,0,5,7,3,1,3,2,6,7,9,0,1,7,1,6,1,7,6],[8,1,6,8,6,8,4,7,3,2,3,2,9,8,8,8,6,9,5,7,9,6,4,1,8,1,3,0,7,4,1,4,9,3,2,6,6,5,1,0,1,1,8,2,0,5,5,4,0,8]]
Case 32
heightMap = [[579,702,691,606,444,663,123,930,117,390,723,729,320,202,144,582,342,964,128,745,251,265,274,855,94,496,731,336,67,310,541,753,347,634,65,150,515,777,201,324,324,771,98,151,762,582,732,363,72,725,777,433,781,829,846,441,514,24,407,466],[611,400,594,162,313,810,756,128,768,786,722,905,533,125,209,761,768,811,833,839,720,537,444,469,318,122,736,384,299,352,689,578,476,30,393,829,522,841,582,131,723,656,523,232,104,792,368,785,466,710,661,933,570,625,790,753,726,200,977,965],[829,132,647,868,357,431,5,617,540,901,152,499,394,483,950,8,449,781,734,404,23,544,871,182,391,801,807,1000,812,491,322,192,470,626,408,880,382,44,98,816,78,931,199,375,876,757,325,727,861,128,837,191,396,806,878,315,647,339,589,357],[718,442,112,620,881,620,128,527,31,282,648,221,900,529,475,801,118,911,711,515,41,881,746,404,507,588,146,813,815,515,24,540,969,371,475,255,722,303,564,389,74,1000,640,503,55,7,218,441,587,629,183,893,328,735,214,580,320,955,698,610],[616,671,261,533,457,774,60,51,613,10,97,350,341,58,493,802,657,407,798,616,143,733,33,757,433,974,980,850,922,836,738,706,816,897,553,879,242,902,799,123,303,556,405,700,79,963,734,246,48,26,544,742,807,549,89,734,890,86,317,820],[393,554,201,926,66,699,96,296,609,438,546,952,565,91,632,664,672,351,211,692,489,976,287,96,308,76,597,829,602,36,912,110,140,770,996,785,623,975,869,434,354,686,249,373,831,534,330,150,927,643,195,299,747,134,434,659,244,657,84,683],[619,218,277,755,755,941,164,444,523,178,394,232,720,862,117,79,686,190,112,333,180,385,167,287,199,478,884,793,213,770,360,41,531,670,697,904,392,608,566,647,831,127,200,817,808,287,468,600,197,701,305,762,675,445,776,835,71,37,4,524],[406,785,244,464,23,672,258,24,430,116,189,935,637,3,627,576,155,179,998,494,988,636,393,318,236,547,787,560,694,400,357,7,344,238,565,231,946,79,933,649,615,340,438,26,616,535,950,935,328,336,577,126,765,41,999,570,917,776,956,258],[646,484,903,882,849,305,232,1,737,439,489,89,252,378,298,594,82,481,342,455,526,83,691,682,90,478,899,56,178,575,105,684,188,648,42,104,291,170,866,303,38,964,683,495,549,428,168,630,342,221,739,421,432,678,479,362,871,299,478,443],[930,294,225,134,395,722,77,605,738,479,320,351,518,925,721,905,882,414,941,781,100,134,105,95,70,511,792,139,36,394,844,611,101,160,854,11,137,582,812,44,666,842,976,326,657,696,978,126,761,448,849,440,110,31,145,374,850,648,838,98],[852,591,452,244,222,451,61,113,190,446,671,574,213,13,271,816,122,114,603,806,260,620,744,163,666,371,632,55,584,544,984,589,251,808,236,927,411,28,384,888,829,116,26,756,723,773,140,127,990,662,289,662,582,715,764,685,212,134,123,29],[631,821,328,822,420,346,475,195,404,31,771,80,939,720,324,948,8,76,755,935,835,443,347,591,760,448,973,844,393,396,70,148,263,184,33,348,836,478,682,448,708,983,933,422,760,497,118,996,871,185,123,272,484,110,788,24,535,877,61,455],[988,657,375,3,606,264,871,849,41,42,148,251,324,955,621,190,664,116,141,466,744,208,930,485,481,783,697,817,402,500,43,429,607,186,522,773,469,142,605,630,194,315,367,142,442,672,317,755,707,256,722,450,126,110,162,644,568,677,9,272],[252,30,505,826,524,45,219,78,287,653,436,810,683,226,611,999,347,517,214,599,24,862,816,464,220,937,211,100,93,867,468,481,189,803,36,588,473,86,287,138,371,439,387,339,877,108,107,696,112,105,431,598,134,516,908,739,967,853,565,322],[840,178,757,315,355,294,312,186,48,936,588,328,901,632,564,446,30,478,539,970,939,82,469,396,12,147,986,945,163,328,352,166,453,509,840,85,93,808,15,155,271,344,491,45,427,3,13,160,70,72,948,205,595,1000,440,283,424,631,488,771],[226,693,125,749,738,476,257,49,845,697,465,345,390,933,281,921,1,313,963,53,87,967,819,162,259,48,223,493,464,888,311,665,518,735,716,426,476,725,4,576,728,537,295,295,945,432,278,761,414,170,343,362,143,722,180,891,365,55,556,753],[698,76,432,258,935,24,591,78,484,158,232,318,380,618,848,566,818,427,561,782,50,388,551,325,328,249,195,864,677,451,515,57,914,177,381,397,633,934,125,893,721,713,768,285,228,381,330,370,109,142,11,565,675,561,398,311,549,212,575,296],[388,94,637,268,857,460,358,63,206,376,204,1,804,913,113,642,667,635,975,149,786,949,853,401,262,623,254,479,148,594,348,541,440,105,552,479,34,561,852,334,379,331,85,899,998,375,936,151,409,694,852,492,388,351,226,696,853,444,337,474],[42,597,99,349,563,480,964,542,347,109,588,221,898,236,475,452,30,577,843,959,347,880,677,2,987,245,309,35,769,372,849,304,498,664,917,342,584,958,328,624,972,636,643,834,393,554,23,959,850,984,809,191,692,148,939,946,366,330,349,989],[217,393,57,607,725,646,228,666,339,652,429,715,544,514,668,241,530,165,419,750,160,407,787,242,86,745,56,516,798,978,233,932,719,193,936,900,240,607,1000,419,67,155,344,594,808,394,650,949,945,311,861,143,47,8,486,717,377,688,701,135],[185,806,311,16,364,502,666,295,444,577,35,679,959,803,633,913,518,289,600,474,713,466,437,145,215,184,340,564,278,532,277,432,504,812,678,942,86,997,979,421,498,31,413,660,64,835,857,229,687,33,693,620,912,553,932,181,245,822,828,819],[263,788,602,240,930,76,591,495,115,195,519,268,106,326,307,514,133,642,467,233,623,581,588,961,858,756,353,286,808,631,701,60,67,33,369,838,275,709,660,491,179,476,614,542,661,515,996,95,894,26,704,38,747,703,568,772,812,673,504,706],[874,211,560,434,947,84,310,288,232,557,966,427,947,834,381,860,837,519,615,968,421,424,811,509,345,504,757,936,688,408,218,822,408,642,990,486,279,553,729,13,570,632,691,839,722,552,45,575,319,631,639,439,408,821,423,827,946,76,83,909],[72,509,373,288,388,701,426,257,733,700,827,228,415,539,12,871,740,775,929,83,948,75,555,349,581,709,726,508,85,655,49,553,311,36,876,355,1,574,342,648,402,489,451,120,766,232,601,48,538,840,371,9,974,484,45,441,243,887,165,83],[844,926,189,650,13,105,24,179,210,388,531,154,841,514,32,353,651,755,632,612,101,874,836,230,38,665,46,674,232,675,432,96,484,323,13,2,35,571,727,881,798,750,982,567,512,372,444,422,451,297,328,422,194,724,62,174,722,864,574,787],[400,762,788,984,109,958,799,638,785,513,270,458,442,503,30,228,883,764,49,582,301,731,690,890,767,87,864,421,127,447,327,924,878,130,149,580,415,816,34,444,599,554,316,442,198,265,193,113,800,62,980,616,771,375,316,581,834,916,116,765],[672,87,273,777,291,399,302,983,61,117,14,662,904,339,293,334,785,284,969,724,910,391,31,31,422,198,808,751,332,121,98,877,584,389,827,432,21,694,353,851,661,760,106,446,689,757,85,111,91,808,144,887,681,44,1,248,440,501,973,282],[809,352,320,57,276,365,461,525,344,257,134,760,939,195,996,609,322,670,957,112,622,80,726,685,639,408,123,512,946,625,216,866,289,140,790,790,954,810,491,484,134,97,403,890,995,660,15,130,321,811,42,923,145,117,562,570,67,854,749,382],[456,596,780,989,775,941,842,542,266,988,667,201,703,643,994,912,781,772,151,65,499,114,911,144,11,39,44,853,344,137,997,874,328,102,932,263,906,233,344,483,619,844,478,16,68,87,637,379,186,480,280,9,744,111,392,431,108,586,321,896],[784,970,620,786,176,430,747,751,864,715,117,470,92,471,602,531,498,304,221,909,998,583,516,916,162,4,237,452,874,960,71,718,769,821,261,680,482,993,261,570,129,137,132,216,778,143,604,859,734,871,263,221,735,142,69,578,31,696,994,577],[826,356,857,660,105,773,115,905,180,341,408,648,219,305,276,895,22,145,60,390,419,803,971,33,713,474,721,600,480,607,20,187,910,32,563,230,113,357,105,564,732,75,209,404,587,323,408,865,650,177,827,803,169,374,893,966,676,426,812,445],[416,584,509,407,179,686,138,260,331,482,137,222,511,961,558,355,580,332,517,758,329,530,342,697,930,258,420,193,458,430,472,925,603,794,411,979,784,279,421,276,84,119,416,673,471,257,586,5,74,460,665,393,155,339,516,925,485,724,0,800],[467,397,324,971,757,815,939,863,190,74,667,95,731,253,497,914,842,845,21,958,991,387,772,5,14,236,790,537,282,797,800,900,355,383,699,669,443,400,910,975,737,724,187,353,763,352,135,930,602,88,933,203,115,596,250,896,891,455,702,466],[90,627,366,817,551,880,838,700,617,379,618,742,287,404,474,73,23,958,320,830,436,826,174,594,643,621,533,423,900,275,964,116,528,629,946,466,449,729,77,854,410,8,572,891,519,998,539,949,673,672,218,103,466,207,138,557,418,174,631,479],[310,693,633,104,740,690,472,737,835,50,896,380,433,213,422,768,873,807,184,799,777,461,662,4,139,74,36,499,102,528,219,366,14,400,906,43,906,294,73,110,61,361,929,671,716,121,591,120,243,714,728,805,314,559,15,521,833,842,651,951],[795,400,533,892,632,370,364,185,118,102,704,772,488,631,716,919,995,851,823,940,473,409,408,950,467,90,111,1000,615,925,895,814,958,968,725,91,761,945,39,577,564,940,909,305,320,331,274,232,832,281,359,726,476,885,414,58,814,736,638,854],[643,160,53,813,57,948,423,183,80,434,699,931,691,747,331,925,756,863,345,695,445,202,798,894,309,265,458,340,839,373,465,713,720,318,105,74,385,508,971,922,38,177,125,537,64,270,517,899,932,561,356,13,118,995,297,190,942,486,44,949],[552,110,334,415,278,8,647,896,523,945,136,505,670,285,332,554,789,408,89,796,142,527,97,972,401,685,471,401,669,179,862,926,932,299,872,331,766,528,775,834,35,923,12,610,833,860,765,50,214,601,967,388,468,714,688,505,202,505,808,399],[435,759,253,237,741,854,21,28,76,641,474,593,10,123,678,417,557,181,690,460,575,526,399,376,516,209,615,739,994,249,449,340,118,967,553,204,351,496,739,805,705,482,654,464,785,800,934,238,589,938,166,367,504,591,433,613,796,833,418,401],[308,174,616,691,773,531,634,859,860,988,700,88,163,897,421,64,678,449,110,993,966,130,453,859,442,327,682,976,108,184,243,532,887,746,473,493,220,373,308,270,336,410,182,276,925,335,527,615,443,362,625,423,830,641,689,217,144,430,832,91],[421,932,262,723,140,400,440,86,758,415,467,31,892,553,657,135,672,780,456,324,755,575,582,2,669,618,422,617,813,852,793,466,730,714,581,926,198,78,851,933,901,462,743,868,173,260,486,847,602,131,194,777,696,901,941,226,388,150,582,984],[956,254,665,572,378,875,844,657,805,203,691,430,897,258,531,475,425,149,247,751,736,743,20,636,680,505,22,442,971,265,885,50,812,349,767,100,431,766,332,416,850,761,216,399,422,768,806,832,440,330,183,370,518,0,515,969,885,579,450,838],[293,286,277,109,656,587,142,461,799,782,284,202,763,488,806,3,871,531,613,571,493,671,808,271,190,544,810,135,568,664,274,165,419,275,66,568,137,778,389,404,618,119,217,489,760,123,784,470,756,450,115,762,26,437,514,973,936,613,276,550],[232,678,681,748,584,994,352,822,505,478,658,188,195,155,437,920,70,435,211,921,189,981,207,963,830,273,553,3,804,783,497,886,762,420,939,822,386,313,264,467,767,895,824,931,377,189,476,153,612,958,281,118,799,690,533,221,865,783,235,313],[918,113,269,200,743,125,974,647,813,197,34,361,154,670,659,529,596,357,544,705,299,456,222,921,176,105,333,769,231,551,706,524,937,657,184,210,661,881,747,36,466,761,1000,821,763,904,575,403,105,783,463,499,342,642,584,316,490,931,778,167]]
Case 33
heightMap = [[43,37,41,42,41,41,37,40,39,38,37,41,39,41,42,43,41,39,37,37,43,37,41,42,39,42,40,37,43,41,37,38,39,43,40,37,43,42,41,37],[38,38,41,41,36,39,38,41,36,39,40,39,38,39,35,41,39,41,36,39,38,38,35,38,36,38,36,41,35,38,36,36,39,35,39,35,38,41,36,38],[38,40,38,39,36,38,39,34,36,35,35,35,37,35,33,34,39,33,33,38,36,34,34,34,35,35,38,38,37,36,38,38,39,38,39,34,39,38,36,36],[42,38,38,33,33,36,34,33,33,31,36,32,33,36,35,33,32,35,34,32,33,32,34,31,35,34,33,35,34,37,35,31,33,36,36,32,37,31,36,35],[41,38,39,33,30,29,30,34,32,32,33,29,35,30,35,30,34,32,33,32,31,35,32,29,30,31,33,29,34,35,30,30,32,34,29,30,34,31,38,40],[37,35,35,32,29,28,30,28,31,31,30,32,30,33,32,28,32,33,30,31,28,33,27,31,29,28,30,31,32,30,32,28,30,32,32,33,29,36,34,35],[38,39,34,32,32,33,28,31,27,25,31,28,27,30,30,31,31,29,30,27,25,29,31,26,31,27,31,28,26,25,31,25,27,26,30,33,31,33,33,36],[42,37,34,35,30,33,25,25,28,25,24,26,28,28,29,24,26,26,28,24,23,29,27,28,25,28,23,25,27,24,29,24,25,29,28,30,30,36,35,35],[41,39,33,34,32,28,29,27,27,26,24,22,22,22,26,27,24,24,23,22,22,21,26,27,27,21,21,27,27,22,21,27,27,26,31,29,32,33,36,41],[38,35,39,34,33,28,31,23,22,23,20,21,22,25,22,25,24,25,19,19,20,21,25,21,19,24,25,22,20,21,20,21,23,25,30,32,33,37,34,40],[37,40,33,32,31,28,27,25,22,19,19,17,19,20,19,17,17,22,22,22,21,18,22,22,21,20,20,22,18,20,19,24,26,24,31,28,33,32,37,36],[37,35,34,31,33,33,26,26,26,20,19,20,21,16,20,20,20,18,16,20,15,19,18,20,16,20,15,21,15,18,18,21,23,23,31,30,30,31,38,37],[38,38,37,36,32,32,30,28,22,22,17,17,19,17,17,14,14,14,13,17,17,15,17,13,19,13,15,18,15,18,17,20,22,23,31,28,32,32,36,37],[38,40,37,35,33,31,29,25,25,24,18,18,14,15,13,16,16,14,14,17,11,14,11,17,15,11,13,13,16,21,17,22,26,28,31,27,32,35,39,38],[41,36,34,37,32,32,30,26,23,19,19,19,16,14,10,11,10,13,14,9,10,11,15,12,10,12,10,11,13,15,22,25,24,25,31,29,30,31,39,35],[43,40,36,34,35,30,27,28,26,21,21,19,19,12,12,8,12,11,7,10,9,13,8,12,9,11,15,13,13,21,21,24,25,23,28,33,33,34,36,39],[40,41,36,36,30,29,29,29,24,21,21,21,13,14,11,7,10,9,9,7,5,5,6,11,8,12,15,15,17,16,21,23,25,28,30,28,34,35,37,36],[38,38,33,33,32,31,28,24,26,19,18,17,14,17,14,10,5,6,4,8,6,3,4,4,10,11,9,11,14,15,21,20,25,24,29,32,29,32,38,39],[39,38,37,32,30,30,28,24,23,19,23,21,14,13,14,10,6,3,5,2,1,1,5,5,10,7,12,12,18,16,23,24,21,23,26,30,31,34,37,41],[37,38,37,32,34,32,25,29,27,20,23,16,19,11,13,8,7,4,7,4,5,5,5,3,9,13,12,11,14,20,21,24,22,29,26,31,32,33,37,36],[41,39,33,34,33,31,31,27,26,19,19,15,13,15,11,7,8,3,1,1,3,1,3,4,7,11,11,13,17,17,17,25,26,29,26,29,29,33,38,41],[43,40,36,37,30,29,29,25,25,25,19,21,19,16,9,13,10,8,1,1,0,2,1,8,7,13,12,14,13,20,22,25,23,23,30,29,34,31,38,37],[43,36,39,33,30,33,29,26,24,23,20,15,14,13,10,12,5,8,4,3,3,2,4,3,10,8,14,13,14,15,22,25,21,23,27,29,29,36,39,38],[42,41,36,31,35,31,29,29,24,19,22,18,16,12,9,9,9,3,3,3,8,6,8,7,8,11,11,17,19,15,18,25,24,24,30,32,29,33,34,37],[38,39,35,33,31,28,26,23,21,25,19,21,13,12,11,7,9,9,10,7,5,9,8,7,9,12,15,17,13,18,22,25,22,25,30,31,35,36,33,41],[37,41,38,36,34,30,31,26,24,22,17,21,13,12,15,13,11,10,13,9,8,9,7,12,9,11,15,17,18,18,18,20,24,25,28,33,32,32,38,36],[43,40,34,32,33,31,30,26,27,22,22,18,18,11,13,9,12,13,15,13,11,11,12,12,14,13,9,11,13,21,20,23,23,29,27,29,30,32,36,40],[38,41,38,36,31,32,31,23,25,22,17,16,13,17,15,16,13,17,12,15,17,17,15,15,16,14,15,16,14,16,18,24,26,24,28,33,35,32,33,37],[41,37,35,32,34,32,26,29,27,19,23,20,19,13,17,14,18,16,15,17,16,15,17,18,14,19,16,16,15,18,18,22,23,29,25,28,30,31,37,40],[40,36,39,31,31,30,25,29,22,19,20,15,19,15,17,20,21,18,21,19,17,17,19,19,15,17,20,17,20,21,20,23,22,26,28,30,33,32,37,40],[37,38,34,34,30,27,28,26,27,19,20,17,22,20,23,18,23,22,22,22,19,19,23,21,18,22,23,18,18,18,22,23,24,24,31,31,32,32,36,38],[43,38,39,33,33,29,25,29,22,24,20,19,25,23,24,24,20,21,22,24,19,21,24,20,21,25,19,20,19,24,19,25,21,24,26,29,35,35,37,37],[38,37,33,34,29,31,26,26,21,25,26,21,26,24,26,23,24,26,23,24,23,24,21,27,21,21,25,21,25,25,25,25,27,29,26,32,31,31,38,37],[42,40,36,32,34,29,26,26,29,29,29,24,25,24,23,26,28,29,24,29,23,27,26,24,26,24,25,26,27,27,23,29,23,23,31,30,35,33,34,38],[41,35,37,36,33,30,27,30,26,27,28,28,27,28,25,25,25,30,29,25,26,25,26,31,30,27,29,28,27,26,30,25,30,30,25,30,35,35,36,36],[38,37,39,33,31,30,27,29,29,32,27,33,31,28,30,30,29,27,30,33,32,30,27,32,32,33,33,33,29,31,31,33,31,28,28,30,29,34,38,38],[37,41,33,36,32,29,31,31,33,33,35,32,33,30,35,30,33,31,35,33,32,30,33,30,35,29,35,34,32,32,34,29,30,32,32,35,32,31,35,39],[41,37,37,37,36,37,35,33,31,32,33,34,36,34,36,31,36,31,36,33,32,34,36,32,35,36,32,36,36,36,35,35,31,37,32,37,34,36,36,38],[43,36,38,39,37,33,37,38,33,34,36,34,34,35,35,38,34,34,36,34,35,33,35,35,39,38,38,37,39,35,33,33,38,38,34,37,37,34,36,38],[41,35,35,35,41,39,39,39,38,40,39,40,37,35,41,38,38,40,37,35,40,40,36,38,36,39,41,41,35,39,37,36,35,39,39,41,38,40,39,35]]