// editor1
#include<stdio.h>
#include<stdlib.h>
typedef struct Node{
    int data;
    struct Node *next;
    struct Node *prev;
}nd;
nd *head=NULL,*tail=NULL;
void create(int num){
    nd *newnode=(nd*)malloc(1*sizeof(nd));
    newnode->data=num;
    newnode->next=NULL;
    newnode->prev=NULL;
    if(head==NULL){
        head=newnode;
        tail=newnode;
    }
    else{
        newnode->prev=head;
        tail->next=newnode;
        tail=newnode;
     
    }
}
void display(){
    nd *itr;
    for(itr=head;itr!=NULL;itr=itr->next){
        printf("%d ",itr->data);
    }
}
void delete(int x){
    nd *temp=head;
    while(temp!=NULL && temp->data!=x){
       temp=temp->next;
        
    }
    if(temp==NULL){
        printf("Node not found");
        return;
    }if(temp==head ){
        head=head->next;
        if(head!=NULL)
         head->prev=NULL;
        else
         tail=NULL;
         
    }else if(temp==tail){
        tail=tail->prev;
        tail->next=NULL;
    }else{
        temp->prev->next=temp->next;
        temp->next->prev=temp->prev;
    }
    free(temp);
    nd *ptr=head;
    while(ptr!=NULL){
        printf("%d",ptr->data);
        
    }
    display();
    
}
int main(){
    int n,num,x;
    scanf("%d",&n);
    if(n<0){
        printf("Node not found");
        return 0;
    }
    for(int i=0;i<n;i++){
      scanf("%d",&num);
      create(num);
    }
   scanf("%d",&x);
   delete(x);
    return 0;
}