#C12124. Merge Sorted Lists

    ID: 41517 Type: Default 1000ms 256MiB

Merge Sorted Lists

Merge Sorted Lists

You are given two sorted lists. Your task is to merge these two lists into one sorted list.

Let \(A\) be the first sorted list and \(B\) be the second sorted list. The merged list must be sorted in non-decreasing order.

Example:

Input:
3
1 3 5
3
2 4 6

Output: 1 2 3 4 5 6

</p>

Note: The inputs are provided via standard input (stdin) and the output should be printed to standard output (stdout).

inputFormat

The input contains four lines:

  • The first line contains an integer \(n\), the number of elements in the first list.
  • The second line contains \(n\) space-separated integers representing the first sorted list. If \(n = 0\), this line will be empty.
  • The third line contains an integer \(m\), the number of elements in the second list.
  • The fourth line contains \(m\) space-separated integers representing the second sorted list. If \(m = 0\), this line will be empty.

outputFormat

Output a single line containing the merged sorted list. The numbers should be space-separated.

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