P27538 [洛谷] [Language Contest 202302] Wind God's Eye
普及-
题目描述

Problem Description

You are helping to design a chess software. Now, you want to design a logical feature. Here is an introduction to this feature.

Imagine an infinite chessboard, where we use $(x, y)$ to denote the $x$-th row and $y$-th column of the board. Specifically, if a piece is at position $(x, y)$, then it is located at the $x$-th row and $y$-th column of the board.

There are four types of pieces: Rook, Cannon, Horse, Elephant. Their corresponding IDs and capture rules are as follows. The following rules assume the piece is at position $(x, y)$.

Note that the following rules may slightly differ from the actual Chinese chess rules.

Name ID Movement Rules
Rook $1$ Can move horizontally or vertically, i.e., in one move, it can capture a piece at any of the positions $(x + k, y), (x - k, y), (x, y + k), (x, y - k)$ where $k$ is any positive integer.
Cannon $2$ Imagine a straight line where the cannon and the opponent's piece are on this line. The cannon can only capture the opponent's piece if there is exactly one other piece between them on this line.
Horse $3$ Moves in an "L" shape, i.e., in one move, it can capture a piece at any of the positions $(x + 2, y + 1), (x + 2, y - 1), (x - 2, y + 1), (x - 2, y - 1), (x + 1, y + 2), (x + 1, y - 2), (x - 1, y + 2), (x - 1, y - 2)$.
Elephant $4$ Moves in a "diagonal" shape, i.e., in one move, it can capture a piece at any of the positions $(x + 2, y + 2), (x + 2, y - 2), (x - 2, y + 2), (x - 2, y - 2)$.

Now you are given a set of queries, each containing five integers $p, x_0, y_0, x_1, y_1$, representing that there are only two pieces on the board. The first piece has ID $p$ and is at the $x_0$-th row and $y_0$-th column. The second piece's ID is unknown and not needed, and it is at the $x_1$-th row and $y_1$-th column.

You need to consider whether, if you can and can only operate the first piece once, the first piece can capture the second piece.

Input Format

The input consists of a single line.

The first line contains five integers $p, x_0, y_0, x_1, y_1$, separated by a space, with the same meaning as in the problem statement.

Output Format

Output a single line. If the first piece can capture the second piece, output Yes; otherwise, output No.

Sample Input and Output

Sample Input #1

1 1 4 2 4

Sample Output #1

Yes

Sample Input #2

1 1 4 2 5

Sample Output #2

No

Sample Input #3

2 1 1 2 1

Sample Output #3

No

Sample Input #4

3 1 4 2 6

Sample Output #4

Yes

Notes

Sample Explanation

Sample sets #1 and #2 represent cases where the Rook can and cannot capture the opponent's piece.

Sample set #3 represents a case where the Cannon cannot capture the opponent's piece.

Sample set #4 represents a case where the Horse can capture the opponent's piece.

The link provided contains all sample piece placements and can be consulted as needed.

Data Range and Constraints

For $20\%$ of the data, it is guaranteed that $p = 2$.
For $100\%$ of the data, it is guaranteed that $p \in \{1, 2, 3, 4\}$, $1 \leq x_0, y_0, x_1, y_1 \leq 10^9$, and it is guaranteed that $x_0$ and $x_1$, $y_0$ and $y_1$ will not be the same simultaneously, meaning the two pieces will not overlap.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
1 1 4 2 4
样例输出
Yes