#include<stdio.h>
#include<stdlib.h>
typedef struct node{
    int data;
    struct node *next;
    struct node *prev;
}s2;

s2 *head=NULL,*tail=NULL;

void create(int num){
    s2 *new=(s2*)malloc(sizeof(s2));
    new->data=num;
    new->prev=NULL;
    new->next=NULL;
    if(head==NULL){
        head=new;
        tail=new;
    }else{
        tail->next=new;
        new->prev=tail;
        tail=new;
    }
}
#include<stdio.h>
#include<stdlib.h>
typedef struct node{
    int data;
    struct node *next;
    struct node *prev;
}s2;

s2 *head=NULL,*tail=NULL;

void create(int num){
    s2 *new=(s2*)malloc(sizeof(s2));
    new->data=num;
    new->prev=NULL;
    new->next=NULL;
    if(head==NULL){
        head=new;
        tail=new;
    }else{
        tail->next=new;
        new->prev=tail;
        tail=new;
    }
}

#include<stdio.h>
#include<stdlib.h>
typedef struct node{
    int data;
    struct node *next;
    struct node *prev;
}s2;

s2 *head=NULL,*tail=NULL;

void create(int num){
    s2 *new=(s2*)malloc(sizeof(s2));
    new->data=num;
    new->prev=NULL;
    new->next=NULL;
    if(head==NULL){
        head=new;
        tail=new;
    }else{
        tail->next=new;
        new->prev=tail;
        tail=new;
    }
}

void delete(int val){
    s2 *temp=head;
    
    if(head->data == val){
        temp=head->next;
    }else if(tail->data == val){
        tail->prev=tail;
        tail->next=NULL;
    }else{
        while(temp!=NULL && temp->data==val){
                temp=temp->next;
        }
        temp->next->prev=temp->prev;
        temp->prev->next=temp->next;
    }
}

void display(){
    s2 *i;
    for(i=head;i!=NULL;i=i->next){
        printf("%d ",i->data);
    }
}
int main(){
    int size,num;
    scanf("%d",&size);
    for(int i=1;i<=size;i++){
        scanf("%d ",&num);
        create(num);
    }
    int val;
    scanf("%d",&val);
    delete(val);
    display();
}
void display(){
    s2 *i;
    for(i=head;i!=NULL;i=i->next){
        printf("%d ",i->data);
    }
}
int main(){
    int size,num;
    scanf("%d",&size);
    for(int i=1;i<=size;i++){
        scanf("%d ",&num);
        create(num);
    }
    int val;
    scanf("%d",&val);
    delete(val);
    display();
}
void display(){
    s2 *i;
    for(i=head;i!=NULL;i=i->next){
        printf("%d ",i->data);
    }
}
int main(){
    int size,num;
    scanf("%d",&size);
    for(int i=1;i<=size;i++){
        scanf("%d ",&num);
        create(num);
    }
    int val;
    scanf("%d",&val);
    delete(val);
    display();
}