// editor1
#include<stdio.h>
#include<stdlib.h>
struct node{
    int data;
    struct node *prev;
    struct node*next;
};
struct node *createNode(int data){
    struct node *newnode=(struct node*)malloc (sizeof(struct node));
    newnode->data=data;
    newnode->prev=newnode->next=NULL;
    return newnode;
}
struct node *createList(int arr[],int n){
    if(n==0)
        return NULL;
    struct node *head=createNode(arr[0]);
    struct node *temp=head;
    for(int i=1;i<n;i++){
        struct node *newnode=createNode(arr[i]);
        temp->next=newnode;
        newnode->prev=temp;
        temp=newnode;
    }
    temp->next=head;
    head->prev=temp;
    return head;
}
struct Node *deleteNode(struct Node *head,int x,int *found){
    if(!head)
       return NULL;
     struct Node *curr=head;
     do{
         if(curr->data==x){
             *found=1;
             if(curr->next==curr){
                 free(curr);
                 return NULL;
             }
             curr->prev->next=curr->next;
             curr->next->prev=curr->prev;
             if(curr==head)
                 head=curr->next;
            free(curr);
            return head;
         }
         curr=curr->next;
     }while(curr!=head);
     *found=0;
     return head;
}
void display(struct Node *head){
    if(!head)
       return;
    struct node *temp=head;
    do{
        printf("%d ",temp->data);
        temp=temp->next;
    }while(temp!=head);
}
int main(){
    int n,val,x;
    scanf("%d",&n);
    int arr[n];
    for(int i=0;i<n;i++)
         scanf("%d",&arr[i]);
    int x;
    scanf("%d",&x);
    struct node *head=createList(arr,n);
    int found=0;
    head=deleteNode(head,x,&found);
    if(!found)
       printf("Node not found");
    else
       display(head);
    return 0;
}