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