#K76142. Merge and Sort Lists

    ID: 34577 Type: Default 1000ms 256MiB

Merge and Sort Lists

Merge and Sort Lists

You are given two lists of integers via standard input. Each list is provided on a separate line, with the integers separated by spaces. Your task is to merge the two lists and then sort the resulting list in non-decreasing order using the Merge Sort algorithm. You are not allowed to use any built-in sort functions.

The merge sort algorithm is a divide and conquer algorithm that divides the input array into two halves, recursively sorts the two halves, and then merges the sorted halves. The main challenge is implementing the merge procedure and ensuring that the algorithm works efficiently even if one or both inputs are empty.

Note: If one of the inputs is an empty line, treat it as an empty list.

inputFormat

The input consists of two lines:

  • The first line contains a sequence of integers separated by spaces representing the first list. This line may be empty.
  • The second line contains a sequence of integers separated by spaces representing the second list. This line may be empty.

Input is read from stdin.

outputFormat

Output a single line containing the merged and sorted list of integers separated by a single space. Output is written to stdout.

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

</p>