#K61087. Merge Sorted Arrays

    ID: 31231 Type: Default 1000ms 256MiB

Merge Sorted Arrays

Merge Sorted Arrays

You are given two sorted arrays of integers. Your task is to merge these two arrays into a single sorted array.

Formally, given two arrays A and B that are sorted in non-decreasing order, merge them into one array C that is also sorted in non-decreasing order. Mathematically, if A has m elements and B has n elements, then the merged array C should satisfy:

\( C = merge(A, B) \), where \( |C| = m+n \)

You need to implement this functionality so that it reads from stdin and outputs the result to stdout as specified below.

inputFormat

The input is given via stdin and consists of four lines:

  1. The first line contains an integer m, the number of elements in the first array.
  2. The second line contains m space-separated integers representing the first sorted array. If m is 0, this line may be empty.
  3. The third line contains an integer n, the number of elements in the second array.
  4. The fourth line contains n space-separated integers representing the second sorted array. If n is 0, this line may be empty.

outputFormat

Output a single line containing the merged sorted array. The array elements should be space-separated.

## sample
3
1 3 5
3
2 4 6
1 2 3 4 5 6