cswork / OAOpen practice workspace

OpenAIOA #3

Chat Event Counts in Recent Window

Estimated MediumJudge-ready

Topics (AI-labelled)IteratorsHashingTwo Pointers

Process EVENT and COUNT in input order. COUNT u c t counts only previously processed events with the same user and channel whose timestamps lie in the closed interval [t−15,t]. Timestamps are not guaranteed to be increasing, and events that appear later in the input must not be counted early; duplicate events are counted individually.

Input

The first line contains q, followed by q lines EVENT user chat timestamp or COUNT user chat timestamp. This site uses 1≤q≤100000; user and chat are 1..20 ASCII letters, digits, or underscores; 0≤timestamp≤10⁹, in minutes.

Output

First output the number of COUNT commands p, then output the p query answers in order, one per line. If there is no COUNT, output only 0.

Example 1

Input:

4
EVENT u c 0
EVENT u c 10
COUNT u c 15
COUNT u c 16

Output:

2
2
1

Example 2

Input:

4
EVENT u c 50
EVENT u c 0
COUNT u c 15
COUNT u c 50

Output:

2
1
1

Example 3

Input:

5
COUNT u c 3
EVENT u c 3
EVENT v c 3
EVENT u d 3
COUNT u c 3

Output:

2
0
1

Example notes

In Example 1 the query results are 2, 1; the endpoint 15 minutes earlier is included. In Example 2 the timestamps are out of order and future times are not counted, giving 1, 1. In Example 3 later events do not affect earlier queries, giving 0, 1.

Editorial

Loading solution…