#CCBCHBAHAI0000056. Bài kiểm tra cuối Ch32 - Array Mastery (Chapter 32 Final Test - Array Mastery)

Bài kiểm tra cuối Ch32 - Array Mastery (Chapter 32 Final Test - Array Mastery)

Chapter 32 Final Test - Array Mastery (Bài kiểm tra cuối Ch32 - Array Mastery)

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem

Maintain a fixed-capacity array of capacity CC with logical size nn, so the active sequence is a0,…,an−1a_0,\ldots,a_{n-1} and 0≤n≤C0\le n\le C.

Process QQ commands in order:

  • 1 p: print apa_p, with 0≤p<n0\le p<n.
  • 2 p x: assign ap←xa_p\leftarrow x.
  • 3: reverse the logical sequence.
  • 4 p x: insert xx before position pp, with 0≤p≤n<C0\le p\le n<C.
  • 5 p: delete position pp, with 0≤p<n0\le p<n.
  • 6 x: print the smallest index containing xx, or −1-1.
  • 7: with n>0n>0, print S=∑aiS=\sum a_i, m=min⁡aim=\min a_i, and M=max⁡aiM=\max a_i.

All positions are 0-based. Updates affect all later commands.

Input

The first line contains C,n,QC,n,Q. The second line contains the initial nn integers (empty if n=0n=0). The next QQ lines contain commands.

Output

For every command of type 1, 6, or 7, print one result line.

Subtask

Subtask 1 (20 points): 1≤C≤101\le C\le10, 1≤Q≤201\le Q\le20.

Subtask 2 (30 points): 1≤C≤1001\le C\le100, 1≤Q≤2001\le Q\le200.

Subtask 3 (50 points): 1≤C≤20001\le C\le2000, 1≤Q≤50001\le Q\le5000.

Example

Input

5 3 7
4 1 9
1 1
4 1 7
6 9
3
2 0 5
7
5 2

Output

1
3
17 1 7

Explanation

The sample follows the definitions and rules above.