// editor4
#include<stdio.h>
#include<stdlib.h>

struct node{
    int data;
    struct node *next;
};

struct node *head=NULL;
struct node *temp;

int createList(){
    struct node newnode= (struct node)malloc(sizeof(struct node));
    if(scanf("%d", &newnode->data)!=1){
        printf("Invalid input");
        exit(1);
    }
    newnode->next=NULL;
    if(head==NULL){
        head=temp=newnode;
    }
    else{
        temp->next= newnode;
        temp= newnode;
    }
}

void display(){
    temp=head;
    while(temp!=NULL){
        printf("%d ", temp->data);
        temp= temp->next;
    }
    printf("\n");
}

int dltVal(int val, int n){
    int count=0;
    struct node *prevnode=NULL;
    temp=head;

    while(temp!=NULL){
        if(temp->data==val){
            if(prevnode==NULL){   
                head=temp->next;
                free(temp);
                temp=head;
            }else{
                prevnode->next=temp->next;
                free(temp);
                temp=prevnode->next;
            }
            count++;
        }else{
            prevnode=temp;
            temp=temp->next;
        }
        if(count==n){
            printf("List is empty\n");
            exit(1);
        }
    }

    if(count==0){
        printf("Value not found\n");
    }else{
        display();
    }
}

int main(){
    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        createList();
    }
    int val;
    scanf("%d", &val);
    dltVal(val,n);
}