#C11453. Integer List Management

    ID: 40771 Type: Default 1000ms 256MiB

Integer List Management

Integer List Management

You are given a list that initially is empty. You need to implement a data structure to manage non-negative integers efficiently. The data structure supports the following operations:

  • insert x: Insert a non-negative integer \(x \in \mathbb{Z}_{\ge 0}\). If \(x\) already exists, increase its count by 1.
  • delete x: Delete one occurrence of integer \(x\) if it exists. If the count becomes 0, remove \(x\) completely.
  • query x: Output the current count of \(x\) in the list.

The input will consist of several commands. For each query command, you must output an integer denoting the current count of the queried number.

Formally, if we denote by \(c(x)\) the count of number \(x\) in the list, the operations are defined as follows: \[ \begin{aligned} \text{insert } x &:& c(x) &\leftarrow c(x) + 1, \\ \text{delete } x &:& c(x) &\leftarrow \max(c(x) - 1, 0), \\ \text{query } x &:& \text{Output } c(x). \end{aligned} \]

Your task is to process the operations given via standard input (stdin) and print the required outputs for the query commands to standard output (stdout).

inputFormat

The first line contains an integer \(T\) denoting the number of operations. Each of the next \(T\) lines contains an operation in one of the following formats:

  • insert x
  • delete x
  • query x

Here, \(x\) is a non-negative integer.

outputFormat

For each query operation, output a single line with the count of \(x\) in the list.

## sample
6
insert 3
insert 3
query 3
query 5
delete 3
query 3
2

0 1

</p>