SDE Path

Merge Two Sorted Linked Lists

Easy

Merge Two Sorted Linked Lists

Merge two sorted singly linked lists into a single sorted linked list.

Input format

The first line contains N and M. The second line contains N sorted values (list 1); the third line contains M sorted values (list 2).

Output format

Merge the two sorted lists and print the merged list.

Constraints

  • Values fit in a 64-bit signed integer
  • Trailing whitespace and a trailing newline are ignored by the judge

Read from stdin, write to stdout. Sample cases below show the exact format.

Sample cases

Example 1
Input
3 3
1 2 4
1 3 4
Expected output
1 1 2 3 4 4
Example 2
Input
1 1
5
2
Expected output
2 5