// editor2
#include<stdio.h>
#include<stdlib.h>
struct Node{
    int data;
    struct Node*prev,*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*buildlist(int n)
{
    if(n<=0)
    return NULL;
    int val;
    scanf("%d",&val);
    struct Node*head=createNode(val);
    struct Node*tail=head;
    for(int i=1;i<n;i++)
{
    scanf("%d",&val);
    struct Node*newNode=createNode(val);
    tail->next=newNode;
    newNode->prev=tail;
    tail=newNode;
    
}
    tail->next=head;
    head->prev=tail;
    return NULL;
    struct Node* curr=head;
    do{
        if(curr->data==x)
          break;
        curr=curr->next;
        
    }
    while(curr!=head);
    if(curr->data!=x)
    return head;
    if(curr->next==curr&&curr->prev==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;
    
}
void display(struct Node*head)
{
    if(head==NULL)
    return;
    struct Node*temp=head;
    do{
        printf("%d",temp->data);
        temp=temp->next;
        
    }
    while(temp!=head);
    
}
int main()
{
    int n,x;
    scanf("%d",&n);
    struct Node*head=buildList(n);
    scanf("%d",&x);
    struct Node*updated=deleteNode(head,x)
    if(uptaded==NULL)
    printf("Node not found");
    else{
        struct Node*check=updated;
        int found=0;
        do{
            if(check->data==x)
            {
                found=1;
                break;
            }
            check=check->next;
        }
        while(check!=uptaded);
        if(found&&n==1)
        printf("Node not found");
        else
        display(updated);
    }
    return 0;
}