Sorting by a hybrid algorithm of merge sort and quick sort

JavaScript Hard sorting

Task «Sorting by a hybrid algorithm of merge sort and quick sort»

Implement a hybrid sorting algorithm that uses quicksort to partition the array, and if the size of a subarray is less than or equal to 10, applies merge sort to that subarray. The input consists of two arrays of integers. It is necessary to merge them into one array, sort it in ascending order using the hybrid algorithm, and output the result. Constraints: the length of each array does not exceed 10^5, the elements are integers from -10^9 to 10^9.

Input Format

The first line contains an integer n — the number of elements in the first array. The second line contains n integers separated by spaces. The third line contains an integer m — the number of elements in the second array. The fourth line contains m integers separated by spaces.

Output Format

One line containing the sorted elements of the merged array, separated by spaces.

Examples

Example 1

INPUT
3 1 3 5 2 2 4
OUTPUT
1 2 3 4 5

Example 2

INPUT
1 10 1 5
OUTPUT
5 10

Example 3

INPUT
0 0
OUTPUT
main.js