#include<stdio.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){
        newnode->next=newnode;
        head=newnode;
    }
    else{
        newnode->next=head->next;
        head->next=newnode;
        head=newnode;
    }
}
void display(){
    Node *temp=head->next;
    do{
        printf("%d ",temp->data);
        temp=temp->next;
    }
    while(temp!=head->next);
}
int delval(int val){
    if(val==head->data){
        Node *temp=head;
        head=head->next;
        free(temp);
    }
    
    Node *first=head;
    Node *second=head->next;
    while(second->next!=head->next){
    if(second->data==val){
        first->next=second->next;
        int found=1;
    }
    first=first->next;
    second=second->next;
    }
    return found;

}
int main(){
    int n;
    scanf("%d",&n);
    if(n<0){
        printf("Invalid input");
        return 0;
    }
    int x;
    for(int i=0;i<n;i++){
        scanf("%d",&x);
        insert(x);
    }
    
    int y;
    scanf("%d",&y);
    delval(y);
    display();
    if(!found){
        printf("Node not found");
        return 0;
    }
    return 0;
}