Hide

Problem G
Getting to Bed

Paul has just moved in, and there are boxes everywhere, however, it’s midnight and he wants to get to bed. He gave the moving company the dimensions of the room, and they provided a list with the coordinate positions of the heavy boxes. These boxes can’t be moved easily, and they fit perfectly in the room’s coordinate squares such that it’s impossible to move diagonally through boxes whose corners touch. Thus, you can move only horizontally or vertically.

Given this information, is it possible to get to your bed without having to move the “heavy boxes?”

The room is given via a coordinate system, as seen below:

\includegraphics[width=.4\textwidth ]{FirstExample.jpg}

The red boxes are the boxes that are too heavy to move, while the green box represents where the bed is located. The door will always be at the starting position $(0,0)$.

Here’s an example where the moving company left a path to the bed:

\includegraphics[width=.4\textwidth ]{SecondExample.jpg}

The green arrows represents one of the paths Paul can take.

Input

The input begins with a single line containing three integers, $n$ ($1 \le n \le 100$) which represents the length of the room in terms of boxes, $m$ ($1 \le m \le 100$) which represents the width of the room in terms of boxes, and $k$ ($0 \le k \le m \cdot n$) which represents how many unmovable boxes there are. After that, there are $k$ number of lines which represent the coordinates of the heavy boxes, each containing a pair of integers $x$ and $y$ ($0 \le x < n$, $0 \le y < m$) denoting the coordinates of a heavy box. Lastly, there is one last line containing another integer pair $(f, g)$ ($0 \le f < n$ and $0 \le g < m$) showing the coordinates where the bed is located. Paul will always start at the position $(0, 0)$, and there will be no heavy boxes located at that spot.

Output

Output SLEEPING if Paul can reach his bed, otherwise output IMPOSSIBLE.

Sample Input 1 Sample Output 1
7 4 5
5 0
6 0
5 1
5 2
6 2
6 1
IMPOSSIBLE
Sample Input 2 Sample Output 2
6 4 4
1 0
2 1
3 2
4 2
2 0
SLEEPING

Please log in to submit a solution to this problem

Log in