Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/dona-yurishi

One move for the piece?

Medium 1000 ms 64 MB 47%
Share

One piece stands on an empty chessboard. The letter of the piece and two squares are given: the square the piece is on and the square it must reach (for example, e2: the letter is the column a…h, the digit is the row 1…8). Can the piece reach that square in one move? K (king) moves to a neighbouring square (side by side or diagonally); R (rook) — to any square of the same row or column; B (bishop) — along a diagonal; Q (queen) — like a rook or a bishop; N (knight) — in an "L" shape: $2$ squares in one direction and $1$ square in the other. Print YES if it can, otherwise NO.

A chessboard: the piece's square and the target square, the piece's path highlighted

Input

One line: the letter of the piece and two squares — where the piece stands and where it must go.

Output

YES or NO.

Note

The letter is only K, Q, R, B or N.
Both squares are on the board and different.

Examples

Input #1
N g1 f3
Output #1
YES
Input #2
B c1 h7
Output #2
NO

Sign in to submit a solution

Signing up is free and takes a minute.