All problems

Problem 584

Merge In Between Linked Lists

Medium · 20 pts · Linked List

Problem

You are given two linked lists, LIST1 with N nodes and LIST2 with M nodes, and two positions a <= b (counted from 0). Remove the nodes of LIST1 from position a to position b inclusive, and put the whole of LIST2 in their place. Print the resulting list. Find the node just before position a and the node just after position b, then connect the first to the head of LIST2 and the tail of LIST2 to the second.

Input

The first line contains N, M, a and b. The second line contains LIST1. The third line contains LIST2.

Output

Print the resulting list from head to tail, separated by spaces.

Constraints

3 <= N <= 10000; 1 <= M <= 10000; 1 <= a <= b < N - 1

Example input

6 3 3 4
10 1 13 6 9 5
100 101 102

Example output

10 1 13 100 101 102 5

Explanation

LIST1 is 10 1 13 6 9 5 and positions 3 to 4 hold 6 and 9. Replacing them with LIST2 = 100 101 102 gives 10 1 13 100 101 102 5.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Double a Number Represented as a Linked List Next: Insert Greatest Common Divisors in a Linked List