// editor5
#include<stdio.h>
#include<stdlib.h>

typedef struct list
{
    int data;
    struct node *next,*prev;
}node;

node *head=NULL,*tail=NULL;
void create(int n)
{
    node *nd=(node*)malloc(sizeof(node));
    nd->data=n;
    nd->next=nd->prev=NULL;
    if(head==NULL)
    {
        head=tail=nd;
        // head->prev=tail;
        // tail->next=head;
    }
    else
    {
        tail->next=nd;
        nd->prev=tail;
        tail=nd;
        tail->next=head;
    }
}
void del(int val)
{
    node *temp=head;
    do
    {
        if(temp->data==val)
        {
            temp-prev->next=temp->next;
            temp->next->pev=temp->prev;
            temp->next=temp->prev=NULL;
            free(temp);
            return;
        }
        temp=temp->next;
    }while(temp!=head);
    printf("Node not found");
}

void display()
{
    node *temp=head;
    do
    {
        printf("%d ",temp->data);
        temp=temp->next;
    }while(temp!=head);
}

int main()
{
    int n,val;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        int data;
        scanf("%d",&data);
        create(data);
    }
    scanf("%d",val);
    del(val);
    display();
}