Revenge of Faucet Flow

A faucet is pouring water into an M × N rectangular aquarium. The aquarium’s floor is uneven, formed from a number of unit cubes piled on top of one another (and glued, to make them watertight). Thus, every square in the aquarium has a specific height, from 0 to 9. There are no other walls or obstructions in or surrounding the aquarium (it is open on all sides). Water pours from the faucet at a rate of 1 cubic unit per second. How long will it take before water begins spilling over one of the sides? You may assume that the water behaves ideally: it instantly spreads out across any flat surface, spilling over all adjacent edges at an equal rate of flow. It cannot flow between two cubes that touch, even at a corner. Input There are up to 20 test cases. Each test case begins with a line containing two integers M and N (1 ≤ M, N ≤ 10), specifying the number of rows and columns in the aquarium, respectively. The next line contains R and C (1 ≤ R ≤ M, 1 ≤ C ≤ N), giving the coordinates of the square the faucet is pouring on. (1,1) is the upper-left corner. Finally, M lines with N integers are given, specifying the height of each square in the aquarium. Input is terminated with a line containing two zeros. Output For each case, output one line containing the number of seconds it will take before water starts spilling over any of the four sides of the aquarium. Print your answer accurate to two decimal places. Sample Input 44 22 5355 5025 5225 5555 00 Sample Output 6.00