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