#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>typedef struct Node {int data;struct Node* next;
} Node;Node* newNode(int data);
Node* mergeList(Node* L1, Node* L2) {Node* head = newNode(-1);Node* last = head;Node* p = L1 -> next, *q = L2->next;while(p!=NULL && q!=NULL){if(p->data < q->data){last -> next = newNode(p->data);p = p->next;}else{last -> next = newNode(q->data);q = q->next;}last = last->next;}while (p!=NULL){last -> next = newNode(p->data);p = p->next;last = last->next;}while (q!=NULL){last -> next = newNode(q->data);q = q->next;last = last->next;}return head;}Node* newNode(int data) {Node* node = (Node*)malloc(sizeof(Node));node -> data = data;node -> next = NULL;return node;
}int main() {int n, m, data;scanf("%d %d", &n, &m);Node* L1 = newNode(-1);Node* last1 = L1;for (int i = 0; i < n; i++) {scanf("%d", &data);last1 -> next = newNode(data);last1 = last1 -> next;}Node* L2 = newNode(-1);Node* last2 = L2;for (int i = 0; i < m; i++) {scanf("%d", &data);last2 -> next = newNode(data);last2 = last2 -> next;}Node* merged = mergeList(L1, L2);Node* p = merged -> next;while (p != NULL) {printf("%d", p -> data);if (p -> next != NULL) {printf(" ");}p = p -> next;}printf("\n");return 0;
}