// editor1
#include<stdio.h>
#include<stdlib.h>
typedef struct node{
    int data;
    struct node *prev;
    struct node*next;
}Node;
Node *head=NULL;
void insert_end(int num){
    Node *newnode=(Node*)malloc(1*sizeof(Node));
    newnode->data=num;
    if(head==NULL){
        newnode->next=newnode;
        newnode->prev=newnode;
        head=newnode;
    }
    else{
        Node *last=head->prev;
        newnode->next=head;
        newnode->prev=last;
        last->next=newnode;
        head->prev=newnode;
    }
}
void delete_value(int x){
    if(head==NULL){
        printf("Node not found");
        return;
    }
    Node *curr=head;
    do{
        if(curr->data==x){
            if(curr->next==curr){
                free(curr);
                head=NULL;
                return;
            }
            if(curr==head)
               head=head->next;
            curr->prev->next=curr->next;
            curr->next->prev=curr->prev;
            free(curr);
            return;
        }
        curr=curr->next;
    }while(curr!=head);
    printf("Node not found");
}
void display_reverse(){
    if(head==NULL)
       return;
}
Node *temp=head;
do{
    printf("%d",temp->data);
    temp=temp->prev;
}while(temp!=head);
}
int main(){
    int n,val,x;
    scanf("%d",&n);
    if(n<=0){
        printf("Invalid input");
        return 0;
    }
    for(int i=0;i<n;i++){
        scanf("%d",&Val);
        insert_end(val);
    }
    scanf("%d",&x);
    delete_value(x);
    if(head!=NULL){
    display_reverse();
    }
    return 0;
}