Simulate the behavior of the queues of a supermarket. Initially, there are queues (), each one with some customers. Afterwards, two events can happen:
A costumer arrives to a queue: If the queue is between 1 and , the customer goes to the end of that queue. Otherwise, the event is ignored.
A customer leaves a queue: If the queue is between 1 and , and that queue is not empty, the first customer of that queue leaves it. Otherwise, the event is ignored.
Input starts with the number of queues
(a strictly positive natural number). Follow
lines, one per queue, each one with its customers (a word), in the order
in which they arrived to que queue. Follow an empty line and the
description of several events, one per line: the word
“ENTERS” followed by the customer (a word) and the queue
(an integer number); or the word “LEAVES” followed by the
queue (an integer number).
First, print the name of the customers that leave the queues, in the order that they departed. Afterwards, print the final content of the queues, using the order in which the customers would leave. Follow the format of the example.
Input
4 Cristina Tomas Francesc Damia Domenec Teresa Toni Carles LEAVES 1 LEAVES 1 ENTERS Amalia 4 LEAVES 2 LEAVES 1 ENTERS Leo 1 ENTERS Maria 3 LEAVES 4 LEAVES 4 LEAVES 3 ENTERS Carme 4 LEAVES 2 LEAVES -1 LEAVES 2
Output
DEPARTS ------- Cristina Tomas Francesc Teresa Toni Maria Damia Domenec FINAL CONTENTS -------------- queue 1: Leo queue 2: queue 3: queue 4: Carles Amalia Carme