#include <stdio.h>
#include<stdlib.h>
struct Node{
    int data;
    struct Node*next;
};

struct Node*createCircularList(int arr[], int n){
    if(n==0) return NULL;


struct Node *head= NULL, *temp= NULL; *last = NULL;
for (int i=0;i<n;i++){
    temp = (struct Node*)malloc(sizeof(struct Node));
    temp->data = arr[i];
    temp->next = NULL;
    
    if(head ==NULL){
        head = temp;
        last = temp;
    }else{
        last->next = temp;
        last = temp;
    }
}
last->next = head;
return head;
}
struct Node*deleteByValue(struct Node *head, int x,int *deleted){
    if(head == NULL){
        *deleted = 0;
        return  NULL;
    }
    struct Node *curr = head, *prev = NULL;
    do{
        if(curr->data == x)
           break;
        prev = curr;
        curr = curr->next;
    }while(curr != head);
    
    if(curr->data != x){
        *deleted = 0;
        return head;
    }
    *deleted = 1;
    
    if(curr == head && curr->next == head){
        free(curr);
        return NULL;
    }
    if(curr == head){
        struct Node *last = head;
        while(last->next!=head)
              last = last->next;
        head = head->next;
        last->next = head;
        free(curr);
        return head;
    }
    
    prev->next = curr->next;
    free(curr);
    return head;
    }
    void printCircularList(struct Node *head){
        if (head == NULL)  return;
        struct Node *temp = head;
        do{
            printf("%d", temp->data);
            (temp = temp->next);
            if(temp!=head)  printf(" ");
        }while (temp!=head);
    }
    
    int main(){
        int n;
        if(scanf("%d", &n)!=1) return 0;
        
        int arr[n];
        for(int i=0;i<n;i++)
            scanf("%d", &arr[i]);
            
        int x;
        scanf("%d", &x);
        struct Node *head =createCircularList(arr, n);
        int deleted = 0;
        head = deleteByValue(head,x, &deleted);
        
        if(!deleted)
           printf("Node not found");
        else if(head != NULL)
           printCircularList(head);
           
        return 0;
    }
}