#include<stdio.h>
#include<stdlib.h>
struct Node{
    int data;
    struct Node *prev, *next;
};
struct Node* insertEnd(struct Node* head, int val){
    struct Node*newNode=malloc(sizeof(struct Node));
    newNode->data =val;
    newNode->next=NULL;
    if(!head){
        newNode->prev=NULL;return newNode;}
        struct Node* temp=head;
        while(temp->next)temp=temp ->next;
        temp->next=newNode;newNode->prev=temp;
        return head;
    }
    struct Node* deletevalue(struct Node * head, int x, int *found){
        struct Node* temp=head;
        while(temp){
            if(temp->data == x){
                *found =1;
                if(temp->prev) temp->prev->next=temp->next;
                else head = temp->next;
                if(temp->next)temp->next->prev=temp->prev;
                struct Node* del = temp;temp=temp->next;
                free(del);
            }else temp = temp->next;
        }
        return head;
    }
    void printList(struct Node* head){
        if(!head)return;
        while(head){
            printf("%d ",head->data);
            head= head->next;
        }
    }
    int main(){
        int n, x;
        scanf("%d", &n);
        struct Node* head=NULL;
        for(int i=0,val;i<n;i++){
            scanf("%d", &val);
            head = insertEnd(head,val);
        }
        scanf("%d", &n);
        int found=0;
        head=deletevalue(head,x,&found);
        if(!found)printf("Node not found");
        else printList(head);
        return 0;
    }
    
    
    
    
}