#include<stdio.h>
#include<stdlib.h>

struct Node{
    int data;
    struct Node*next;
};

void append(struct Node** head,int val){
    struct Node*newNode=(struct Node*)malloc(sizeof(struct Node));
    newNode->data=val;
    newNode->next=NULL;
    if(*head==NULL){
        *head=newNode;
        return;
    }
    struct Node*temp=*head;
    while(temp->next!=NULL)temp=temp->next;
    temp->next=newNode;
}
void deleteNode(struct Node** head,struct Node* target){
    if(*head==NULL||target==NULL)return;
    if(*head==target){
        *head=target->next;
        free(target);
        return;
    }
    struct Node* prev=*head;
    while(prev->next!=NULL &&prev->next!=target){
        prev=prev->next;
    }
    if(prev->next==target){
        prev->next=target->next;
        free(target);
    }
}
int main(){
    int n,val,x;
    struct Node*head=NULL;
    
    if(scanf("%d",&n)!=1)return 0;
    if(n<=0){
        printf("Invalid input\n");
        return 0;
    }
    for(int i=0;i<n;i++){
        scanf("%d",&val);
        append(&head,val);
    }
    scanf("%d",&x);
    
    struct Node *first=NULL,*last=NULL,*curr=head;
    
    while(curr!=NULL){
        if(curr->data==x){
            if (first==NULL) first=curr;
            last=curr;
            
        }
        curr=curr->next;
    }
    if(first==NULL){
        printf("Element not found\n");
    } else{
        if(first==last){
            deleteNode(&head,first);
        }else{
            deleteNode(&head,first);
            deleteNode(&head,last);
        }
        curr=head;
        while(curr!=NULL){
            printf("%d",curr->data)
            curr=curr->next;
            
        }
        printf("\n")
    }
    return 0;
}