Capture the knight

Given an chessboard, one white knight at position and one black knight at position, you are asked if one can capture the other in 1 or 2 moves.
A knight captures another knight if it moves to the same location as the other one.
As a reminder, in one move, the knight moves 2 cells in one direction and 1 cell in another perpendicular to the first direction. So, it can move 2 cells up and 1 cell left or right. It can move 2 cells right and 1 cell up or down. It can move 2 cells down and one cell left or right, etc.
notion image
In this problem, the second knight stays in the same place, while the first one does exactly two moves.


The input contains 2 lines. The first line contains two coordinates indicating the first knight , while the second line contains the coordinates of the second knight (1 ≀ ≀ 8). It’s guaranteed that is different from .


The program should print Yes in case the first knight can capture the second one in 1 or 2 moves and No otherwise.


1 1 1 3
1 1 8 8


β†’ β†’
notion image
Impossible in 2 moves
notion image


Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue