#K94432. Student Class Allocation

    ID: 38640 Type: Default 1000ms 256MiB

Student Class Allocation

Student Class Allocation

In this problem, you are given nn students and mm classes, where each class can accommodate at most cc students. Each student provides a list of class preferences in order of priority. Your task is to allocate each student to a class according to their preferences. The allocation process is performed in order: for each student, assign them to the first class in their preference list that still has available capacity. If a student cannot be assigned to any of their preferred classes, then the allocation is considered impossible.

Mathematically, if we denote the capacity of each class by cc, the number of students by nn, and the number of classes by mm, then an allocation is valid if for every student i (1in)i \ (1 \le i \le n), there exists a class j (1jm)j \ (1 \le j \le m) in their preference list such that the total number of students allocated to class jj is at most cc.

If an allocation is possible, output "Possible" followed by the assignment of each student (using 1-indexed class numbers). Otherwise, output "Impossible".

inputFormat

The input is given via standard input (stdin).

The first line contains three space-separated integers: nn, mm, and cc, representing the number of students, the number of classes, and the maximum capacity of each class respectively.

This is followed by nn lines. The iith line contains a sequence of integers where the first integer kk is the number of preferences for the iith student, followed by kk distinct integers representing the student's class preferences (each integer is between 1 and mm).

outputFormat

Output the result to standard output (stdout).

If it is possible to allocate all students according to their preferences, print "Possible" on the first line, followed by nn lines each containing the allocated class (1-indexed) for the corresponding student.

If it is not possible, output "Impossible".## sample

6 3 2
3 1 2 3
2 2 3
3 1 3 2
1 3
3 2 1 3
2 3 1
Possible

1 2 1 3 2 1

</p>