#include<stdio.h>
#include<stdlib.h>
typedef struct Node{
    int data;
    struct Node *next;
    struct Node *prev;
}node;
node *head=NULL,*tail;
node create(int num){
    node *newnode=(node*)malloc(1*sizeof(node));
    newnode->data=num;
    newnode->next=NULL;
    newnode->prev=NULL;
    if(head==NULL){
        head=newnode;
        tail=newnode;
    }
    else{
        tail->next=newnode;
        newnode->prev=tail;
        tail=newnode;
    }
}
node *first,*second;
int del(int val){
    int found=0;
    first=head;
    second=head->next;
    if(first->data==val){
        found=1;
        head=head->next;
        head->prev=NULL;
        free(first);
    }
    while(second!=NULL){
        if(second->data==val){
            found=1;
            first->next=second->next;
            second->next->prev=first->next;
            free(second);
            break;
        }
        first=first->next;
        second=second->next;
    }
}
void display(){
    node *i;
    for(i=head;i!=NULL;i=i->next){
        printf("%d ",i->data);
    }
}
int main(){
    int n,num;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&num);
        create(num);
    }
    int val;
    scanf("%d",&val);
    del(val);
    if(found==0){
        printf("Node not found");
        return 0;
    }
    display();
}