eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Guessing Game

Guessing Game

Лимит времени 1 секунда
Лимит использования памяти 64 MiB

Jaehyun has two lists of integers, namely a_1, ..., a_N and b_1, ..., b_M . Jeffrey wants to know what these numbers are, but Jaehyun won’t tell him the numbers directly. So, Jeffrey asks Jaehyun a series of questions of the form "How big is a_i+b_j ?" Jaehyun won’t even tell him that, though; instead, he answers either "It’s at least c," or "It’s at most c." (Right, Jaehyun simply doesn’t want to give his numbers for whatever reason.) After getting Jaehyun’s responses, Jeffrey tries to guess the numbers, but he cannot figure them out no matter how hard he tries. He starts to wonder if Jaehyun has lied while answering some of the questions. Write a program to hep Jeffrey.

Входные данные

The input consists of multiple test cases. Each test case begins with a line containing three positive integers N, M, and Q, which denote the lengths of the Jaehyun’s lists and the number of questions that Jeffrey asked. These numbers satisfy 2N + M1000 and 1Q10000. Each of the next Q lines is of the form i j<=c or i j>=c. The former represents a_i + b_j ≤ _c, and the latter represents a_i + b_jc. It is guaranteed that −1000c1000. The input terminates with a line with N = M = Q = 0.

Выходные данные

For each test case, print a single line that contains "Possible" if there exist integers a_1, ..., a_N and b_1, ..., b_M that are consistent with Jaehyun’s answers, or "Impossible" if it can be proven that Jaehyun has definitely lied (quotes added for clarity).

Пример

Входные данные #1
2 1 3
1 1 <= 3
2 1 <= 5
1 1 >= 4
2 2 4
1 1 <= 3
2 1 <= 4
1 2 >= 5
2 2 >= 7
0 0 0
Выходные данные #1
Impossible
Possible
Источник 2011 Stanford Local ACM Programming Contest, Saturday, October 8th, 2011