Relative Town Massacre

View as PDF

Submit solution

Points: 1
Time limit: 1.0s
Memory limit: 256M

Problem types

İlim is a very curious boy and likes to dive into his grandfather's library very frequently. This time he finds a book called "Relative Town Massacre" and immediately picks it up. The moment he opens the book, a demon called Skr appears and kidnaps İlim into the book.

Skr says: "We are gonna play a game. Provided relative positions of points on an X-dimensional world, first, you need to find whether such a world can exist without any contradictions. After that, if it does exist, we will find the minimum volumed X-dimensional object including all the points. So, it needs to be a Then, that second phase will start."

İlim spoke with rolling eyes: "Se... Second phase? What is it?"

Skr answers with a smiling face: "Nice that you asked... We will play a turn-based game. The active player will choose a dimension and after that, they will shrink the edge on that dimension of the minimum volumed X-dimensional object into any amount, they can even erase that edge! (Note that erasing one edge completely doesn't destroy the object.) If no amount of shrinkage is possible on any of the dimensions, the active player loses. Lastly, you do not want to be on the losing side..."

İlim asked: "Who will start?"

Skr answered: "I am in a generous mood, so you can start.."

Now you need to find whether İlim can get out of Skr's world by winning the game or finding that no such world can exist. Can you predict İlim's future if both sides play optimally?

Notes:

  • No point has a relation to itself.
  • There might be duplicate rules.
  • There are at least two different relations.
  • The object can be shrunk from an edge when the edge is larger than 0. The shrinkage can be defined as follows: An edge with length \(\mathbf{L}\) can be shrunk to length \(\mathbf{L - A}\) with an integer \(\mathbf{A}\) that satisfies the condition \(1 \leq \mathbf{A} \leq \mathbf{L}\).

Input

The first line includes a positive integer representing the number of rules, \(\mathbf{N}\).

Next \(\mathbf{N}\) lines include three parts, \(\mathbf{a, b, c}\). \(\mathbf{a}\) and \(\mathbf{c}\) are integers that represent the points in the relation. \(\mathbf{b}\) is a string constructed by concatenating the integers by a comma. Each of the integers in \(\mathbf{b}\) represents a dimension between \(\mathbf{a}\) and \(\mathbf{c}\). This means for each dimension \(\mathbf{b_i}\), \(\mathbf{a}\) and \(\mathbf{c}\) are related in that dimension.

  • \(2 \leq \mathbf{N} \leq 10^3\)
  • \(1 \leq \mathbf{a, c} \leq 10^3\)
  • \(1 \leq \mathbf{len(b)} \leq 10\)
  • \(-1000 \leq \mathbf{b_i} \leq 1000\)
Explanation

Each dimension is represented by an integer and each relation exists in positive and negative forms.

For example, if we were working on a 2-dimensional world and 1 representing vertical and 2 representing horizontal for instance. In that case 1 2 2 would mean \(1^{st}\) point is positioned on the right of \(2^{nd}\) point and 1 -1 2 would mean \(1^{st}\) point is positioned on the bottom of \(2^{nd}\) point. It could also be left and top too since they are all relative.

Output

If possible, print the winner of the game as ILIM or SKR. If no such world can exist just print IMPOSSIBLE.

Examples

Input 1:

3
1 1 2
2 1,2 3
3 2 1

Output 1:

SKR

Input 2:

3
1 10,2 2
2 10,3 3
3 12,10 1

Output 2:

IMPOSSIBLE

Explanation

Input 1:

Assuming 1 represents top and 2 represents right:

  • 1 1 2 => 1 is on top of 2
  • 2 1,2 3 => 2 is on top of 3 AND 2 is on the right side of 3
  • 3 2 1 => 3 is on the right side of 1

It can be visualized as:

| 1 |   |   |
|   |   | 2 |
|   | 3 |   |

This world does exist and the minimum volume that encapsulates all the points would have a value of 9 with dimensions [3, 3]. İlim would start the game assuming that played optimally, İlim would lose.

Input 2:

In this exaple on the \(10^{th}\) dimension 1 => 2 => 3 => 1 is assumed and this simply can not happen.