#C14996. Merge Two Sorted Lists

    ID: 44706 Type: Default 1000ms 256MiB

Merge Two Sorted Lists

Merge Two Sorted Lists

You are given two sorted lists. Your task is to merge these two lists into a single sorted list without using any built-in sorting functions.

Formally, given two lists \(A = [a_1, a_2, \dots, a_n]\) and \(B = [b_1, b_2, \dots, b_m]\) where both lists are sorted in non-decreasing order, produce the merged list \(C\) which is also in non-decreasing order.

Note: Duplicate elements should be preserved in the merged list.

inputFormat

The input is read from standard input (stdin) with the following format:

  1. The first line contains an integer (n), representing the number of elements in the first sorted list.
  2. The second line contains (n) space-separated integers in non-decreasing order (if (n = 0), this line will be empty).
  3. The third line contains an integer (m), representing the number of elements in the second sorted list.
  4. The fourth line contains (m) space-separated integers in non-decreasing order (if (m = 0), this line will be empty).

outputFormat

Print the merged sorted list as space-separated integers on a single line to standard output (stdout). If the merged list is empty, print nothing.## sample

0

0