cho.sh
Notes
Loading...

Pirate of Busan

Time limit

1s

Memory limit

128 MB

Problem

Sua found a treasure map. The map is an N × M grid, and each cell is either sea or part of an island. The map also marks the treasure, a pirate ship, and the current position of Sua.

Sua must choose a route that starts at the current position and ends at the treasure. On each move, Sua moves one cell up, down, left, or right, and cannot enter an island cell.

The pirate moves in the same way. Each turn, Sua moves first, and then the pirate either moves one cell or stays in place. After each turn, apply the following rules.

  • If Sua and the pirate are in the same row or the same column, and there is no island between them, Sua is caught.
  • If Sua has not been caught and is on the treasure cell, Sua obtains the treasure.

Determine whether there is a route that lets Sua obtain the treasure without being caught, no matter how the pirate moves.

Input

The first line contains N and M. The next N lines contain the treasure map. Each line consists of M characters.

  • .: sea
  • I: island
  • V: pirate position
  • Y: current position of Sua
  • T: treasure position

V, Y, and T each appear exactly once.

Constraint: 1 ≤ N, M ≤ 700

Output

Print YES if Sua can obtain the treasure, and print NO otherwise.

Hint

In the first visible test case, moving down, down, down, right, right, right, and down reaches the treasure.