#include<stdio.h>
#include<stdlib.h>
typedef struct Node{
    int data;
    struct Node* next;
} Node;
 struct Node* createNode(int data) {
     struct Node* newNode = (struct Node *)malloc(sizeof( struct Node));
    newNode->data = data;
    newNode->next = NULL;
    return newNode;
}
void printList(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 == head){
        prev = head;
        while(prev->next !=head)prev = prev->next;
        head = head->next;
        prev->next=head;
        free(curr);
    }else{
        prec->next = curr->next;
        free(curr);
    }
    return head;
}
int main(){
    int x,n;
    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;
            tail=newNode;
            tail->next=head;
        }
    }
    scanf("%d",&x);
    head=deleteNode(head, x);
    if(head != NULL){
        printList(head);
    }
    return 0;
}