This page is still under construction.

Parts of this page are still being built. What you see may change.

Bishop Tour

Interview

Time limit1sMemory limit512 MB

Summary
Given a board and two squares, decide whether a bishop can travel from the start square to the end square using any number of diagonal moves.
Level

Easy2 of 10

Topics
Math, Implementation, Geometry
Solved
No attempts yet

Problem

A knight's tour is a problem of finding a path on a chessboard where a knight visits every square exactly once. Chess master Heeja wondered whether the bishop, another minor piece, can also travel freely across the board. Given a start point and an end point, determine whether the bishop can move from the start point to the end point using as many moves as needed.

A bishop moves any number of squares diagonally in a single move.

Input

The first line gives the board dimensions NN and MM.

The second line gives the coordinates of the start point (sx,sy)(s_x, s_y).

The third line gives the coordinates of the end point (ex,ey)(e_x, e_y).

The top-left corner of the board has coordinates (1,1)(1, 1), and the bottom-right corner has coordinates (N,M)(N, M).

Output

Print YES if the bishop can move from the start point to the end point, or NO otherwise.

Constraints

  • 1≤N,M≤1091 ≤ N, M ≤ 10^9
  • 1≤sx,ex≤N1 ≤ s_x, e_x ≤ N
  • 1≤sy,ey≤M1 ≤ s_y, e_y ≤ M

Examples2

  1. Example 1

    Input
    2 3
    1 1
    1 3
    
    Expected output
    YES
    
  2. Example 2

    Input
    2 2
    1 1
    1 2
    
    Expected output
    NO