#Q184. 「一本通 5.5 练习 3」理想的正方形

「一本通 5.5 练习 3」理想的正方形

Description

Original source: HAOI 2007

There is a matrix of integers with dimensions a×ba\times b. Your task is to find an n×nn\times n square submatrix within it such that the difference between the maximum and minimum values in this submatrix is minimized.

Input Format

The first line contains three integers: aa, bb, and nn;

The next aa lines each contain bb non-negative integers, representing the numbers in the corresponding positions of the matrix.

Output Format

Output a single integer, which is the minimum difference between the maximum and minimum values among all possible n×nn\times n square submatrices in the a×ba\times b matrix.

Sample 1

5 4 2
1 2 5 6
0 17 16 0
16 17 2 1
2 10 2 1
1 2 2 2

1

Data Range and Hints

For 20%20\% of the data, 2a,b1002\le a,b\le 100 and n10n\le 10;
For 100%100\% of the data, 2a,b10002\le a,b\le 1000, nan\le a, nbn\le b, n100n\le 100, and all numbers in the matrix do not exceed 10910^9.