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

#BS0000090. Tìm số trong ma trận có thứ tự (Search a 2D Matrix)

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 có thứ tự (Search a 2D Matrix)

Search a 2D Matrix

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Given an m×nm\times n integer matrix whose rows are non-decreasing and whose first element of each row is greater than the last element of the previous row, determine whether tt occurs.

Input

The first line contains m,n,tm,n,t. Each of the next mm lines contains exactly nn matrix entries.

Output

Print true if tt is present, otherwise false.

Subtasks

  • Subtask 1 (20 points): 1≤m,n≤51\le m,n\le 5; −104≤ai,j,t≤104-10^4\le a_{i,j},t\le10^4; each row is non-decreasing and each next row starts with a greater value than the previous row ends.
  • Subtask 2 (30 points): 1≤m,n≤301\le m,n\le 30; −104≤ai,j,t≤104-10^4\le a_{i,j},t\le10^4; each row is non-decreasing and each next row starts with a greater value than the previous row ends.
  • Subtask 3 (50 points): 1≤m,n≤1001\le m,n\le 100; −104≤ai,j,t≤104-10^4\le a_{i,j},t\le10^4; each row is non-decreasing and each next row starts with a greater value than the previous row ends.

Examples

Input

3 4 3
1 3 5 7
10 11 16 20
23 30 34 60

Output

true

Explanation

The entry in row 00, column 11 equals the target 33, so the answer is true.