Trapping Rain Water - 2

hard
Given an m x n integer matrix heightMap representing the height of each unit cell in a 2D elevation map, return the volume of water it can trap after raining.

Input Format

Array

Output Format

Integer

Constraints

m == heightMap.length
n == heightMap[i].length
1 <= m, n <= 200
0 <= heightMap[i][j] <= 2 * 104

Notice

NA

Example

Input
6
6
0 1 4 2 8 2
4 3 6 5 0 4
1 2 4 1 4 6
2 0 7 3 2 2
3 1 5 9 2 4
2 7 0 8 5 1
Output
9
Previous
Count Submatrices With All Ones
Next
Sequential Digits

Related Questions