Crime House (Small)
Time limit5sMemory limit512 MB
Assign each masked passage to a person so inside and outside states stay valid and report the smallest possible final occupancy, or CRIME TIME.
- Level
Medium6 of 10
- Topics
- Backtracking, Simulation
- Solved
- No attempts yet
Problem
You work for the police, and you have found a house that people use for committing crimes. Everyone calls it the Crime House. One day you mount a camera above the front door and record everyone who passes through it.
You do not know how many people were inside when the day began. You are also not sure whether the front door is the only way in and out. The people going in and out are criminals, so some of them wear a mask, and the recording does not show who those people are.
Sometimes you can guess who was behind a mask. Suppose criminal 5 enters, then a masked person leaves, then criminal 5 enters again. Either the masked person was criminal 5, or the house has another way out.
Someone who is already inside cannot enter, and someone who is already outside cannot leave. At the end of the day, after the house closes its doors for the night, you watch the recording. You are an optimist, so you want to know whether the recording can be explained with the front door as the only entrance and exit. If it can, you want the smallest number of people who could be inside at the end of the day.
Input
The first line holds the number of test cases . The test cases follow. Each test case starts with a line holding one integer , the number of times people pass through the front door during the day. The next lines hold one passage each, in the order they were recorded.
Each of those lines holds a single character, E or L, then a space, then an integer . E means someone entered through the front door and L means someone left through it. If is greater than zero, the person with that identifier passed through. If is zero, the person who passed through wore a mask and you do not know who it was. A masked person can be anyone, including someone whose identifier never appears in the recording.
Limits
Output
For each test case, print one line in the form Case #x: y, where x is the test case number starting from 1. If it is possible that the front door is the only entrance and exit, y is the smallest number of people who could be inside the house at the end of the day. If it is impossible, y is CRIME TIME.