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