[3:28 pm, 25/8/2025] Hemalatha JSR: #include <stdio.h>
#include <stdlib.h>

struct Node {
    int data;
    struct Node *prev, *next;
};

struct Node* createNode(int data) {
    struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
    newNode->data = data;
    newNode->prev = newNode->next = NULL;
    return newNode;
}

void append(struct Node** head, int data) {
    struct Node* newNode = createNode(data);
    if (*head == NULL) {
        *head = newNode;
        return;
    }
    struct Node* temp = *head;
    while (temp->next) temp = temp->next;
    temp->next = newNode;
    newNode->prev = temp;
}

struct Node* mergeLists(struct Node* head1, struct Node* head2) {
    struct Node* merged = NULL;
    while (head1 && head2) {
        if (head1->data <= head2->data) {
            append(&merged, head1->data);
            head1 = head1->next;
        } else {
            append(&merged, head2->data);
            head2 = head2->next;
        }
    }
    while (head1) {
        append(&merged, head1->data);
        head1 = head1->next;
    }
    while (head2) {
        append(&merged, head2->data);
        head2 = head2->next;
    }
[3:28 pm, 25/8/2025] Hemalatha JSR: return merged;
}

void printList(struct Node* head) {
    while (head) {
        printf("%d ", head->data);
        head = head->next;
    }
    printf("\n");
}

int main() {
    int n1, n2, val;
    scanf("%d", &n1);
    if (n1 <= 0) {
        scanf("%*[^\\n]"); // Skip remaining input
    }
    struct Node* head1 = NULL;
    for (int i = 0; i < n1; i++) {
        scanf("%d", &val);
        append(&head1, val);
    }

    scanf("%d", &n2);
    struct Node* head2 = NULL;
    for (int i = 0; i < n2; i++) {
        scanf("%d", &val);
        append(&head2, val);
    }

    if (n1 <= 0 && n2 <= 0) {
        printf("Invalid input\n");
        return 0;
    }

    struct Node* merged = mergeLists(head1, head2);
    printList(merged);

    return 0;
}