#include<stdio.h>
#include<stdlib.h>
 struct Node{
    int data;
    struct Node* next;
};
 struct Node* createNode(int data) {
     struct Node* newNode = (struct Node*)malloc(sizeof( struct Node));
    newNode->data = data;
    newNode->next = NULL;
    return newNode;
}
void printList(struct Node* head){
    if(head == NULL) return;
    struct Node* temp=head;
    do{
        printf("%d ",temp->data);
        temp = temp->next;
    }while(temp!=head);
    printf("\n");
}
struct Node* deleteNode(struct Node* head, int key){
    if(head = NULL)return NULL;
    struct Node* curr=head,*prev=NULL;
    do{
        if(curr->data == key)break;
        prev = curr;
        curr=curr->next;
    }while(curr != head);
    if(curr->data!=key){
        printf("Node not found\n");
        return NULL;
    }
    if(curr->next== curr){
        free(curr);
        return NULL;
        
    }
    if(curr = head){
        prev = head;
        while(prev->next!=head)prev= prev->next;
        head = head->next;
        prrev->next=head;
        free(curr);
    //    return NULL;
    // }
    //if(curr == head){
    //    prev = head;
    //    while(prev->next != head)prev = prev->next;
    //    head=head->next;
    //     prev->next=head;
    //      free(curr);
    }else{
        prev->next = curr->next;
        free(curr);
    }
    return head;
    }
    int main(){
        int n,x;
        scanf("%d",&n);
        if(n<=0)return 0;
        int val;
        struct Node* head =NULL;
        struct Node* tail=NULL;
        for(int i=0;i<n;i++){
            scanf("%d",&val);;
            struct Node* newNode = createNode(val);
            if(head == NULL){
                head=newNode;
                tail=newNode;
                newNode->next=head;
            }else{
                tail->next= newNode;
                teil=newNode;
                tail->next=head;
            }
        }
        scanf("%d",&x);
        head=deleteNode(head,x);
        if(head != NULL){
            printList(head);
        }
        return 0;
    }