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