Each student has a list of targets, initially having one known target.
For every round in the fight, each student in the order
There may be multiple occurrences of the same student in a student's list of targets. If the target student is on the list multiple times, only the first occurrence should be removed.
When all people have finished throwing or doing nothing for the round, students that had snowballs thrown at them this round will add whoever threw a snowball at them to the end of their list, in increasing order. For example, if students
This will be repeated for
Determine the last student each student threw a snowball to.
Constraints
For this problem, you will be required to pass all the samples in order to receive points. In addition, you must pass all previous subtasks to earn points for a specific subtask.
Subtask 1 [4/15]
Subtask 2 [11/15]
No additional constraints.
Input Specification
The first line will contain
The second and last line will contain
Output Specification
Output
Sample Input
4 3
4 1 1 2
Sample Output
3 1 1 2
Explanation
In the first round, student
The new target list looks like
In the second round, student
The new target list looks like
In the third round, student
Comments