QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#15334. Thieves and Prisons

الإحصائيات

There are $n$ thieves and $k$ prisons. A thief is either on the run or caught in a prison. Initially all thieves are on the run.

A thief who is on the run can be caught by the police, and then ends up in one of the prisons. A thief who is on the run can also open the gate of a prison. Then every thief in that prison is released from the prison. It would be pointless to open the gate of an empty prison, so that never happens.

You are given a list of $m$ events of the form "thief $x$ has been caught" or "thief $x$ has opened the gate of a prison". Your task is to find a prison assignment that corresponds to the events, or determine that it is not possible.

Input

The first input line has three integers $n$, $k$ and $m$: the number of thieves, prisons and events. The thieves and prisons are numbered $1,2,\dots,n$ and $1,2,\dots,k$.

After this, there are $m$ lines that describe the events. Each event is "C x" (thief $x$ has been caught) or "O x" (thief $x$ opens the gate of a prison).

Output

Print a valid prison assignment that consists of $m$ integers: for every event the corresponding prison. If there are no solutions, print "IMPOSSIBLE".

Example

Input 1

3 2 5
C 1
C 2
O 3
O 2
C 1

Output 1

1 2 2 1 1

Input 2

1 1 1
O 1

Output 2

IMPOSSIBLE

Subtasks

Subtask 1 (8 points)

  • $1 \le n,m \le 10$
  • $k=2$

Subtask 2 (13 points)

  • $1 \le n,k,m \le 10^5$
  • $n=k$

Subtask 3 (14 points)

  • $1 \le n,m \le 10^5$
  • $k=2$

Subtask 4 (18 points)

  • $1 \le n,k,m \le 500$

Subtask 5 (47 points)

  • $1 \le n,k,m \le 10^5$
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.