Merge two sorted arrays

Merge two arrays that are already sorted in ascending order into one sorted array, without using a sort function.

Reported in: LTIMindtree (2025), Cognizant GenC (memory-based)

Input

Line 1: N. Line 2: N sorted integers. Line 3: M. Line 4: M sorted integers.

Output

The merged array, space-separated.

Constraints

1 ≤ N, M ≤ 10^5.

Example 1

Input:
3
1 4 7
4
2 3 8 9

Output:
1 2 3 4 7 8 9

Example 2

Input:
2
5 5
1
5

Output:
5 5 5

Hint: Two pointers: always take the smaller front element.

All coding practice