#CCBCHBAHAI0000074. Chèn x sau lần xuất hiện đầu tiên của y (Insert x After the First Occurrence of y)
Chèn x sau lần xuất hiện đầu tiên của y (Insert x After the First Occurrence of y)
Insert x After the First Occurrence of y (Chèn x sau lần xuất hiện đầu tiên của y)
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem
A static array has capacity and current logical size , where . The active sequence is . Given integers and , define
If is empty, leave the array unchanged. If is nonempty but , the array is full, so leave it unchanged. Otherwise let and insert immediately after position . The new size is , with
$$b_i=a_i\ (0\le i\le p),\qquad b_{p+1}=x,\qquad b_i=a_{i-1}\ (p+2\le i\le n).$$Print the final logical size and array.
Input
The first line contains and . The second line contains integers . The third line contains and .
Output
Print the final logical size on the first line and the active array elements on the second line.
Subtask
Subtask 1 (20 points): , .
Subtask 2 (30 points): , .
Subtask 3 (50 points): , .
Example
Input
8 6
4 2 7 2 9 5
100 2
Output
7
4 2 100 7 2 9 5
Explanation
The sample follows the mathematical definition above.