#P1170. Safe Orchard? Determining Bugs Bunny's Safety

    ID: 13790 Type: Default 1000ms 256MiB

Safe Orchard? Determining Bugs Bunny's Safety

Safe Orchard? Determining Bugs Bunny's Safety

Bugs Bunny is hiding under a tree in an orchard adjacent to a forest. The orchard contains an M×NM \times N grid of trees arranged in MM rows and NN columns, where the distance between two horizontally or vertically adjacent trees is 11. A hunter, armed with a shotgun, enters the orchard and climbs a tree to kill Bugs Bunny. The hunter can see Bugs Bunny if there is no other tree on the straight line connecting their respective trees. In other words, if the greatest common divisor (gcd) of the differences in their row and column indices is 11, there will be no intermediate tree blocking the line of sight, and the hunter will be able to see Bugs Bunny.

Given the positions of Bugs Bunny and the hunter (both corresponding to tree locations), determine whether Bugs Bunny is safe. Bugs Bunny is considered safe if there is at least one other tree on the line between them (i.e. when the gcd of the differences is greater than 11).

inputFormat

The input consists of three lines:

  1. The first line contains two integers MM and NN, representing the number of rows and columns in the orchard.
  2. The second line contains two integers rbr_b and cbc_b, representing the row and column of Bugs Bunny's tree.
  3. The third line contains two integers rhr_h and chc_h, representing the row and column of the hunter's tree. It is guaranteed that both positions lie within the grid.

outputFormat

Output a single word:

  • Print YES if Bugs Bunny is safe (i.e. there exists at least one tree on the line between the hunter and Bugs Bunny),
  • Otherwise, print NO (if the hunter can see Bugs Bunny).

sample

5 5
1 1
1 2
NO

</p>