eolymp
bolt
Try our new interface for solving problems
Problems

Path caver

Path caver

The cave is represented by a cube, partitioned into \textbf{N} parts of each imereniyu (ie \textbf{N^3} cubic cells). Each cell is either empty or completely filled with stone. Based on the provisions spaleologa in a cave, you want to find a minimum number of movements of cells it takes to get to the surface. Move from cell to cell is possible only if they are both free and have a common face. \InputFile The first line contains the number \textbf{N} (\textbf{1} ≤ \textbf{N} ≤ \textbf{30}). This is followed by \textbf{N} blocks. The unit consists of empty rows and \textbf{N} lines of \textbf{N} characters: \textbf{#} denotes a cage filled with rocks, point - a free cell. Initial position of the caver indicated by a capital letter \textbf{S}. The first block represents the top level of the cave, the achievement of any free his cell means going to the surface. The yield on the surface is always possible. \OutputFile Derive a single number - the length of the path to the surface.
Time limit 1 second
Memory limit 64 MiB
Input example #1
3

###
###
.##

.#.
.#S
.#.

###
...
###
Output example #1
6