Kurt has built a cool new service called Gigatron. He's not sure how well it's performing relative to its predecessor, Megatron. Your job is to help him determine how much Gigatron is lagging.
Here's a simplified model of how Gigatron works. Gigatron has partitions, numbered through . Each partition corresponds to a queue of events that need to be processed. We define the "lag" of a partition to be the number of active events in its corresponding queue.
There are six types of actions that can happen:
- Events can be added to a single partition.
- Events can be added to all partitions.
- Gigatron can process events on a single partition.
- Gigatron can process events on all partitions.
- Kurt wants to know the lag of a specific partition.
- Kurt wants to know the maximum lag over all partitions.
When Gigatron is initialized, all partitions have zero lag. Help Kurt analyze Gigatron's performance!
Constraints
There is at least one event of the form LAG p
or MAXLAG
.
Input Specification
The first line of input contains a single integer, . The number of actions is .
Each of the next lines contains a line either of the form
ADD p x
, ADDALL x
, or PROCESS p x
, PROCESSALL x
, LAG p
, or MAXLAG
.
If the line is of the form ADD p x
, partition has additional events to process.
If the line is of the form ADDALL x
, all partitions have additional events to process.
If the line is of the form PROCESS p x
, Gigatron processes events from partition . If
is greater than the number of events in partition 's queue, all events are processed.
If the line is of the form PROCESSALL x
, Gigatron processes events from every partition. If
is greater than the number of events in some partition's queue, all events are processed from that queue.
If the line is of the form LAG p
, print the lag of partition .
If the line is of the form MAXLAG
, print the maximum lag over all partitions.
Output Specification
For every LAG
line, print Gigatron's lag at the time of the request. For every MAXLAG
line, print the maximum
lag over all partitions.
Print each lag amount on a separate line.
Sample Input
15
LAG 39
MAXLAG
ADDALL 17
LAG 42
MAXLAG
PROCESS 1 2
LAG 1
MAXLAG
PROCESSALL 1
LAG 39
MAXLAG
PROCESSALL 100
MAXLAG
ADD 17 1
MAXLAG
Sample Output
0
0
17
17
15
17
16
16
0
1
Sample Explanation
Gigatron starts out with no lag over all partitions. The third event causes all partitions to have a lag of 17. After processing 2 events from partition 1, partition 1 has a lag of 15. After processing 1 event from all partitions, the maximum lag is 16 and all partitions except for partition 1 have a lag of 16. After attempting to process 100 events from all partitions, the maximum lag is 0. After adding one event to partition 17, Gigatron ends with a maximum lag of 1.
Comments