// editor4
#include <stdio.h>
#include <stdlib.h>
#include<ctype.h>

struct Node {
    int data;
    struct Node* next;
};

int deleteNode(struct Node** head_ref, int key) {
    struct Node* temp = *head_ref;
    struct Node* prev = NULL;

    if (temp != NULL && temp->data == key) {
        *head_ref = temp->next;
        free(temp);
        return 1;
    }

    while (temp != NULL && temp->data != key) {
        prev = temp;
        temp = temp->next;
    }

    if (temp == NULL) {
        return 0;
    }

    prev->next = temp->next;
    free(temp);
    return 1;
}

int main() {
    int i, n, dl;
    scanf("%d", &n);

    struct Node *p, *q, *head;
    q = malloc(sizeof(struct Node));
    if(scanf("%d", &q->data)!=1);
	{
	    printf("Invalid input");
	    return 0;
	}
	else
	{
    q->next = NULL;
    head = q;
    p = head;

    for (i = 2; i <= n; i++) {
        q = malloc(sizeof(struct Node));
        if(scanf("%d", &q->data)!=1);
        {
	    printf("Invalid input");
	    return 0;
	    }
        q->next = NULL;
        p->next = q;
        p = p->next;
    }
}
    scanf("%d", &dl);
    
    int deleted = deleteNode(&head, dl);
    if (!deleted) {
        printf("Value not found");
    }

   else{
    p = head;
    while(head==NULL)
	{
	    printf("List is empty");
	    return 0;
	}
    while (p != NULL) {
        printf("%d ", p->data);
        p = p->next;
    }}

    return 0;
}