#include <stdio.h>
#include <stdlib.h>
typedef struct node{
    int data;
    struct node *next;
}nod;
nod *head =NULL,*temp=NULL,*newNode=NULL;
void display(){
    temp=head;
    while(temp!=NULL){
        printf("%d ",temp->data);
        temp=temp->next;
    }
}
void deletebyval(val){
    nod *first,*second;
    first=head;
    second=head->next;
    if(val==first->data){
        head=head->next;
    }else{
        while(second!=NUll){
            if(second->data==val){
                head->next=second->next;
                break;
            }else{
                first=second;
                second=second->next;
            }
            
        }
    }
}
int main(){
    int n;
    scanf("%d",&n);
    if(n<0){
        printf("Invalid Input");
        return 0;
    } 
    
    for(int i=0;i<n;i++){
        int x;
        if(scanf("%d",&x)!=1){
            printf("Invalid Input");
            return 0;
        }
        newNode=(nod*)malloc(sizeof(nod));
        newNode->data=x;
        newNode->next=NULL;
        
        if(head==NULL){
            head=newNode;
            temp=newNode;
        }else{
            temp->next=newNode;
            temp=temp->next;
        }
    }
    int x;
    scanf("%d",&x);
    deletebyval(x);
    display();
    return 0;
}