Array

Start with array a_i = i, apply up to 300000 queries that reverse or rotate subarrays and ask for range min, max, sum, value at index, or index of a value, then print the final array.

Hard9ArrayImplementationSegment treeMathNo attempts yetTime limit1sMemory limit512 MB

Problem

Beomsu and Sangsu, two brothers, play with an array. Their array A=[a1,,aN]A = [a_1, \ldots, a_N] has size NN, and at the start ai=ia_i = i for every ii (1iN1 \le i \le N). The brothers receive QQ queries and handle them one at a time in the given order. Each query is one of the four kinds below.

1 l r (1lrN1 \le l \le r \le N): find the minimum, the maximum and the sum of ala_l through ara_r. Then reverse ala_l through ara_r. After the reversal the array looks like this.

[a1,,al1,ar,ar1,,al+1,al,ar+1,,aN][a_1, \ldots, a_{l-1}, a_r, a_{r-1}, \ldots, a_{l+1}, a_l, a_{r+1}, \ldots, a_N]

2 l r x (1lrN1 \le l \le r \le N, N<x<N-N < x < N): find the minimum, the maximum and the sum of ala_l through ara_r. Then rotate ala_l through ara_r to the right by xx positions. If xx is negative, rotate to the left by x-x positions. When 0<xrl0 < x \le r - l, the array looks like this.

[a1,,al1,arx+1,,ar1,ar,al,al+1,,arx,ar+1,,aN][a_1, \ldots, a_{l-1}, a_{r-x+1}, \ldots, a_{r-1}, a_r, a_l, a_{l+1}, \ldots, a_{r-x}, a_{r+1}, \ldots, a_N]

The rotation stays inside the block [l,r][l, r]. A value pushed off one end of the block comes back in at the other end. Write m=rl+1m = r - l + 1 for the length of the block. Rotating right by xx has the same effect as rotating right by x+mx + m, so the result is fixed even when xx is negative or xm|x| \ge m.

3 i (1iN1 \le i \le N): find the value of aia_i.

4 x (1xN1 \le x \le N): find the index ii with ai=xa_i = x.

Once a query changes the array, every later query works on the changed array. Print the value found by each query, and print the array as it stands after all queries are handled.

Input

The first line has the array size NN and the number of queries QQ, separated by a space. (1N3000001 \le N \le 300000, 1Q3000001 \le Q \le 300000)

Each of the next QQ lines has one query in one of the four formats above.

Output

Print one line per query holding the values found, separated by spaces. A query of kind 1 or kind 2 prints the minimum, the maximum and the sum in that order. A query of kind 3 or kind 4 prints the single value found.

On the last line, line Q+1Q+1, print the values of the array after all queries are handled, separated by spaces.

Hint

In the first example the array changes in this order.

[1,2,3,4,5][1,4,3,2,5][1,4,5,3,2][5,1,4,3,2][1, 2, 3, 4, 5] \to [1, 4, 3, 2, 5] \to [1, 4, 5, 3, 2] \to [5, 1, 4, 3, 2]