You might be familiar with the game Bloxorz. If not, please watch stage 1 of this video to understand the mechanics of the game. In this problem, there are no buttons, no possibility of splitting the player into two cubes, or any other features that do not appear in stage 1 of the video.
The player is a rectangular parallelepiped with dimensions . Initially, its height is while its length and width are . To move on the map, the player will rotate in four directions (North, South, East, West). With each rotation, the player's height, length, and width will interchange. For example, from the player's initial state, it can change to a height of , a length of , and a width of .
Task
You are given a two-dimensional map that contains platforms at some positions. The player is allowed to move only on platforms. Check if it is possible for the player to move from an initial platform to a final platform, ending with a height of and a length and width of . If it is possible, display a correct path that the player can use.
Input data
The first line contains the numbers and , representing the dimensions of the map (number of rows and number of columns, respectively).
The next lines contain characters, each representing a piece of the map. The characters can be:
_
— This character represents a platform.#
— This character represents a space with nothing. The player is not allowed to move there.A
— This character represents the initial platform.B
— This character represents the final platform.
Output data
If there is no path, print NU
.
If there is a path, print on the first line DA
, and on the second line a sequence of characters from the set N
S
E
V
representing the directions the player will take at each step (N
— North, S
— South, E
— East, V
— West).
Constraints and clarifications
- The player must be entirely on platforms. It is not allowed for half of the player to be on a platform while the other half is not.
- The problem does not necessarily require the path to have the minimum number of steps.
- There are no platforms outside the map.
- You will receive of the points for a subtask for correctly displaying only the first message (
DA
/NU
).
# | Points | Constraints |
---|---|---|
0 | 0 | Example |
1 | 10 | If there is a path, it consists of only one direction |
2 | 70 | |
3 | 20 | No additional constraints |
Example
stdin
6 10
___#######
_A____####
_________#
#_________
#####__B__
######___#
stdout
DA
EESEEES
Explanation
The example is the same as in the video, as well as the moves made.
The solutions ESSEESE
or EESENVSEEESSNVNSVNESEVSSVENVNEESVNESVNESV
are also correct.