Linda is giving an exam. When the exam is over, Linda will redistribute the exams among the students for a peer review, so they may grade each other's answers and assign preliminary scores.
The students are split up in several rooms of varying sizes. Linda has devised the following scheme for redistributing the exams:
Naturally, it is imperative that no student receives their own exam to review, and that Linda does not run out of exams in her pile while doing the redistribution (i.e., when entering a room after the first one, Linda's pile contains at least as many exams as many students there are in the room). Whether or not this is the case depends on the order in which the rooms are visited. We say that an ordering of the rooms is safe if Linda will not run out of exams in her pile when visiting rooms in that order, and there is no chance that any student receives their own exam to review.
Can you find a safe order in which to visit the rooms (or determine that no safe order exists)?
The input consists of:
If it is impossible to redistribute the exams safely, output
Sample Input 1
Output for Sample Input 1
Sample Input 2
Output for Sample Input 2
|University of Debrecen; Faculty of Informatics; v. 03/01/2019|