// editor4
#include<stdio.h>
#include<stdlib.h>

struct Node {
    int data;
    struct Node* prev;
    struct Node* next;
};
struct Node* head = NULL;
struct Node* tail = NULL;

void createList(int n) {
    if (n <= 0) {
        return;
    }
    struct Node* newNode;
    int data;
    
    for (int i = 0; i < n; i++) {
        newNode =(struct Node*)malloc(sizeof(struct Node));
        printf("Enter data for node %d; ", i + 1);
        scanf("%d", &data);
        newNode->data = data;
        newNode->prev = NULL;
        newNode->next = NULL;
        
        if (head == NULL) {
            head = newNode;
            tail = newNode;
        }else{
            tail->next = newNode;
            newNode->prev = tail;
            tail = newNode;
        }
    }
}
int insertAfterNode(int targetID, int newID) {
    struct Node* temp = head;
    while (temp != NULL && temp->data != targetID) {
        temp = temp->next
    }
    if (temp == NULL) {
        retrun 0;
    }
    struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
    newNode->data = newID;
    newNode->prev = temp;
    newNode->next = temp->next;
    
    if(temp->next != NULL) {
        temp->next->prev = newNode;
    }else{
        tail = newNode;
    }
    temp->next = newNode;
    
    return 1;
}
void displayList(){
    struct Node* temp = head;
    while (temp != NULL) {
        printf("%d",temp->data);
        temp = temp->next;
    }
    printf("\n");
}
int main(){
    int n, targetID, newID;
    
    printf(" ");
    scanf("%d", &n);
    
    if(n<0) {
        printf("Invalid input\n");
        return 1;
    }
    head = NULL;
    tail = NULL;
    createList(n);
    
    printf(" ");
    scanf("%d", &targetID);
    printf(" ");
    scanf("%d", &newID);
    printf(" ");
    displayList();
    
    if(n==0 || insertAfterNode(targetID, newID) == 0) {
        printf("Invalid input\n");
    }else{
        printf(" ");
        displayList();
    }
    struct Node* temp = head;
    while (temp != NULL) {
        struct Node* toFree = temp;
        temp = temp->next;
        free(to)
    }
}