#C3419. Course Registration Assignment

    ID: 46844 Type: Default 1000ms 256MiB

Course Registration Assignment

Course Registration Assignment

You are tasked with developing a system to assign students to courses based on their preferences. Each course has a fixed capacity, and students should be assigned to the highest-preference course that still has an available slot. If a student cannot be assigned to any of the courses in his/her preference list, they will not be assigned to any course.

The input is given via standard input (stdin) and the output should be sent to standard output (stdout). The format of the input is described below. You are required to follow the input/output format exactly.

In this problem, if you need to include formulas, use LaTeX format. For instance, to denote the capacity of the i-th course, you might write \( C_i \), and to denote the number of students assigned to the i-th course, you can write \( A_i \).

inputFormat

The input is read from stdin and is formatted as follows:

  • The first line contains an integer \( m \), the number of courses.
  • The second line contains \( m \) space-separated integers representing the course capacities \( C_1, C_2, \dots, C_m \).
  • The third line contains an integer \( n \), the number of students.
  • The following \( n \) lines each represent a student's course preferences. Each line contains a space-separated list of course indices in the order of the student's preference. If a student has no preferences, the line will be blank.

It is guaranteed that \( 1 \le m \le 1000 \) and \( 0 \le n \le 10000 \). Course indices start from 1.

outputFormat

The output should be a single line containing \( m \) space-separated integers. The \( i\)-th integer represents the number of students assigned to course \( i \). Output must be written to stdout.

## sample
3
2 1 1
4
1 2 3
2 1 3
3 1
1 3
2 1 1