#K39582. Princess Escape

    ID: 26452 Type: Default 1000ms 256MiB

Princess Escape

Princess Escape

The problem is set on a grid of size \(n \times m\). The princess starts at position \((p_x, p_y)\) with a security number \(p_s\). There are several guards on the grid, each positioned at \((g_x, g_y)\) with a security number \(g_s\). The princess can move one cell at a time in one of the four cardinal directions (up, down, left, right). She is allowed to move into a cell if and only if the cell is empty or the guard in that cell has a security number strictly less than \(p_s\).

The princess escapes if she can reach any boundary cell of the grid. In other words, if the princess reaches a cell where either its row index is \(1\) or \(n\), or its column index is \(1\) or \(m\) (note that the grid is 1-indexed), she successfully escapes.

Your task is to determine whether the princess can escape the grid given the initial conditions.

inputFormat

The input is read from standard input and has the following format:

n m
p_x p_y p_s
k
g_x1 g_y1 g_s1
g_x2 g_y2 g_s2
... (k lines in total)

Here, \(n\) and \(m\) are the number of rows and columns of the grid respectively, \((p_x, p_y)\) is the starting position of the princess, \(p_s\) is her security number, and \(k\) is the number of guards. Each of the next \(k\) lines contains three integers representing a guard's row, column, and security number.

outputFormat

The output should be printed to standard output. It is a single line containing either "YES" if the princess can escape, or "NO" otherwise.

## sample
5 5
3 3 7
5
2 2 5
2 3 6
3 2 8
4 4 5
5 5 10
YES