#CCBCHBAHAI0000047. Mô phỏng danh sách tĩnh với Q lệnh insert/delete (Simulate a Fixed-Capacity List with Q Insert/Delete Commands)

Mô phỏng danh sách tĩnh với Q lệnh insert/delete (Simulate a Fixed-Capacity List with Q Insert/Delete Commands)

Mô phỏng danh sách tĩnh với Q lệnh insert/delete (Simulate a Fixed-Capacity List with Q Insert/Delete Commands)

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem

A fixed array has capacity CC and initial logical size nn, where

0≤n≤C.0\le n\le C.

Its current elements are a0,a1,…,an−1a_0,a_1,\ldots,a_{n-1}. Then QQ commands are processed in their given order.

There are two command types:

  • I p x: insert xx at index pp. The command is valid exactly when
0≤p≤nandn<C.0\le p\le n\quad\text{and}\quad n<C.

If valid, old elements at indices p,p+1,…,n−1p,p+1,\ldots,n-1 move one position right, xx is placed at pp, and nn increases by 11. Otherwise the command is ignored.

  • D p: delete the element at index pp. It is valid exactly when
0≤p<n.0\le p<n.

If valid, elements to the right move one position left and nn decreases by 11. Otherwise the command is ignored.

After all QQ commands, print the final logical size and the remaining elements.

Input

The first line contains integers C,n,QC,n,Q. The second line contains the initial nn integers and may be empty when n=0n=0. Each of the next QQ lines contains one command I p x or D p.

Output

Print the final logical size nn on the first line. If n>0n>0, print the current array on the second line.

Subtask

Subtask 1 (100 points): 1≤C≤20001\le C\le2000; 0≤n≤C0\le n\le C; 1≤Q≤50001\le Q\le5000; ∣ai∣,∣x∣≤109|a_i|,|x|\le10^9; ∣p∣≤109|p|\le10^9.

Example

Input

5 3 5
10 20 30
I 1 15
D 2
I 3 40
I 4 50
I 0 99

Output

5
10 15 30 40 50

Explanation

After the first four commands, the array is 10 15 30 40 50 and is full because n=C=5n=C=5. The final command I 0 99 is ignored because no capacity remains.