PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#PS0000214. Cạnh hình vuông lớn nhất có tổng không vượt ngưỡng (Maximum Side Length)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Cạnh hình vuông lớn nhất có tổng không vượt ngưỡng (Maximum Side Length)

Maximum Side Length

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

An m×nm\times n matrix aa contains nonnegative integers. Find the largest side length of a nonempty square of consecutive cells, with sides parallel to the matrix axes, whose cell sum is at most KK. Print 0 if no such square exists.

Input

The first line contains three integers m,n,Km,n,K. Each of the next mm lines contains exactly nn integers ai,1,…,ai,na_{i,1},\ldots,a_{i,n}.

Output

Print the largest side length, or 0 if no valid square exists.

Subtasks

  • Subtask 1 (20 points): 1≤m,n≤121\le m,n\le 12; 0≤ai,j≤100000\le a_{i,j}\le 10000; 0≤K≤1000000\le K\le 100000.
  • Subtask 2 (30 points): 1≤m,n≤3001\le m,n\le 300; 0≤ai,j≤100000\le a_{i,j}\le 10000; 0≤K≤1000000\le K\le 100000; K=0K=0.
  • Subtask 3 (50 points): 1≤m,n≤3001\le m,n\le 300; 0≤ai,j≤100000\le a_{i,j}\le 10000; 0≤K≤1000000\le K\le 100000.

Example 1

Input

3 7 4
1 1 3 2 4 3 2
1 1 3 2 4 3 2
1 1 3 2 4 3 2

Output

2

Explanation

The 2-by-2 square in the first two columns sums to 4. Every 3-by-3 square exceeds 4.

Example 2

Input

5 5 1
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2

Output

0

Explanation

Every single cell already exceeds 1.

Example 3

Input

2 3 0
0 0 2
0 0 1

Output

2

Explanation

The leftmost four cells form a square of side 2 with sum 0.