#include<stdio.h>
#include<stdlib.h>
typedef struct node{
    int data;
    struct node *next,*prev;
}Node;
Node *head=NULL,*tail;
Node *first;
Node *second;
void create(int num){
    Node *newnode=(Node*)malloc(sizeof(Node));
    newnode->data=num;
    newnode->next=NULL;
    newnode->prev=NULL;
    if(head==NULL){
        head=newnode;
        tail=newnode;
    }
    else{
        tail->next=newnode;
        newnode->prev=tail;
        tail=newnode;
    }
     tail->next=head;
     head->prev=tail;
}
void delete(int val){
    Node *first=head;
    Node *second=head->next;
    if(second->data==val){
        first->next=second->next->prev;
        second->next=first->next;
        second->prev=NULL;
        }
        first=first->next;
        second=second->next;
}
void display(){
    Node *itr;
    for(itr=head;itr!=;itr=itr->next){
        printf("%d ",itr->data);
    }
}
int main(){
    int num,size,itr;
    int val;
    scanf("%d",&size);
    for(itr=0;itr<size;itr++){
        scanf("%d",&num);
        create(num);
    }
    scanf("%d",&val);
    delete(val);
    display();
    return 0;
}