// editor1

#include<stdio.h>
#include<stdlib.h>

typedef struct Node{
    struct Node* prev;
    int data;
    struct Node* next;
}Node;

Node *head=Node *tail=NULL;

void createNode(int data){
    Node* newNode=(Node*)malloc(sizeof(Node));
    newNode->data=data;
    newNode->next=NULL;
    newNode->prev=tail;
    if(head==NULL){
        head=newNode;
        tail=newNode;
    }
    else{
        tail->next=newNode;
        tail=newNode;
    }
}

int deleteNode(int data){
    if(head==NULL){
        return 0;
    }
    for(Node* prev, *itr=head;itr!=NULL;itr=itr->next){
        if(itr->data==data){
            prev->next=itr->next;
            return 1;
        }
        prev=itr;
    }
    return 0;
}

int displayNodes(){
    if(head==NULL){
        return 0;
    }
    
    for(Node *temp=head;temp!=NULL;temp=temp->next){
        printf("%d ", temp->data);
    }
    return 1;
}



int main(){
    int n, data;
    scanf("%d", &n);
    for(int i=0;i<n;i++){
        scanf("%d", &data);
        createNode(data);
    }
    scanf("%d", &data);
    if(deleteNode(data)){
        displayNodes();
    }else{
        printf("Node not found");
    }
    
}