#include <stdio.h>
#include <stdlib.h>
typedef struct node{
    int data;
    struct node*next;
}a;
a *head=NULL,*tail;
void create(int num){
    a *newNode=(a*)malloc(sizeof(a));
    newNode->data=num;
    newNode->next=NULL;
    if(head==NULL){
        head=newNode;
        tail=newNode;
    }
    else{
        tail->next=newNode;
        tail=newNode;
    }
}
void deletion(int value){
    while(1){
    a*first=head;
    a*second=head->next;
    if(value=head->data){
        head->next=head;
    }
    else{
        while(second->next!=NULL){
            int cnt=0;
            if(second->data==value){
                first->next=second->next;
                break;
                free(second);
            }
        }
    }
    first=first->next;
    second=second->next;
    }
}
void traverse(){
    a*i;
    for(i=head;i!=NULL;i=i->next){
        printf("%d ",i->data);
    }
}
int main(){
    int size,num,value;
    scanf("%d",&size);
    if(size<0){
        printf("Invalid input");
        return 0;
    }
    for(int i=0;i<size;i++){
        scanf("%d",&num);
        create(num);
    }
    scanf("%d",&value);
    deletion(value);
    traverse();
    return 0;
    
}