#ds605. 序列维护

序列维护

Sequence Maintenance

Problem Description

You are to maintain nn sequences p1,p2,…,pnp_1, p_2, \dots, p_n, which are initially all empty. Then you must support qq operations:

  1. 1 x y: append the number yy to the end of sequence pxp_x. The indices of every sequence start from 00.
  2. 2 z: for every non-empty sequence pip_i, compute the element pi, z mod ∣pi∣p_{i,\, z \bmod |p_i|}, and output the sum of all such elements, where ∣pi∣|p_i| denotes the number of elements in sequence pip_i.

Input Format

The first line contains two integers n,qn, q ($1 \leq n \leq 2 \times 10^5,\ 1 \leq q \leq 4 \times 10^5$).

The next qq lines each describe one operation. It is guaranteed that 1≤x≤n, 1≤y,z≤1091 \leq x \leq n,\ 1 \leq y, z \leq 10^9.

Output Format

For each query operation, output one number: the answer.

Sample Input

3 9
2 123
1 1 1
2 123
1 1 2
2 123
1 1 3
2 123
1 2 1
2 123

Sample Output

0
1
2
1
2

Constraints

  • 1≤n≤2×1051 \leq n \leq 2 \times 10^5
  • 1≤q≤4×1051 \leq q \leq 4 \times 10^5
  • 1≤x≤n, 1≤y,z≤1091 \leq x \leq n,\ 1 \leq y, z \leq 10^9 for every operation