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