#C7239. Mark Integer in List Insertion Problem
Mark Integer in List Insertion Problem
Mark Integer in List Insertion Problem
You are given a list of n integers. Your task is to insert a given integer x into the list at the specified position m (0-indexed). If m is less than or equal to n, then insert x at index m shifting the subsequent elements to the right. If m is greater than n, append x at the end of the list.
The process can be described by the following formula:
$$res = \begin{cases} \text{initial\_list}[0:m] \oplus [x] \oplus \text{initial\_list}[m:n] & \text{if } m \le n, \\ \text{initial\_list} \oplus [x] & \text{if } m > n. \end{cases} $$Print the final modified list as space-separated integers.
inputFormat
The input consists of three lines:
- The first line contains a single integer
n
representing the number of integers in the list. - The second line contains
n
space-separated integers. - The third line contains two space-separated integers:
x
(the integer to insert) andm
(the position at which to insertx
).
outputFormat
Output the updated list in one line as space-separated integers.
## sample5
1 2 3 4 5
100 2
1 2 100 3 4 5