#include<stdio.h>
#include<stdlib.h>
struct Node{
    int data;
    struct Node* next;
};
struct Node* createNode(int data){
    struct Node* newNode=(struct Node*)malloc(sizeof(struct Node));
    newNode->data=data;
    newNode->next=NULL;
    return newNode;
}
int main(){
    int n,x,value;
    struct Node*head=NULL, *tail=NULL;
    scanf("%d", &n);
    if(n<=0){
        printf("Invalud input");
        return 0;
    }
    
    for(int i=0; i<n; i++){
        scanf("%d", &value);
        struct Node*newNode=createNode(value);
        if(head==NULL){
            head=tail=newNode;
        }else{
            tail->next=newNode;
            tail=newNode;
        }
    }
    scanf("%d", &x);
    struct Node*temp=head, *prev=NULL;
    struct Node*firstPrev=NULL, *firstNode=NULL;
    struct Node*lastprePrev=NULL, *lastNode=NULL;
    while(temp!=NULL){
        if(temp->data==x){
            if(firstNode==NULL){
                firstNode=temp;
                firstPrev=prev;
            }
            lastNode=temp;
            lastPrev=prev;
        }
        prev=temp;
        temp=temp->next;
    }
    if(firstNode==NULL){
        printf("Element not found");
        return 0;
    }
    if(firstPrev==NULL){
        head=firstNode->next;
    }else{
        firstPrev->next=firstNode->next;
    }
    if(lastNode!=firstNode){
        if(lastPrev==NULL){
            head=lastNode->next;
        }else{
            lastPrev->next=lastNode->next;
        }
    }
    temp=head;
    while(temp!=NULL){
        printf("%d", temp->data);
        if(temp->next!=NULL){
            print(" ");
        }
        temp=temp->next;
    }
    return 0;
}