// editor5
#include<stdio.h>
#include<stdlib.h>
typedef struct node{
    int data;
    struct node *next;
    struct node *prev;
}Node;

Node *head,*tail;
int cnt=0;
void create(int num){
    Node *newnode = (Node*) malloc (sizeof(Node));
    newnode->data = num;
    newnode->next = NULL;
    newnode->prev = NULL;
    if(head == NULL){
        head = newnode;
        tail = newnode;
    }else{
        tail->next = newnode;
        newnode->prev = tail;
        tail = newnode;
    }
    head->prev = tail;
    tail->next = head;
}
int deleteone(){
    return 0;
}

void deletion(Node *head,int val){
    
    if(head==NULL){
        return;
    }
    if(head->data==val && head->next==NULL){
        deleteone();
    }
 
    if(head->data==val){
        head = head->next;
    }        
    }else if(tail->data == val){
        tail->prev->next = head;
        head->prev = tail->prev;
        tail = tail->prev;
        
    }else{
        Node *temp = head->next;
        
        while(temp!=head){
            if(temp->data == val){
                temp->prev->next = temp->next;
                temp->next->prev = temp->prev;
                cnt += 1;
                break;
            }
            temp=temp->next;
        }
        // for(temp=head;head!=NULL;temp=temp->next){
           
}
}

void display(){
    Node *itr=head;
    do{
        printf("%d ",itr->data);
        itr = itr->next;
    }while(head!=itr);
}

int main(){
    int n,num,itr;
    scanf("%d",&n);
    if(n<0){
        printf("Node not found");
        return 0;
    }
    for(itr=0;itr<n;itr++){
        scanf("%d",&num);
        // if(num<0){
        //     printf("Node not found");
        //     return 0;
        // }
        create(num);
    }
    int val;
    scanf("%d",&val);
    deletion(head,val);
    if(cnt==0){
        printf("Node not found");
        return 0;
    }
    display();
    return 0;
}