The Root of Evil#11697

The Root of Evil

3 seconds
256 megabytes
Very hard

You are given a multiset a_1, a_2, \ldots, a_n consisting of numbers.

Next, you will be given types of queries:

You need to process queries. For each query of the rd type, output the required number of pairs.

Input

The first line contains an integer (1 \le n \le 10^5) — the number of elements in the initial array.

The second line contains integers a_1, a_2, \ldots, a_n (1 \le a_i \le 10^5) — the elements of the multiset.

The third line contains an integer (1 \le q \le 10^5) — the number of queries.

Each of the next lines contains a query, given as two integers (1 \le type \le 3) and such that

\begin{cases} 1 \le x \le 10^5, & \text{if } type \leq 2 \\ 2 \le x \le 10^5, & \text{if } type = 3 \end{cases}

where is the type of query and is the number in the query. It is guaranteed that there is at least one query of type .

Output

For each query of the rd type, output the required number of pairs for the given .

Examples

Example

Loading
Loading

Scoring

  1. ( points): n \le 500, q \le 500, a_i \le 500, x \le 500 in each query.

  2. ( points): a_i \le 1000, x \le 1000 in each query.

  3. ( points): there are no queries of type and .

  4. ( points): there are no queries of type .

  5. ( points): no additional constraints.