
It is almost Thanksgiving at Pierre Elliott Trudeau High School! (The school celebrates it around 1-2 weeks after the actual date). In order to truly celebrate Thanksgiving, TSAC (Trudeau Student Activity Council) has decided to host a huge Thanksgiving feast.
Each student has a list of dishes that they would like to eat from. In particular, the
You have been tasked to choose the order to place the students and the dishes. Can you find a way to order the students and dishes so that it is impossible for any two students to cross their arms?
Constraints
For all subtasks:
The sum of all
Subtask 1 [25%]
Subtask 2 [25%]
Additionally, if there is a solution, it is possible to place the
Subtask 3 [50%]
Input Specification
The first line will contain
Output Specification
If there is a way to arrange the students and the dishes such that no two students can cross their arms, output two lines of
If there is no valid arrangement, output every man for himself!
.
Sample Input 1
2
2 1 2
1 1
Sample Output 1
1 2
2 1
Explanation for Sample Output 1
If the dishes are ordered 1,2 and the ordering of the students is 1,2, the two students would cross arms if student 1 reaches for dish 2 at the same time student 2 reaches for dish 1.
If the dishes are ordered 2,1 and the ordering of the students is 1,2, the two students will never be able to cross arms. Note that the two students are allowed to reach for dish 1 at the same time.
Sample Input 2
3
2 2 3
2 1 3
2 1 2
Sample Output 2
every man for himself!
Sample Input 3
3
1 1
2 1 2
2 1 3
Sample Output 3
2 1 3
2 1 3
Comments
what is a WA (Presentation Error)???
It can mean one of many things.
Of course, outputting
every man for himself!
bypasses these checks.