Подразделы

Другие разделы

Дата и время

20/12/2024 11:27:55

Авторизация

Имя:
Пароль:
Зарегистрироваться
Восстановить пароль
 

printThe Run

Ограничения: время – 1s/2s, память – 32MiB Ввод: input.txt или стандартный ввод Вывод: output.txt или стандартный вывод copy
Послать решение Blockly Посылки Темы Где Обсудить (0)

Bob is a coach of juniors' baseball team. One day he ordered team to run around the playing-field five times. Soon he was distracted by telephone call. While Bob and Alex discussed the plans of big party, the run was ended. Bob asked several children about the results of the run. But nobody of them can give him the order how they came to finish. Children remembered only who were before him and who were after him. Children did not remember exact order among they also. Probably somebody was mistaken, because Bob could not determine the order how children came to finish by the results of interview.
Write the program to help Bob to determine who was wrong in his evidence.
Input
The first line of the input file contains an integer `N` (`1\ ≤\ N\ ≤\ 100`), which equals the amount of the participants of the run, who gave their evidence to Bob. The following `N` lines contain several integers separated by spaces. The first integer in a line is the number of the participant who gave his evidence. The numbers of participants who gave evidence are different. Further there are numbers of those participants who finished before him, then 0 (zero), then the numbers of those participants who finished after him, then 0 (zero). The numbers of all participants are written at their game shirts and have values from 1 to 100.
Output
Write into the output file 0 (zero), if there are no contradictions in these evidences. If there are contradictions and they can be explained by errors of single participant, write the numbers of participants who may be mistaken in increasing order. The numbers should be separated by one space. If there are contradictions and they cannot be explained by single error evidence, write the number `–1`.

Sample Input #1

1
2 1 0 3 0

Sample Output #1

0

Sample Input #2

3
2 1 0 3 0
1 3 0 2 0
3 0 4 0

Sample Output #2

1 2

Sample Input #3

3
2 1 0 3 0
1 3 0 2 0
3 2 0 1 4 0

Sample Output #3

-1
Clarification
Children finished at different time.
Условие задачи на русском языке
loading