This page is still under construction.

Parts of this page are still being built. What you see may change.

Time Travel and Multiset

Interview

Time limit2sMemory limit512 MB

Summary
Process insert, delete, and count operations on a time-indexed multiset, where each value's count at time t depends on prior operations with time at most t.
Level

Medium6 of 10

Topics
Dynamic programming, Binary search, Prefix sum, Array
Solved
No attempts yet

Problem

Seonggwan built a time machine. This is an algorithm problem, so instead of doing something impressive with it he decided to apply time travel to a multiset.

A multiset with time travel supports three operations.

  1. Go to time tt and put one copy of the integer xx into the multiset.
  2. Go to time tt and take one copy of the integer xx out of the multiset. At least one copy of xx is guaranteed to be present at time tt.
  3. Print how many copies of the integer xx the multiset holds at time tt.

An integer put in at time tt stays from time tt onward, and an integer taken out at time tt is gone from time tt onward. So the number of copies of xx at time tt is the number of already processed type 1 operations on xx whose time is at most tt, minus the number of already processed type 2 operations on xx whose time is at most tt.

For example, suppose two copies of the integer 1 are put in at time 2 and one copy is taken out at time 5. The integer 1 then has two copies from time 2 to time 4 and one copy from time 5 onward. If one more copy is taken out at time 4, the integer 1 has two copies from time 2 to time 3, one copy at time 4, and none from time 5 onward. In that state an operation that takes the integer 1 out at time 5 never appears in the input, because no copy exists at that moment.

Operations are processed in the order given in the input. The answer to a type 3 operation reflects only the type 1 and type 2 operations that come before it.

Write a program that behaves as described above.

Input

The first line contains the number of queries NN (1≤N≤100 0001 \le N \le 100\,000).

Each of the next NN lines contains one query as three positive integers aia_i, tit_i, xix_i (1≤ai≤31 \le a_i \le 3, 1≤ti,xi≤1091 \le t_i, x_i \le 10^9). aia_i is the operation type, and tit_i and xix_i are the tt and xx from the statement.

Output

For every query with ai=3a_i = 3, print its answer on its own line.

Examples2

  1. Example 1

    Input
    6
    1 1 5
    3 5 5
    1 2 5
    3 6 5
    2 3 5
    3 7 5
    
    Expected output
    1
    2
    1
    
  2. Example 2

    Input
    3
    1 1 1
    2 2 1
    3 3 1
    
    Expected output
    0