Under construction

Still being built. Things may change

Merging Two Sorted Arrays

Interview

Time limit1.5sMemory limit256 MB

Summary
Merge two sorted arrays into one sorted sequence with a two-pointer walk.
Level

Easy3 of 10

Topics
Two pointers, Array
Solved
No attempts yet

Problem

You are given two arrays AA and BB, each sorted in non-decreasing order. Write a program that combines all of their elements and prints them in non-decreasing order.

Input

The first line contains the size NN of array AA and the size MM of array BB, separated by a space. (1≤N,M≤1061 \le N, M \le 10^6)

The second line contains the NN elements of array AA, and the third line contains the MM elements of array BB, separated by spaces. Every element is an integer whose absolute value is at most 10910^9, and both arrays are already sorted in non-decreasing order.

Output

On the first line, print the combined elements of both arrays in non-decreasing order, separated by single spaces. If a value appears several times, print it as many times as it appears.

Examples3

  1. Example 1

    Input
    2 2
    3 5
    2 9
    
    Expected output
    2 3 5 9
    
  2. Example 2

    Input
    2 1
    4 7
    1
    
    Expected output
    1 4 7
    
  3. Example 3

    Input
    4 3
    2 3 5 9
    1 4 7
    
    Expected output
    1 2 3 4 5 7 9