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

#BS0000097. Tìm số trong ma trận hàng và cột có thứ tự (Search a 2D Matrix II)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Tìm số trong ma trận hàng và cột có thứ tự (Search a 2D Matrix II)

Search a 2D Matrix II

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Given an m×nm\times n integer matrix non-decreasing across every row and down every column, determine whether target tt occurs.

Input

The first line contains m,n,tm,n,t, followed by mm rows of nn integers each.

Output

Print true if tt occurs, otherwise false.

Subtasks

  • Subtask 1 (20 points): 1≤m,n≤61\le m,n\le 6; −109≤ai,j,t≤109-10^9\le a_{i,j},t\le10^9; all rows and columns are non-decreasing.
  • Subtask 2 (30 points): 1≤m,n≤401\le m,n\le 40; −109≤ai,j,t≤109-10^9\le a_{i,j},t\le10^9; all rows and columns are non-decreasing.
  • Subtask 3 (50 points): 1≤m,n≤3001\le m,n\le 300; −109≤ai,j,t≤109-10^9\le a_{i,j},t\le10^9; all rows and columns are non-decreasing.

Examples

Input

3 3 5
1 4 7
2 5 8
3 6 9

Output

true

Explanation

The entry at row 11, column 11 is 55, equal to the target, so output true.