This page is still under construction.

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

Gunwoo Trapped in a Maze

Time limit1sMemory limit256 MB

Summary
Find the earliest day and time of day to reach the goal in an n x n maze where every m moves flip between day and night; at night he can pass through consecutive walls in a straight line.
Level

Medium7 of 10

Topics
BFS, Graph, Implementation, Simulation
Solved
No attempts yet

Problem

Gunwoo, who had been idling away his days, started his assignment on the last day. Perhaps because fatigue caught up with him, he fell asleep. Then he dreamed. The place was a maze, and it was so unrealistic that Gunwoo realized it was a dream. He tried to wake up right away, but he could not. To wake from the dream, he had to escape the maze. The maze has the following properties.

  • It is an n×n maze; the top-left cell is the start and the bottom-right cell is the goal. The start and the goal are guaranteed to have no wall.
  • Gunwoo can move only up, down, left, and right. Except when crossing walls, a single move takes him to an adjacent cell that has no wall.
  • The initial state is day 1 daytime, and every time Gunwoo makes m moves, the state changes from day to night or from night to day.
  • At night, unlike during the day, he can also cross walls. To cross a wall, the adjacent cell in the intended direction must be a wall, and he continues crossing consecutive walls until he reaches a cell where he can stand.
  • He cannot change direction while crossing walls, and crossing a wall counts as one move.

The following are examples of crossing walls. Orange is where Gunwoo is, and blue is a wall.

In this case, he can cross the wall.

As in this case, if crossing the wall would take him out of the maze, the move is not allowed.

Find the day on which Gunwoo can escape the fastest, and whether it is daytime or nighttime, so that he can wake up!

Input

The first line gives n and m. (1 ≤ n ≤ 500, 1 ≤ m ≤ 10)

From the second line, n lines follow, each containing n values of 0 or 1 separated by spaces. Here 0 means a cell with no wall where Gunwoo can stand, and 1 means a cell with a wall where he cannot stand.

Output

Print the number of the day on which Gunwoo can escape the fastest, together with "sun" if it is daytime or "moon" if it is nighttime, separated by a space. For example, if it is night of day 2, print "2 moon", and if it is day of day 3, print "3 sun". If he cannot escape, print -1.

Examples2

  1. Example 1

    Input
    5 2
    0 0 0 0 0
    0 0 1 0 0
    0 0 1 0 0
    0 0 1 0 0
    0 0 0 0 0
    
    Expected output
    2 sun
    
  2. Example 2

    Input
    3 1
    0 1 0
    1 0 0
    0 0 0
    
    Expected output
    -1