Time Travel and Multiset

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.

Medium6Dynamic programmingBinary searchPrefix sumArrayInterviewNo attempts yetTime limit2sMemory limit512 MB

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 (1N1000001 \le N \le 100\,000).

Each of the next NN lines contains one query as three positive integers aia_i, tit_i, xix_i (1ai31 \le a_i \le 3, 1ti,xi1091 \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.