A group of computer science students are going to the amusement park!
Because they do not like going outside, the amusement park is an indoor building with a height of .
The students see a very scary looking roller coaster, but scary is fun, right?! They draw the roller coaster on an by celled grid paper, with cell being on the bottom-left and cell on the top-right.
Each column will contain exactly one /
or \
track, with the rest being empty space as denoted by .
. and are guaranteed to contain the track for their respective columns.
The roller coaster is safe if one can follow the coaster's path from , the start of the coaster, to the end at without any jumps. No jump occurs if:
- the track on a column is
/
, the track on the next column is\
and are on the same row. For example,
....
./\.
....
- the track on a column is
\
, the track on the next column is/
and are on the same row. For example,
....
.\/.
....
- the track on a column is
/
, the track on the next column is/
and is one row above. For example,
....
../.
./..
- the track on a column is
\
, the track on the next column is\
and is one row below. For example,
....
.\..
..\.
Otherwise, there is a jump and the coaster is unsafe. Can you determine whether the coaster is safe or not?
Constraints
Each cell will either be .
, /
, or \
.
Each column will contain exactly one \
or /
characters.
Cell will be /
and cell will be \
.
Input Specification
The first line will contain space-separated integers and .
The next lines will contain characters denoting the drawing of the roller coaster for that row.
Output Specification
According to the rules above, output safe
if the roller coaster is safe and unsafe
otherwise.
Sample Input 1
10 5
..........
...../\...
../\/..\..
./......\.
/........\
Sample Output 1
safe
Sample Input 2
6 4
.../..
../...
./..\.
/....\
Sample Output 2
unsafe
Comments