#P4896. Teacher's Game Surveillance

    ID: 18137 Type: Default 1000ms 256MiB

Teacher's Game Surveillance

Teacher's Game Surveillance

There are three handsome teachers (A), (B), and (C) and five students (a), (b), (c), (d), and (e). The system receives a series of messages indicating events in a computer room:

  • When a student starts playing games, a message in the format "XX started playing games!" is displayed.
  • When a student stops playing games, a message in the format "XX stopped playing games!" is displayed.
  • When a teacher comes to inspect the room, a message in the format "XX came!" is displayed.
  • When a teacher leaves, a message in the format "XX left!" is displayed.
Whenever a teacher comes (i.e. a message ending with "came!" from \(A\), \(B\), or \(C\)), if there is at least one student currently playing games then output the name of the student who started playing first and is still playing. If no student is playing at that moment, output nothing for that event.

The input starts with an integer (n) representing the number of events, followed by (n) lines each containing one of the messages described above.

inputFormat

The first line contains an integer (n) ((1 \leq n \leq 10^5)) representing the number of events. Each of the next (n) lines contains a string that represents an event, which can be one of the following formats:

  • "XX started playing games!" where XX is one of the students: a, b, c, d, e.
  • "XX stopped playing games!" where XX is one of the students.
  • "XX came!" where XX is one of the teachers: A, B, C.
  • "XX left!" where XX is one of the teachers.
It is guaranteed that the events are valid.

outputFormat

For each event where a teacher comes (i.e. message ending with "came!" from (A), (B), or (C)), if there is at least one student currently playing games, output the name (a single lowercase letter) of the student who started playing first and is still playing. Each such output should be printed on a new line. If no student is playing at that moment, output nothing for that event.

sample

6

a started playing games!
A came!
a stopped playing games!
b started playing games!
B came!
C came!
a

b b

</p>