#C1252. Merge and Sort Lists

    ID: 41956 Type: Default 1000ms 256MiB

Merge and Sort Lists

Merge and Sort Lists

You are given two lists of integers. Your task is to merge the two lists and output a single list that is sorted in non-decreasing order.

The input consists of two lines. The first line contains zero or more integers separated by spaces representing the first list. The second line contains zero or more integers separated by spaces representing the second list. If a line is empty, it represents an empty list.

The output should be a single line containing the merged and sorted list with the numbers separated by a single space. If the merged list is empty, print an empty line.

Note: The sorting order must follow the natural numerical order. The solution should implement the merging and sorting functionality efficiently.

Mathematically, if the two lists are \(A\) and \(B\), then the merged list \(C\) is defined as:

\[ C = sort(A \cup B) \quad \text{(in non-decreasing order)} \]

inputFormat

The input is read from standard input (stdin) and consists of exactly two lines:

  • Line 1: A sequence of zero or more space-separated integers representing the first list.
  • Line 2: A sequence of zero or more space-separated integers representing the second list.

An empty line indicates an empty list.

outputFormat

The output is written to standard output (stdout) and should be a single line containing the merged and sorted list. The integers should be separated by a single space. If the resulting list is empty, output an empty line.

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