Amazing Mazes

(Hard Problem No# 2)


A solution for this problem can be found here.

You are trapped in a 3D maze and need to find the quickest way out! The maze is approximated as a set of unit cubes which may or may not be filled with rock. You can move in any of six directions (nominally up, down, north, south, east and west, but the actual orientation doesn't matter). In the escape plan, going up or down (moving between levels) takes twice as long as it does to move between cells on the same level. You cannot move diagonally in any plane.

Each side of the maze may be up to 30 units in length, and there is solid rock surrounding the maze.


INPUT FORMAT

The input file consists of a number of mazes. Each maze starts with a line containing the number of levels in the maze, as an integer. Each level is the same size, and consists of a number of lines terminated by a blank line. Each character in each line represents one cell in the maze. A cell that is full of rock, and hence impassable, is represented as a '#', and an empty cell is represented as a '.'. The start cell is represented as an 'S', and the end cell is represented as an 'E'.

The end of file is signified by a maze with 0 levels.


OUTPUT FORMAT

The output for each maze is a single line containing the word "Escape" if it is possible to get to the destination point, or "Trapped" if it is not. In addition, if you can escape, the output line should contain the time required to escape, as an integer in units of time measured in terms of how long it takes to move between two cells on the same level.

The solution to each maze should be output on a new line.


SAMPLE INPUT

3
S....
.###.
.##..
###.#

#####
#####
##.##
##...

#####
#####
#.###
####E

1
S##
#E#
###

0


SAMPLE OUTPUT

Escaped in 13 minutes.
Trapped!


########################################################################## Competition Server comp@arcadia.cs.rmit.edu.au (via comp@cs.curtin.edu.au) Problems with server: contact Craig Dillon (cdillon@cs.curtin.edu.au) ##########################################################################